public ActionResult Edit(RouteMileage model) { RouteValueDictionary parameters = Request.QueryString.ToRouteValues(); if (model.Action == "Delete") { try { CarraraSQL.RouteMileages.Attach(model); CarraraSQL.RouteMileages.Remove(model); CarraraSQL.SaveChanges(); TempData["Page.Title"] = "The Route Mileage Was Deleted Successfully"; return(RedirectToAction("Index", parameters)); } catch (Exception ex) { Page.Title = "The Route Mileage Was NOT Deleted! " + ex.Message; return(View("Manage", model)); } } if (ModelState.IsValid) { CarraraSQL.Entry(model).State = EntityState.Modified; CarraraSQL.SaveChanges(); TempData["Page.Title"] = "The Route Mileage Was Updated Successfully"; return(RedirectToAction("Index", parameters)); } Page.Title = "The Route Mileage Was NOT Updated!"; Page.Message = "Please correct the following errors:"; return(View("Manage", model)); }
public ActionResult Edit(WeightFormulaType model) { if (model.Action == "Delete") { WeightFormulaType entity = CarraraSQL.WeightFormulaTypes.Find(model.WeightFormulaTypeID); if (entity.MarkTypes.Any()) { return(Content("Whoops…The Weight Formula Type Is In Use And Was NOT Deleted!", "text/plain")); } try { CarraraSQL.WeightFormulaTypes.Remove(entity); CarraraSQL.SaveChanges(); HttpContext.Cache.Remove("WeightFormulaTypesSelectList"); return(Content("OK", "text/plain")); } catch (Exception ex) { string message = ex.Message; if (ex.InnerException != null) { message = ex.InnerException.Message; } return(Content(string.Concat("Whoops…", message), "text/plain")); } } if (ModelState.IsValid) { CarraraSQL.Entry(model).State = EntityState.Modified; CarraraSQL.SaveChanges(); HttpContext.Cache.Remove("WeightFormulaTypesSelectList"); return(PartialView("Row", model)); } return(ReturnError()); }
public ActionResult Edit(Models.CarraraSQL.Route model) { RouteValueDictionary parameters = Request.QueryString.ToRouteValues(); if (model.Action == "Delete") { Models.CarraraSQL.Route entity = CarraraSQL.Routes.Find(model.RouteID); if (entity.Jobs.Any() || entity.Loads.Any() || entity.RouteMileages.Any()) { Page.Title = "The Route Is In Use And Was NOT Deleted!"; Page.Message = "Set the Route to Inactive if you do not intend to use this Route again."; return(View("Manage", model)); } try { CarraraSQL.Routes.Attach(model); CarraraSQL.Routes.Remove(model); CarraraSQL.SaveChanges(); HttpContext.Cache.Remove("RoutesSelectList"); TempData["Page.Title"] = "The Route Was Deleted Successfully"; return(RedirectToAction("Index", parameters)); } catch (Exception ex) { Page.Title = "The Route Was NOT Deleted! " + ex.Message; return(View("Manage", model)); } } if (model.Action == "Mileage") { return(RedirectToAction("Index", "RouteMileage", new { guid = model.RouteID })); } if (ModelState.IsValid) { CarraraSQL.Entry(model).State = EntityState.Modified; CarraraSQL.SaveChanges(); TempData["Page.Title"] = "The Route Was Updated Successfully"; HttpContext.Cache.Remove("RoutesSelectList"); return(RedirectToAction("Index", parameters)); } Page.Title = "The Route Was NOT Updated!"; Page.Message = "Please correct the following errors:"; return(View("Manage", model)); }
public ActionResult Edit(Job model) { RouteValueDictionary parameters = Request.QueryString.ToRouteValues(); if (model.Action == "Delete") { Job entity = CarraraSQL.Jobs.Find(model.JobID); if (entity.HoursAssignments.Any() || entity.JobSiteLocations.Any() || entity.Loads.Any() || entity.Marks.Any() || entity.NonConformingReports.Any() || entity.Pours.Any()) { Page.Title = "The Job Is In Use And Was NOT Deleted!"; Page.Message = "Set the Job Type to Completed, On Hold or Cancelled if you do not intend to use this Job again."; return(View("Manage", model)); } try { CarraraSQL.Jobs.Attach(model); CarraraSQL.Jobs.Remove(model); CarraraSQL.SaveChanges(); HttpContext.Cache.Remove("JobsSelectList"); TempData["Page.Title"] = "The Job Was Deleted Successfully"; return(RedirectToAction("Index", parameters)); } catch (Exception ex) { Page.Title = "The Job Was NOT Deleted! " + ex.Message; return(View("Manage", model)); } } if (ModelState.IsValid) { CarraraSQL.Entry(model).State = EntityState.Modified; CarraraSQL.SaveChanges(); Search.Index.JobsAsync(); HttpContext.Cache.Remove("JobsSelectList"); TempData["Page.Title"] = "The Job Was Updated Successfully"; return(RedirectToAction("Index", parameters)); } Page.Title = "The Job Was NOT Updated!"; Page.Message = "Please correct the following errors:"; return(View("Manage", model)); }
public ActionResult Edit(Department model) { RouteValueDictionary parameters = Request.QueryString.ToRouteValues(); if (model.Action == "Delete") { Department entity = CarraraSQL.Departments.Find(model.DepartmentID); if (entity.Employees.Any() || entity.HoursAssignments.Any() || entity.Loads.Any() || entity.TimeClockPermissions.Any()) { Page.Title = "The Department Is In Use And Was NOT Deleted!"; Page.Message = "Set the Department to Inactive if you do not intend to use this Department again."; return(View("Manage", model)); } try { CarraraSQL.Departments.Attach(model); CarraraSQL.Departments.Remove(model); CarraraSQL.SaveChanges(); HttpContext.Cache.Remove("DepartmentsSelectList"); TempData["Page.Title"] = "The Department Was Deleted Successfully"; return(RedirectToAction("Index", parameters)); } catch (Exception ex) { Page.Title = "The Department Was NOT Deleted! " + ex.Message; return(View("Manage", model)); } } if (ModelState.IsValid) { CarraraSQL.Entry(model).State = EntityState.Modified; CarraraSQL.SaveChanges(); HttpContext.Cache.Remove("DepartmentsSelectList"); TempData["Page.Title"] = "The Department Was Updated Successfully"; return(RedirectToAction("Index", parameters)); } Page.Title = "The Department Was NOT Updated!"; Page.Message = "Please correct the following errors:"; return(View("Manage", model)); }
public ActionResult Edit(JobStatu model) { RouteValueDictionary parameters = Request.QueryString.ToRouteValues(); if (model.Action == "Delete") { JobStatu entity = CarraraSQL.JobStatus.Find(model.JobStatusID); if (entity.Jobs.Any()) { Page.Title = "The Job Status Is In Use And Was NOT Deleted!"; Page.Message = "Set the Job Status to Inactive if you do not intend to use this Job Status again."; return(View("Manage", model)); } try { CarraraSQL.JobStatus.Attach(model); CarraraSQL.JobStatus.Remove(model); CarraraSQL.SaveChanges(); TempData["Page.Title"] = "The Job Status Was Deleted Successfully"; return(RedirectToAction("Index", parameters)); } catch (Exception ex) { Page.Title = "The Job Status Was NOT Deleted! " + ex.Message; return(View("Manage", model)); } } if (ModelState.IsValid) { CarraraSQL.Entry(model).State = EntityState.Modified; CarraraSQL.SaveChanges(); TempData["Page.Title"] = "The Job Status Was Updated Successfully"; return(RedirectToAction("Index", parameters)); } Page.Title = "The Job Status Was NOT Updated!"; Page.Message = "Please correct the following errors:"; return(View("Manage", model)); }