Beispiel #1
0
        /// <summary>
        /// Page displays: A form to create a new rental.
        /// </summary>
        public ActionResult Create(string licensePlate, DateTime startDate, DateTime returnDate)
        {
            try
            {
                // Gets the car object, according to the license plate:
                FleetCarsLogic carsLogic = new FleetCarsLogic();
                FleetCar       car       = carsLogic.GetFleetCarByLicensePlate(licensePlate);

                // Checks if the car exists to order:
                if (car == null)
                {
                    return(new HttpNotFoundResult("Car is not found.")); // If car not exists, returns error 404 not found.
                }
                // Car exists, so creates the order view model object:
                OrderViewModel model = new OrderViewModel();
                model.LicensePlate = licensePlate;
                model.CarModelName = string.Format("{0} {1} {2} {3}", car.CarModel.ManufacturerModel.Manufacturer.ManufacturerName,
                                                   car.CarModel.ManufacturerModel.ManufacturerModelName,
                                                   car.CarModel.ProductionYear,
                                                   car.CarModel.ManualGear ? "Manual" : "Automatic");
                model.CarImage      = car.CarImage;
                model.DailyPrice    = car.CarModel.DailyPrice;
                model.DayDelayPrice = car.CarModel.DayDelayPrice;
                model.StartDate     = startDate.Date;
                model.ReturnDate    = returnDate.Date;

                return(View(model));
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage = "An error has occurred. please try again later.";
                return(View(new OrderViewModel()));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates a car in the fleet.
        /// </summary>
        /// <param name="fleetCar">The car in the fleet to update.</param>
        public void UpdateFleetCar(FleetCar fleetCar)
        {
            if (fleetCar == null)
            {
                throw new ArgumentNullException();
            }

            DB.Entry(fleetCar).State = EntityState.Modified;
            DB.SaveChanges();
        }
Beispiel #3
0
        /// <summary>
        /// Inserts a new car to the fleet.
        /// </summary>
        /// <param name="fleetCar">The car to insert.</param>
        public void InsertFleetCar(FleetCar fleetCar)
        {
            if (fleetCar == null)
            {
                throw new ArgumentNullException();
            }

            DB.FleetCars.Add(fleetCar);
            DB.SaveChanges();
        }
        /// <summary>
        /// Page displays: The details of a car in the fleet.
        /// </summary>
        public ActionResult Details(string licensePlate)
        {
            try
            {
                FleetCar fleetCar = logic.GetFleetCarByLicensePlate(licensePlate);
                if (fleetCar == null)
                {
                    return(HttpNotFound());
                }

                return(View(fleetCar));
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage = "An error has occurred. please try again later.";
                return(View(new FleetCar()));
            }
        }
        /// <summary>
        /// Page displays: A form to edit a car in the fleet.
        /// </summary>
        public ActionResult Edit(string licensePlate)
        {
            try
            {
                FleetCar fleetCar = logic.GetFleetCarByLicensePlate(licensePlate);
                if (fleetCar == null)
                {
                    return(HttpNotFound());
                }

                FleetCarViewModel model = new FleetCarViewModel();
                model.FleetCar = fleetCar;
                return(View(model));
            }
            catch (Exception)
            {
                ViewBag.ErrorMessage = "An error has occurred. please try again later.";
                return(View(new FleetCarViewModel()));
            }
        }
Beispiel #6
0
        /// <summary>
        /// Deletes a car in the fleet.
        /// </summary>
        /// <param name="fleetCar">The car in the fleet to delete.</param>
        /// <param name="isCollective">Indicator if to perform a collective delete, if to delete all it's related data.</param>
        public void DeleteFleetCar(FleetCar fleetCar, bool isCollective = false)
        {
            if (fleetCar == null)
            {
                throw new ArgumentNullException();
            }

            // Checks if to perform a collective delete:
            if (isCollective)
            {
                // Begins to delete any related data, to this fleet car:

                // Deletes all the rentals, related to this fleet car:
                List <Rental> orders = DB.Rentals.Where(r => r.LicensePlate == fleetCar.LicensePlate).ToList();
                foreach (Rental r in orders)
                {
                    DB.Rentals.Remove(r);
                }
            }

            // Deletes this fleet car:
            DB.FleetCars.Remove(fleetCar);
            DB.SaveChanges();
        }