public ActionResult Create(ChurchEditModel model) { var church = Mapper.Map<Church>(model); church.PhoneNumbers = Mapper.Map<List<ContactPhoneNumber>>(model.PhoneNumbers); DbContext.Churches.Add(church); DbContext.SaveChanges(User.Identity.GetUserId()); return Redirect(model.UrlForReturn); }
public ActionResult Edit(int id, ChurchEditModel model) { var church = DbContext.Churches.SingleOrDefault(c => c.ChurchId == id); if (church == null || !church.TeamYears .Where(ty => ty.Year == Consts.CurrentYear) .Any(ty => User.IsTeamIdValidForUser(ty.TeamId))) { return HttpNotFound(); } Mapper.Map(model, church); var changes = ChangeTracker.GetChangeSets(church.PhoneNumbers, model.PhoneNumbers.Models, e => e.ContactPhoneNumberId, m => m.ContactPhoneNumberId); foreach (var pair in changes.CommonItems) { Mapper.Map(pair.RightItem, pair.LeftItem); } // TODO: Add // TODO: Delete DbContext.SaveChanges(User.Identity.GetUserId()); return Redirect(model.UrlForReturn); }