コード例 #1
0
        public ActionResult AddCar(Car car, IEnumerable <HttpPostedFileBase> fileUpload)
        {
            if (car.EngineVolume < 0)
            {
                ModelState.AddModelError("EngineVolume", "Engine volume must be greather then 0");
            }
            if (car.EnginePower < 0)
            {
                ModelState.AddModelError("EnginePower", "Engine power must be greather then 0");
            }
            if (car.Price < 0)
            {
                ModelState.AddModelError("Price", "Price must be greather then 0");
            }

            if (ModelState.IsValid)
            {
                if (CRUDCars.AddCar(car, fileUpload))
                {
                    ViewBag.NewCar = car.Make + " " + car.Model;
                    return(View("Index"));
                }
                else
                {
                    return(View("Error"));
                }
            }
            else
            {
                return(View("AddCar"));
            }
        }
コード例 #2
0
 public ActionResult Show(int id)
 {
     if (CRUDCars.GetCarById(id) != null)
     {
         ViewData.Model = CRUDCars.GetCarById(id);
         return(View("Show"));
     }
     else
     {
         return(View("Error"));
     }
 }
コード例 #3
0
        public ActionResult RemoveCar(int id)
        {
            List <Image> images = CRUDCars.RemoveCar(id);

            if (images != null)
            {
                foreach (Image item in images)
                {
                    string path = Path.Combine(Server.MapPath("~/images"), item.ProductImage);
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                }

                return(View("Index"));
            }
            else
            {
                return(View("Error"));
            }
        }