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));
        }
        private Venue CreateFromModel(AddEditVenueModel model, Int32 providerId)
        {
            Venue venue = model.ToEntity(db);

            venue.ProviderId     = providerId;
            venue.RecordStatusId = (Int32)Constants.RecordStatus.Live;
            Address venueAddress = model.Address.ToEntity(db);

            venue.Address = venueAddress;
            db.Addresses.Add(venueAddress);
            db.Venues.Add(venue);
            db.SaveChanges();

            return(venue);
        }