public ActionResult Create(int id) { var model = new AddEditDeliveryLocationViewModel(); model = model.PopulateNew(id, db); return(View(model)); }
public ActionResult Edit(AddEditDeliveryLocationViewModel model) { if (!db.Providers.Any(x => x.ProviderId == userContext.ItemId.Value) || !db.ApprenticeshipLocations .Any(x => x.ApprenticeshipLocationId == model.ApprenticeshipLocationId && x.Apprenticeship.ProviderId == userContext.ItemId.Value)) { return(HttpNotFound()); } Location location = db.Locations.Find(model.LocationId); if (location == null || location.ProviderId != userContext.ItemId) { ModelState.AddModelError("Location", AppGlobal.Language.GetText("DeliveryLocation_Edit_InvalidLocation", "The Location is not valid.")); } // Ensure that the selected location is valid for the delivery modes selected CheckLocationIsValidForDeliveryModes(location, model.SelectedDeliveryModes); model.Validate(db, ModelState); if (ModelState.IsValid) { var deliveryLocation = model.ToEntity(model.ApprenticeshipId, model.ApprenticeshipLocationId, db); db.Entry(deliveryLocation).State = EntityState.Modified; db.SaveChanges(); UpdateDeliveryModes(model, deliveryLocation); ShowGenericSavedMessage(); return(RedirectToAction("Edit", "Apprenticeship", new { id = model.ApprenticeshipId })); } model.AddMetaData(db, userContext); return(View(model)); }
public ActionResult Create(int id, AddEditDeliveryLocationViewModel model) { Apprenticeship app = db.Apprenticeships.Find(id); if (app == null) { return(HttpNotFound()); } if (app.ProviderId != userContext.ItemId) { return(HttpNotFound()); } Location location = db.Locations.Find(model.LocationId); if (location == null || location.ProviderId != app.ProviderId) { ModelState.AddModelError("Location", AppGlobal.Language.GetText("DeliveryLocation_Create_InvalidLocation", "The Location is not valid.")); } // Ensure that the selected location is valid for the delivery modes selected CheckLocationIsValidForDeliveryModes(location, model.SelectedDeliveryModes); model.ApprenticeshipLocationId = 0; model.Validate(db, ModelState); if (ModelState.IsValid) { model.ApprenticeshipId = id; var deliveryLocation = model.ToEntity(id, 0, db); db.ApprenticeshipLocations.Add(deliveryLocation); UpdateDeliveryModes(model, deliveryLocation); db.SaveChanges(); ShowGenericSavedMessage(); return(Request.Form["Create"] != null ? RedirectToAction("Edit", "Apprenticeship", new { id = deliveryLocation.ApprenticeshipId }) : RedirectToAction("Create", "DeliveryLocation", new { id = deliveryLocation.ApprenticeshipId })); } model.AddMetaData(db, userContext); return(View(model)); }
public ActionResult Edit(Int32?id) { if (id == null || id == 0) { RedirectToAction("Create"); } if (!db.Providers.Any(x => x.ProviderId == userContext.ItemId.Value) || !db.ApprenticeshipLocations .Any(x => x.ApprenticeshipLocationId == id && x.Apprenticeship.ProviderId == userContext.ItemId.Value)) { return(HttpNotFound()); } var model = new AddEditDeliveryLocationViewModel(); model = model.Populate(id.Value, db); if (model == null) { return(HttpNotFound()); } return(View(model)); }
private void UpdateDeliveryModes(AddEditDeliveryLocationViewModel model, ApprenticeshipLocation deliveryLocation) { }