Пример #1
0
 //Delete vehicle type page - show only
 public ActionResult Delete(int?id)
 {
     try
     {
         using (VehiclesTypesLogic logic = new VehiclesTypesLogic())
         {
             return(View(logic.GetOneVehicleTypeDetails(id)));
         }
     }
     catch (Exception)
     {
         ViewBag.Error         = "We have problem on the server, Please try again later!";
         ViewBag.CriticalError = true;
         return(View(new VehiclesType()));
     }
 }
        public ActionResult Create(VehiclesFleet car)
        {
            try
            {
                #region TypeToAdd
                VehiclesType       typeToAdd = new VehiclesType();
                VehiclesTypesLogic logicType = new VehiclesTypesLogic();
                var type = logicType.GetOneVehicleTypeDetails(car.TypeID);


                typeToAdd.DailyRentCost    = type.DailyRentCost;
                typeToAdd.Manufacturer     = type.Manufacturer;
                typeToAdd.ManufactureYear  = type.ManufactureYear;
                typeToAdd.Model            = type.Model;
                typeToAdd.Picture          = type.Picture;
                typeToAdd.RentCostForDelay = type.RentCostForDelay;
                typeToAdd.Transmission     = type.Transmission;

                car.Type = typeToAdd;
                #endregion

                VehiclesFleetLogic numToCheck = new VehiclesFleetLogic();
                if (!numToCheck.CheckVehicleNumber(car.CarNumber))
                {
                    ModelState.AddModelError("CarNumber", "The number already exists!");
                }

                if (!ModelState.IsValid)
                {
                    return(View());
                }

                using (VehiclesFleetLogic logic = new VehiclesFleetLogic())
                {
                    logic.AddVehiclesToFleet(car);
                }

                return(RedirectToAction("Index", "MangeHome"));
            }
            catch
            {
                ViewBag.Error = "We have problem on the server, Please try again!";
                return(View(new VehiclesFleet()));
            }
        }