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()));
            }
        }
Exemplo n.º 2
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()));
            }
        }
Exemplo n.º 3
0
 public Vehicle(VehiclesType vehicleType)
 {
     _vehicleType = vehicleType;
 }
Exemplo n.º 4
0
 /// <summary>
 /// Delete vehicle type
 /// </summary>
 /// <param name="Type">The details of the type to delete</param>
 public void DeleteVehicleType(VehiclesType Type)
 {
     DB.Entry(Type).State = EntityState.Deleted;
     DB.SaveChanges();
 }
Exemplo n.º 5
0
 /// <summary>
 /// Edit exist vehicle type
 /// </summary>
 /// <param name="Type">The vehicle type details with the updates</param>
 public void EditVehicleType(VehiclesType Type)
 {
     DB.VehiclesTypes.Add(Type);
     DB.Entry(Type).State = EntityState.Modified;
     DB.SaveChanges();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Add new vehicle type
 /// </summary>
 /// <param name="Type">The new type details</param>
 public void AddVehicleType(VehiclesType Type)
 {
     DB.VehiclesTypes.Add(Type);
     DB.SaveChanges();
 }
Exemplo n.º 7
0
 void Awake()
 {
     instance = this;
 }