public ActionResult Edit(Guid id, MetaMenuModel model, string button) { using (DBEntities context = Settings.CreateDataContext()) { Validate(context, model); if (!ModelState.IsValid) { return(View(model)); } MetaMenu target = null; if (model.Id != Guid.Empty) { target = MetaMenuHelper.Get(model.Id, context); if (target == null) { ModelState.AddModelError("", Resources.Resource.RowNotFound); return(View(model)); } } else { target = new MetaMenu(); target.Id = Guid.NewGuid(); context.AddToMetaMenu(target); } MetaMenuModel.CreateMap(); Mapper.Map(model, target); try { context.SaveChanges(); } catch (Exception ex) { var sb = new StringBuilder(Resources.Resource.SaveError + ": " + ex.Message); if (ex.InnerException != null) { sb.AppendLine(ex.InnerException.Message); } ModelState.AddModelError("", sb.ToString()); return(View(model)); } if (button == "SaveAndExit") { return(RedirectToAction("Index")); } else { return(RedirectToAction("Edit", new { target.Id })); } } }