public ActionResult Create(AddEditApprenticeshipViewModel model) { model.ApprenticeshipId = 0; RemoveSpellCheckHTMLFromMarketingInformation(model); model.Validate(db, ModelState); if (ModelState.IsValid) { var apprenticeship = model.ToEntity(db); db.Apprenticeships.Add(apprenticeship); db.SaveChanges(); List <String> messages = model.GetWarningMessages(db); if (messages.Count == 0) { ShowGenericSavedMessage(); } else { // Add a blank entry at the beginning so the String.Join starts with <br /><br /> messages.Insert(0, ""); SessionMessage.SetMessage(AppGlobal.Language.GetText(this, "SaveSuccessfulWithWarnings", "Your changes were saved successfully with the following warnings:") + String.Join("<br /><br />", messages), SessionMessageType.Success); } return(Request.Form["Create"] != null ? RedirectToAction("List") : RedirectToAction("Create", "DeliveryLocation", new { id = apprenticeship.ApprenticeshipId })); } return(View(model)); }
public ActionResult Edit(Int32 id, AddEditApprenticeshipViewModel model) { if (!db.Providers.Any(x => x.ProviderId == userContext.ItemId.Value) || !db.Apprenticeships.Any(x => x.ApprenticeshipId == id && x.ProviderId == userContext.ItemId.Value) || model.ApprenticeshipId != id) { return(HttpNotFound()); } RemoveSpellCheckHTMLFromMarketingInformation(model); model.Validate(db, ModelState); if (ModelState.IsValid) { model.ToEntity(db); db.SaveChanges(); List <String> messages = model.GetWarningMessages(db); if (messages.Count == 0) { ShowGenericSavedMessage(); } else { // Add a blank entry at the beginning so the String.Join starts with <br /><br /> messages.Insert(0, ""); SessionMessage.SetMessage(AppGlobal.Language.GetText(this, "SaveSuccessfulWithWarnings", "Your changes were saved successfully with the following warnings:") + String.Join("<br /><br />", messages), SessionMessageType.Success); } return(RedirectToAction("List")); } var deliveryLocations = new DeliveryLocationListViewModel(); model.DeliveryLocations = deliveryLocations.Populate(id, db); return(View(model)); }