public ActionResult Create(CoachEditModel model) { var coach = Mapper.Map<Coach>(model); coach.PhoneNumbers = Mapper.Map<List<ContactPhoneNumber>>(model.PhoneNumbers); DbContext.Coaches.Add(coach); DbContext.SaveChanges(User.Identity.GetUserId()); return Redirect(model.UrlForReturn); }
public ActionResult Edit(int id, CoachEditModel model) { var coach = DbContext.Coaches.SingleOrDefault(c => c.CoachId == id); if (coach == null || !coach.TeamYears .Where(ty => ty.Year == Consts.CurrentYear) .Any(ty => User.IsTeamIdValidForUser(ty.TeamId))) { return HttpNotFound(); } Mapper.Map(model, coach); var changes = ChangeTracker.GetChangeSets(coach.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); }