public ActionResult Create(AddEditVenueModel model) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } if (ModelState.IsValid) { CreateFromModel(model, provider.ProviderId); List <String> messages = model.GetWarningMessages(); 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")); } // Populate drop downs GetLookups(model); return(View(model)); }
public ActionResult Unarchive(Int32 id) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } Location location = db.Locations.Find(id); if (location == null || location.ProviderId != userContext.ItemId || location.RecordStatusId == (Int32)Constants.RecordStatus.Deleted) { return(HttpNotFound()); } Location locDupPostcode = db.Locations.FirstOrDefault(x => x.RecordStatusId == (int)Constants.RecordStatus.Live && x.LocationId != location.LocationId && x.Address.Postcode == location.Address.Postcode && x.ProviderId == provider.ProviderId); if (locDupPostcode != null) { var message = AppGlobal.Language.GetText(this, "UnArchiveFailed", "Unable to unarchive location, there is already a location using this postcode."); SessionMessage.SetMessage(message, SessionMessageType.Danger, 2); return(RedirectToAction("Edit", "Location", new { Id = location.LocationId })); } location.Unarchive(db); db.SaveChanges(); ShowGenericSavedMessage(true); return(RedirectToAction("Edit", "Location", new { Id = location.LocationId })); }
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 async Task <ActionResult> Edit(Int32 id, AddEditVenueModel model) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } if (model.VenueId != id) { return(HttpNotFound()); } Venue venue = db.Venues.Find(id); if (venue == null) { return(HttpNotFound()); } if (ModelState.IsValid) { venue = model.ToEntity(db); if (venue.ProviderId != userContext.ItemId) { // User is trying to change the VenueId (or the context has changed) return(HttpNotFound()); } venue.ModifiedByUserId = Permission.GetCurrentUserId(); venue.ModifiedDateTimeUtc = DateTime.UtcNow; Address venueAddress = model.Address.ToEntity(db); db.Entry(venueAddress).State = EntityState.Modified; db.Entry(venue).State = EntityState.Modified; await db.SaveChangesAsync(); List <String> messages = model.GetWarningMessages(); 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")); } // Populate drop downs GetLookups(model); 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)); }
public ActionResult Create(AddEditLocationModel model) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } if (model.ProviderId != provider.ProviderId) { return(HttpNotFound()); } Location loc = db.Locations.FirstOrDefault(x => x.LocationName == model.LocationName && x.ProviderId == provider.ProviderId); if (loc != null) { ModelState.AddModelError("LocationName", AppGlobal.Language.GetText("Location_Create_DuplicateLocatioName", "The Location Name supplied is already in use.")); } Address address = model.Address.ToEntity(db); Location locDupPostcode = db.Locations.FirstOrDefault(x => x.RecordStatusId == (int)Constants.RecordStatus.Live && x.Address.Postcode == address.Postcode && x.ProviderId == provider.ProviderId); if (locDupPostcode != null) { ModelState.AddModelError("Address.Postcode", AppGlobal.Language.GetText("Location_Create_DuplicatePostcode", "The postcode supplied is already in use.")); } CheckMaxNumberOfLocations(provider); if (ModelState.IsValid) { Location location = CreateFromModel(model, provider.ProviderId); if (!location.Address.Latitude.HasValue) { ModelState.AddModelError("Address.Postcode", unableToFindLatLngMessage); } else { List <String> messages = model.GetWarningMessages(); 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")); } } // Populate drop downs GetLookups(model); // Set this to true here so that the message doesn't appear twice ViewBag.CanProviderCreateNewLocation = true; return(View(model)); }
public async Task <ActionResult> Edit(Int32 id, AddEditLocationModel model) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } if (model.LocationId != id) { return(HttpNotFound()); } Location location = db.Locations.Find(id); if (location == null) { return(HttpNotFound()); } Location loc = db.Locations.FirstOrDefault(x => x.LocationId != location.LocationId && x.LocationName == model.LocationName && x.ProviderId == provider.ProviderId); if (loc != null) { ModelState.AddModelError("LocationName", AppGlobal.Language.GetText("Location_Edit_DuplicateLocatioName", "The Location Name supplied is already in use.")); } Address address = model.Address.ToEntity(db); Location locDupPostcode = db.Locations.FirstOrDefault(x => x.RecordStatusId == (int)Constants.RecordStatus.Live && x.Address.Postcode == address.Postcode && x.ProviderId == provider.ProviderId && x.LocationId != model.LocationId); if (locDupPostcode != null) { ModelState.AddModelError("Address.Postcode", AppGlobal.Language.GetText("Location_Create_DuplicatePostcode", "The postcode supplied is already in use.")); } if (ModelState.IsValid) { location = model.ToEntity(db); if (location.ProviderId != userContext.ItemId) { // User is trying to change the LocationId (or the context has changed) return(HttpNotFound()); } location.ModifiedByUserId = Permission.GetCurrentUserId(); location.ModifiedDateTimeUtc = DateTime.UtcNow; Address locationAddress = model.Address.ToEntity(db); if (!locationAddress.Latitude.HasValue) { ModelState.AddModelError("Address.Postcode", unableToFindLatLngMessage); } else { db.Entry(locationAddress).State = EntityState.Modified; db.Entry(location).State = EntityState.Modified; await db.SaveChangesAsync(); List <String> messages = model.GetWarningMessages(); 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")); } } // Populate drop downs GetLookups(model); return(View(model)); }
public async Task <ActionResult> Create(AddEditCourseModel model) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } CheckModel(model); if (ModelState.IsValid) { if (!String.IsNullOrEmpty(model.LearningAimId)) { LearningAim learningAim = db.LearningAims.Find(model.LearningAimId); if (learningAim == null) { return(HttpNotFound()); } } Course course = model.ToEntity(db); course.ProviderId = provider.ProviderId; course.RecordStatusId = (Int32)Constants.RecordStatus.Pending; course.AddedByApplicationId = (Int32)Constants.Application.Portal; if (String.IsNullOrEmpty(model.LearningAimId)) { List <String> LearnDirectClassificationCodes = new List <String>(); if (!String.IsNullOrEmpty(model.LearnDirectClassificationId1)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId1); } if (!String.IsNullOrEmpty(model.LearnDirectClassificationId2)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId2); } if (!String.IsNullOrEmpty(model.LearnDirectClassificationId3)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId3); } if (!String.IsNullOrEmpty(model.LearnDirectClassificationId4)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId4); } if (!String.IsNullOrEmpty(model.LearnDirectClassificationId5)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId5); } Int32 i = 1; foreach (LearnDirectClassification classification in LearnDirectClassificationCodes.Select(ld => db.LearnDirectClassifications.Find(ld))) { CourseLearnDirectClassification cld = new CourseLearnDirectClassification { LearnDirectClassification = classification, ClassificationOrder = i }; course.CourseLearnDirectClassifications.Add(cld); i++; } } db.Courses.Add(course); await db.SaveChangesAsync(); List <String> messages = model.GetWarningMessages(); 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); } // If user clicked "Create" then take them to Course List if (Request.Form["Create"] != null) { return(RedirectToAction("List")); } // User clicked "Create and Add Opportunity" - Take them to Create Opportunity page return(RedirectToAction("Create", "Opportunity", new { id = course.CourseId })); } // Populate drop downs GetLookups(model); return(View(model)); }
public async Task <ActionResult> Edit(Int32 id, AddEditCourseModel model) { Provider provider = db.Providers.Find(userContext.ItemId); if (provider == null) { return(HttpNotFound()); } if (model.CourseId != id) { return(HttpNotFound()); } Course course = db.Courses.Find(id); if (course == null) { return(HttpNotFound()); } CheckModel(model); if (ModelState.IsValid) { course = model.ToEntity(db); if (course.ProviderId != userContext.ItemId) { // User is trying to change the VenueId (or the context has changed) return(HttpNotFound()); } // Delete Existing CourseLearnDirectClassifications // Normally I would work out which already exist and just write the changes but because of the ordering it's easier just to delete them all and re-write them all foreach (CourseLearnDirectClassification ld in course.CourseLearnDirectClassifications.ToList()) { course.CourseLearnDirectClassifications.Remove(ld); } // Add any new Learn Direct classifications if (String.IsNullOrEmpty(model.LearningAimId)) { List <String> LearnDirectClassificationCodes = new List <String>(); if (!String.IsNullOrEmpty(model.LearnDirectClassificationId1)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId1); } if (!String.IsNullOrEmpty(model.LearnDirectClassificationId2)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId2); } if (!String.IsNullOrEmpty(model.LearnDirectClassificationId3)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId3); } if (!String.IsNullOrEmpty(model.LearnDirectClassificationId4)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId4); } if (!String.IsNullOrEmpty(model.LearnDirectClassificationId5)) { LearnDirectClassificationCodes.Add(model.LearnDirectClassificationId5); } Int32 i = 1; foreach (LearnDirectClassification classification in LearnDirectClassificationCodes.Select(ld => db.LearnDirectClassifications.Find(ld))) { CourseLearnDirectClassification cld = new CourseLearnDirectClassification { LearnDirectClassification = classification, ClassificationOrder = i }; course.CourseLearnDirectClassifications.Add(cld); i++; } } course.ModifiedByUserId = Permission.GetCurrentUserId(); course.ModifiedDateTimeUtc = DateTime.UtcNow; course.AddedByApplicationId = (Int32)Constants.Application.Portal; db.Entry(course).State = EntityState.Modified; await db.SaveChangesAsync(); List <String> messages = model.GetWarningMessages(); 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")); } // Populate drop downs GetLookups(model); return(View(model)); }
/// <summary> /// Shows the generic data saved message on the next page load, surviving a redirect. /// </summary> public void ShowGenericSavedMessage(bool surviveRedirect) { var message = AppGlobal.Language.GetText(this, "SaveSuccessful", "Your changes were saved successfully."); SessionMessage.SetMessage(message, SessionMessageType.Success, surviveRedirect ? 2 : 1); }