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 Create() { var model = new AddEditApprenticeshipViewModel().Populate(db); ModelState.Clear(); return(View(model)); }
public ActionResult Edit(Int32?id) { if (id == null || id == 0) { return(RedirectToAction("Create")); } if (!db.Providers.Any(x => x.ProviderId == userContext.ItemId.Value) || !db.Apprenticeships.Any(x => x.ApprenticeshipId == id && x.ProviderId == userContext.ItemId.Value)) { return(HttpNotFound()); } var model = new AddEditApprenticeshipViewModel(); model = model.Populate(id.Value, db); return(View(model)); }
public void RemoveSpellCheckHTMLFromMarketingInformation(AddEditApprenticeshipViewModel model) { model.MarketingInformation = Markdown.Sanitize(model.MarketingInformation); if (!ModelState.IsValidField("MarketingInformation") && model.MarketingInformation.Length <= AddEditApprenticeshipViewModel.MarketingInformationMaxLength) { // These 2 strings should match the corresponding strings in AddEditApprenticeshipViewModel (especially where language is set to developer mode) String errorMessage = String.Format(AppGlobal.Language.GetText("AddEditApprenticeshipViewModel_StringLength_MarketingInformation", "The maximum length of {0} is 750 characters."), AppGlobal.Language.GetText("AddEditApprenticeshipViewModel_DisplayName_MarketingInformation", "Your Apprenticeship Information for Employers")); foreach (ModelError me in ModelState["MarketingInformation"].Errors) { if (me.ErrorMessage == errorMessage) { ModelState["MarketingInformation"].Errors.Remove(me); break; } } // If there are no more marketing information errors then remove the key altogether if (ModelState["MarketingInformation"].Errors.Count == 0) { ModelState.Remove("MarketingInformation"); } } }
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)); }