Пример #1
0
        /// <summary>
        /// Get all vehicle types as list of string
        /// </summary>
        /// <returns>To ajax The list of all vehicle types/BadRequest</returns>
        public ActionResult VehiclesTypesList()
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    string errorMessage = (from state in ModelState.Values
                                           from error in state.Errors
                                           select error.ErrorMessage).FirstOrDefault().ToString();
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, errorMessage));
                }

                using (VehiclesTypesLogic logic = new VehiclesTypesLogic())
                {
                    var q = logic.GetAllVehiclesTypes().Select(m => new
                    {
                        VehicleTypeID = m.VehicleTypeID,
                        DetailsString = m.VehicleTypeID + " " + m.Manufacturer + " " +
                                        m.Model + " " + m.ManufactureYear + " " +
                                        m.Transmission
                    }).ToList();

                    return(Json(q, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, "We have problem on the server, Please try again later!"));
            }
        }
Пример #2
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()));
     }
 }
Пример #3
0
        //Manage Vehicles Types - for the main admin page
        public ActionResult vehiclesTypesIndex()
        {
            try
            {
                using (VehiclesTypesLogic logic = new VehiclesTypesLogic())
                {
                    return(View("VehiclesTypes", logic.GetAllVehiclesTypes()));
                }
            }
            catch (Exception)
            {
                ViewBag.Error = "We have problem on the server, Please try again later!";

                return(View("VehiclesTypes", new List <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()));
            }
        }
Пример #5
0
 /// <summary>
 /// Search vehicles for rent - view page
 /// In this page the user can search vehicles for rent by to dates and filter the results by JS - jquery
 ///
 /// For the filter this action connects to the DB - if he can't connect "CriticalError" rising and the user redirect to the home page
 /// In this way the user can't start search if the server has problems.
 /// </summary>
 /// <returns>The search vehicles page</returns>
 public ActionResult Search()
 {
     try
     {
         using (VehiclesTypesLogic logic = new VehiclesTypesLogic())
         {
             ViewBag.ManufacturersList = logic.listOfManufacturer();
             ViewBag.ModelsList        = logic.listOfModels();
             ViewBag.YearsList         = logic.listOfYears();
             return(View());
         }
     }
     catch (Exception)
     {
         ViewBag.Error             = "We have problem on the server, Please try again later!";
         ViewBag.CriticalError     = true;
         ViewBag.ManufacturersList = new List <string>();
         ViewBag.ModelsList        = new List <string>();
         ViewBag.YearsList         = new List <int>();
         return(View(new VehiclesType()));
     }
 }
Пример #6
0
        public ActionResult Delete(VehiclesType deleteType)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View());
                }

                using (VehiclesTypesLogic logic = new VehiclesTypesLogic())
                {
                    logic.DeleteVehicleType(deleteType);
                }

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