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 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)); }