public ActionResult EditExternalMethod(Guid?id, Guid?FormId, MetaFormExternalMethodModel model, string button) { if (string.IsNullOrEmpty(button)) { return(View(model)); } if (!ModelState.IsValid) { return(View(model)); } using (DBEntities context = Settings.CreateDataContext()) { MetaFormExternalMethod target = null; if (model.Id != Guid.Empty) { target = MetaFormHelper.GetExternalMethod(model.Id, context); if (target == null) { ModelState.AddModelError("", Resources.Resource.RowNotFound); return(View(model)); } } else { target = new MetaFormExternalMethod(); target.Id = model.Id = Guid.NewGuid(); context.AddToMetaFormExternalMethod(target); } MetaFormExternalMethodModel.CreateMap(); target = Mapper.Map(model, target); try { context.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("", Resources.Resource.SaveError + ": " + ex.Message); } } if (button == "SaveAndExit") { return(RedirectToAction("Edit", new { id = model.MetaFormId })); } else { return(RedirectToAction("EditExternalMethod", new { id = model.Id })); } }
public ActionResult EditExternalMethod(Guid? id, Guid? FormId, MetaFormExternalMethodModel model, string button) { if (string.IsNullOrEmpty(button)) return View(model); if (!ModelState.IsValid) { return View(model); } using (DBEntities context = Settings.CreateDataContext()) { MetaFormExternalMethod target = null; if (model.Id != Guid.Empty) { target = MetaFormHelper.GetExternalMethod(model.Id, context); if (target == null) { ModelState.AddModelError("", Resources.Resource.RowNotFound); return View(model); } } else { target = new MetaFormExternalMethod(); target.Id = model.Id = Guid.NewGuid(); context.AddToMetaFormExternalMethod(target); } MetaFormExternalMethodModel.CreateMap(); target = Mapper.Map(model, target); try { context.SaveChanges(); } catch (Exception ex) { ModelState.AddModelError("", Resources.Resource.SaveError + ": " + ex.Message); } } if (button == "SaveAndExit") return RedirectToAction("Edit", new { id = model.MetaFormId }); else { return RedirectToAction("EditExternalMethod", new { id = model.Id }); } }