public ActionResult Create() { // //Load ViewModel // //Statuses var editPageViewModel = new EditPageViewModel(); editPageViewModel.EAFormStatuses = db.EAFormStatuses; editPageViewModel.LastUpdated = DateTime.Today; editPageViewModel.StartDate = null; editPageViewModel.LastSubmitted = null; editPageViewModel.SetupMultiSelectViewModels(null); return View(editPageViewModel); }
public ActionResult Edit(EditPageViewModel editPageViewModel, string Command, string SearchKeywords) { if (Command == "Search") { string action = Command; string result = SearchKeywords; } else { string edit = Command; } EAForm eaform = db.EAForms.Find(editPageViewModel.ID); if (eaform == null) { return HttpNotFound(); } //Include Save History ((System.Data.Entity.Infrastructure.IObjectContextAdapter)db).ObjectContext.LoadProperty(eaform, i => i.SaveHistory); eaform = Mapper.Map<EAFormViewModel, EAForm>(editPageViewModel, eaform); eaform.Status = db.EAFormStatuses.Find(editPageViewModel.SelectedStatusValue); eaform.LastUpdated = DateTime.Now; eaform.CreateSaveHistoryRecord("rderouin");//User.Identity.Name); if (ModelState.IsValid) { try { db.Entry(eaform).State = EntityState.Modified; db.SaveChanges(); ViewBag.SuccessMessage = "Saved successfully"; // UI.SaveSuccess; } catch (DbEntityValidationException ex) { ModelState.AddModelError("EditForm", "Form could not be saved"); //ErrorMessages.SaveError); Elmah.ErrorSignal.FromCurrentContext().Raise(ex); string errorMessage = string.Empty; //debug code foreach (var err in ex.EntityValidationErrors) { System.Diagnostics.Debug.WriteLine(string.Format("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:", err.Entry.Entity.GetType().Name, err.Entry.State)); foreach (var ve in err.ValidationErrors) { System.Diagnostics.Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"", ve.PropertyName, ve.ErrorMessage); } } } } else { var errors = ModelState.Values.SelectMany(v => v.Errors); foreach (var error in errors) { if (error.Exception != null) Elmah.ErrorSignal.FromCurrentContext().Raise(error.Exception); else Elmah.ErrorSignal.FromCurrentContext().Raise(new Exception(error.ErrorMessage)); } } editPageViewModel = Mapper.Map<EAForm, EditPageViewModel>(eaform, editPageViewModel); editPageViewModel.EAFormStatuses = db.EAFormStatuses; editPageViewModel.SetupMultiSelectViewModels(eaform); return View(editPageViewModel); }
// GET: /EAForms/Edit/5 //[CustomAuthorize(Roles = "Admin,Program Assistant")] public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ViewBag.Title = "Edit"; var editPageViewModel = new EditPageViewModel(); EAForm eaform = db.EAForms.Find(id); if (eaform == null) { return HttpNotFound(); } //Include Status ((System.Data.Entity.Infrastructure.IObjectContextAdapter)db).ObjectContext.LoadProperty(eaform, i => i.Status); //Include Save History ((System.Data.Entity.Infrastructure.IObjectContextAdapter)db).ObjectContext.LoadProperty(eaform, i => i.SaveHistory); // //Load ViewModel // //Statuses editPageViewModel = Mapper.Map<EAForm, EditPageViewModel>(eaform, editPageViewModel); editPageViewModel.EAFormStatuses = db.EAFormStatuses; editPageViewModel.SetupMultiSelectViewModels(eaform); return View("Edit", editPageViewModel); }