public ActionResult DeleteColor(int ID) { JsonResult result; try { bool hasVehicles = db.VehicleWizards.Any(x => x.AutoInteriorColorID == ID); if (hasVehicles) { result = Json(new { IsDeleted = false, Message = AutoMax.Utility.Constants.CAN_NOT_DELETE_AS_USED_IN_VEHICLE_INFO }, JsonRequestBehavior.AllowGet); } else { AutoInteriorColor model = db.AutoInteriorColors.FirstOrDefault(d => d.AutoInteriorColorID == ID); db.AutoInteriorColors.Remove(model); db.SaveChanges(); result = Json(new { IsDeleted = true, AutoMax.Utility.Constants.SUCCESSFULLY_DELETED }, JsonRequestBehavior.AllowGet); } } catch (Exception ex) { result = Json(new { IsDeleted = false, Message = ex.ToString() }, JsonRequestBehavior.AllowGet); } return(result); }
public ActionResult Edit(AutoInteriorColor viewModel) { this.ValidateAdminUser(); try { if (string.IsNullOrEmpty(viewModel.InteriorColor)) { ModelState.AddModelError("InteriorColor", "This field is required."); } if (ModelState.IsValid) { AutoInteriorColor model; if (viewModel.AutoInteriorColorID != 0) { model = db.AutoInteriorColors.Find(viewModel.AutoInteriorColorID); if (model == null) { return(HttpNotFound()); } else { model.InteriorColor = viewModel.InteriorColor; model.ArabicInteriorColor = viewModel.ArabicInteriorColor; model.Value = viewModel.Value; model.UpdatedDate = DateTime.Now; db.SaveChanges(); this.SetFlashMessage(); return(RedirectToAction("Index")); } } else { model = new AutoInteriorColor(); model.InteriorColor = viewModel.InteriorColor; model.ArabicInteriorColor = viewModel.ArabicInteriorColor; model.Value = viewModel.Value; model.CreatedDate = model.UpdatedDate = DateTime.Now; model.CreatedBy = model.UpdatedBy = 1; // HACK : Hardcoded value represents Admin user db.AutoInteriorColors.Add(model); db.SaveChanges(); this.SetFlashMessage(); return(RedirectToAction("Index")); } } } catch (Exception ex) { this.SetFlashMessage("Some Error occured. Error : " + ex.Message, isError: true); // log exception ex.Message } return(View(viewModel)); }
public ActionResult Edit(int id) { this.ValidateAdminUser(); AutoInteriorColor model = new AutoInteriorColor(); if (id != 0) { model = db.AutoInteriorColors.Find(id); if (model == null) { return(HttpNotFound()); } } return(View(model)); }