Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
protected override Dictionary<Type, List<EntityInfo>> BeforeSaveEntities(Dictionary<Type, List<EntityInfo>> saveMap) {
Dictionary<Type, List<EntityInfo>> saveMapAdditions = new Dictionary<Type, List<EntityInfo>>();
foreach (var type in saveMap.Keys) {
if (type == typeof(Category)) {
foreach (var entityInfo in saveMap[type]) {
if (entityInfo.EntityState == EntityState.Modified) {
// assume we changed the category name and now want to add $1 to all product prices in this category
// stupid i know, but it'll prove a point
Category category = (entityInfo.Entity as Category);
var products = this.Context.Set<Product>().Where(p => p.CategoryID == category.CategoryID);
foreach (var product in products) {
if (!saveMapAdditions.ContainsKey(typeof(Product)))
saveMapAdditions[typeof(Product)] = new List<EntityInfo>();
var ei = this.CreateEntityInfo(product, EntityState.Modified);
ei.ForceUpdate = true;
product.UnitPrice += 1;
// pop product onto list of entities to save
saveMapAdditions[typeof(Product)].Add(ei);
}
}
}
}
}
foreach (var type in saveMapAdditions.Keys) {
if (!saveMap.ContainsKey(type)) {
saveMap[type] = new List<EntityInfo>();
}
foreach (var enInfo in saveMapAdditions[type]) {
saveMap[type].Add(enInfo);
}
}
return saveMap;
}
[HttpPost]
public SaveResult SaveChanges(JObject saveBundle) {
return _contextProvider.SaveChanges(saveBundle);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.