public ActionResult Edit(Guid?id) { if (id.HasValue) { MetaView obj = MetaViewHelper.Get(id.Value); if (obj == null) { return(MessageHelper.FormedContentObjectNotFound()); } MetaViewModel.CreateMap(); MetaViewModel model = Mapper.Map <MetaView, MetaViewModel>(obj); return(View(model)); } else { return(View(new MetaViewModel())); } }
public ActionResult EditExternalMethod(Guid?id, Guid?ViewId) { MetaViewExternalMethodModel model = null; if (id.HasValue) { var att = MetaViewHelper.GetExternalMethod(id.Value); if (att == null) { return(MessageHelper.FormedContentObjectNotFound()); } MetaViewExternalMethodModel.CreateMap(); model = Mapper.Map <MetaViewExternalMethod, MetaViewExternalMethodModel>(att); return(View(model)); } else if (ViewId.HasValue) { MetaView item = MetaViewHelper.Get(ViewId.Value); if (item != null) { return(View(new MetaViewExternalMethodModel { MetaViewId = item.Id, MetaViewCaption = item.Caption, })); } else { return(MessageHelper.FormedContentObjectNotFound()); } } else { return(MessageHelper.FormedContentObjectNotFound()); } }
public ActionResult Edit(Guid id, MetaViewModel model, List <MetaViewColumnModel> columns, string button) { using (DBEntities context = Settings.CreateDataContext()) { Validate(context, model); if (!ModelState.IsValid) { return(View(model)); } MetaView target = null; if (model.Id != Guid.Empty) { target = MetaViewHelper.Get(model.Id, context); if (target == null) { ModelState.AddModelError("", Resources.Resource.RowNotFound); return(View(model)); } } else { target = new MetaView { Id = Guid.NewGuid() }; context.AddToMetaView(target); } MetaViewModel.CreateMap(); Mapper.Map(model, target); if (columns != null) { SyncViewColumns(target, columns, context); } 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 })); } } }