Ejemplo n.º 1
0
        public static double GetCarParkingSum(Car car)
        {
            if (car.HasContract)
            {
                _sum = ContractFee;
            }
            else
            {
                var elapsedTime = car.EntryTime - DateTime.Now;

                _sum = (elapsedTime.Hours+1)*HourlyFee;
            }
            return _sum;
        }
Ejemplo n.º 2
0
 public ActionResult AddParkingCar(Car car)
 {
     _repository.AddCarToParkingLot(car, this);
     if (ModelState.IsValid)
     {
         _repository.AddCar(car);
         ParkingLot.CarsParking = _repository.Cars.Count();
         TempData["message"] = "A vehicle has entered the parking house!";
         return RedirectToAction("List");
     }
     TempData["message"] = "The vehicle does not fit.";
     TempData["error"] = string.Join("; ", ModelState.Values
         .SelectMany(x => x.Errors)
         .Select(x => x.ErrorMessage));
     return RedirectToAction("List");
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Adds cars into parking spaces according if car has contract or not.
        /// </summary>
        /// <param name="car">Car which is being added</param>
        /// <param name="parkingController">Used to set modelstate to false if any errors occur</param>
        public void AddCarToParkingLot(Car car, ParkingController parkingController)
        {
            var carsInParkingLotWithContract = context.Cars.Count(c => c.HasContract);
            var carsInParkingLot = context.Cars.Count();

            if (!HasFreeParkingSpaces(carsInParkingLot))
            {
                parkingController.ModelState.AddModelError("error",
                    "The parking house is full. Come back later.");
                return;
            }

            // try to add a car with contract
            if (CanAddCarsWhenNoFreeSpaceLeft(carsInParkingLot, carsInParkingLotWithContract, car.HasContract))
            {
                context.Cars.Add(car);
                return;
            }

            // try to add a car with no contract
            if (CanAddCarsWhenNoFreeSpaceLeft(carsInParkingLot, carsInParkingLotWithContract, !car.HasContract))
            {
                var reservedSpaces = GetReservedSpaces(carsInParkingLotWithContract);
                if (GetFreeSpaces(carsInParkingLotWithContract, reservedSpaces) <= 0)
                {
                    parkingController.ModelState.AddModelError("error",
                        string.Format(
                            "Last {0} spot(s) reserved for clients with a contract. Come back later.",
                            reservedSpaces));
                    return;
                }

                // Add a car only if there are free spaces left
                context.Cars.Add(car);
            }
        }
Ejemplo n.º 4
0
 public void AddCar(Car car)
 {
     car.EntryTime = DateTime.Now;
     context.Cars.Add(car);
     context.SaveChanges();
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Generates a single instance of a car
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="length"></param>
 /// <param name="width"></param>
 /// <param name="hasContract"></param>
 /// <returns></returns>
 private Car GenerateCar(int ID, decimal length, decimal width, bool hasContract)
 {
     var car = new Car
     {
         CarID = ID,
         CarWidth = length,
         CarLength = width,
         HasContract = hasContract
     };
     return car;
 }