Beispiel #1
0
        public ActionResult DeleteColor(int ID)
        {
            JsonResult result;

            try
            {
                bool hasVehicles = db.VehicleWizards.Any(x => x.AutoExteriorColorID == ID);
                if (hasVehicles)
                {
                    result = Json(new { IsDeleted = false, Message = AutoMax.Utility.Constants.CAN_NOT_DELETE_AS_USED_IN_VEHICLE_INFO }, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    AutoExteriorColor model = db.AutoExteriorColors.FirstOrDefault(d => d.AutoExteriorColorID == ID);
                    db.AutoExteriorColors.Remove(model);
                    db.SaveChanges();
                    result = Json(new { IsDeleted = true, Message = AutoMax.Utility.Constants.SUCCESSFULLY_DELETED }, JsonRequestBehavior.AllowGet);
                }
            }
            catch (Exception ex)
            {
                result = Json(new { IsDeleted = false, Message = ex.ToString() }, JsonRequestBehavior.AllowGet);
            }
            return(result);
        }
Beispiel #2
0
        public ActionResult Edit(AutoExteriorColor viewModel)
        {
            this.ValidateAdminUser();
            try
            {
                if (string.IsNullOrEmpty(viewModel.ExteriorColor))
                {
                    ModelState.AddModelError("ExteriorColor", "This field is required.");
                }
                if (ModelState.IsValid)
                {
                    AutoExteriorColor model;
                    if (viewModel.AutoExteriorColorID != 0)
                    {
                        model = db.AutoExteriorColors.Find(viewModel.AutoExteriorColorID);
                        if (model == null)
                        {
                            return(HttpNotFound());
                        }
                        else
                        {
                            model.ExteriorColor       = viewModel.ExteriorColor;
                            model.ArabicExteriorColor = viewModel.ArabicExteriorColor;
                            model.Value       = viewModel.Value;
                            model.UpdatedDate = DateTime.Now;
                            db.SaveChanges();
                            this.SetFlashMessage();
                            return(RedirectToAction("Index"));
                        }
                    }
                    else
                    {
                        model = new AutoExteriorColor();
                        model.ExteriorColor       = viewModel.ExteriorColor;
                        model.ArabicExteriorColor = viewModel.ArabicExteriorColor;
                        model.Value       = viewModel.Value;
                        model.CreatedDate = model.UpdatedDate = DateTime.Now;
                        model.CreatedBy   = model.UpdatedBy = 1; // HACK : Hardcoded value represents Admin user

                        db.AutoExteriorColors.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));
        }
Beispiel #3
0
        public ActionResult Edit(int id)
        {
            this.ValidateAdminUser();

            AutoExteriorColor model = new AutoExteriorColor();

            if (id != 0)
            {
                model = db.AutoExteriorColors.Find(id);
                if (model == null)
                {
                    return(HttpNotFound());
                }
            }
            return(View(model));
        }
 private long?GetAutoExteriorColorID(string colour)
 {
     try
     {
         var obj = new AutoExteriorColor();
         obj.CreatedBy     = 1;
         obj.CreatedDate   = DateTime.Now;
         obj.UpdatedBy     = 1;
         obj.UpdatedDate   = DateTime.Now;
         obj.ExteriorColor = colour;
         db.AutoExteriorColors.Add(obj);
         db.SaveChanges();
         return(obj.AutoExteriorColorID);
     }
     catch (Exception ex)
     {
         return(1);
     }
 }