Esempio n. 1
0
        public ActionResult ParkingSpotUnbooked(int?vehicleId)
        {
            if (vehicleId == null)
            {
                return(RedirectToAction("Index", "Garage"));
            }

            CheckIn checkIn = new CheckInsVehicles().CheckInByVehicle((int)vehicleId);

            if (checkIn == null)
            {
                return(RedirectToAction("Index", "Garage"));
            }

            // Check out the vehicle ID to the parking spot
            DateTime now         = DateTime.Now;
            int      nbMonths    = (int)Math.Truncate((now - (DateTime)checkIn.CheckInTime).TotalDays / 30) + 1;
            double   totalAmount = nbMonths * checkIn.ParkingSpot.MonthlyFee();

            checkIn = db.CheckOut(checkIn.ID, now, totalAmount);

            // Displays the bill
            return(View(new ParkingSpotUnbookedVM
            {
                CheckIn = checkIn,
                NbMonths = nbMonths
            }));
        }
Esempio n. 2
0
        public ActionResult VehicleCheckedOut(int?vehicleId)
        {
            if (vehicleId == null)
            {
                return(RedirectToAction("Index", "Garage"));
            }

            CheckIn checkIn = new CheckInsVehicles().CheckInByVehicle((int)vehicleId);

            if (checkIn == null)
            {
                return(RedirectToAction("Index", "Garage"));
            }

            // Check out the vehicle ID to the parking spot
            DateTime now         = DateTime.Now;
            int      nbMinutes   = (int)Math.Truncate((now - (DateTime)checkIn.CheckInTime).TotalMinutes) + 1;
            double   totalAmount = nbMinutes * checkIn.ParkingSpot.VehicleType.DefaultFee.Fee;

            checkIn = db.CheckOut(checkIn.ID, now, totalAmount);

            // Displays the bill
            return(View(new VehicleCheckedOutVM
            {
                CheckIn = checkIn,
                NbMinutes = nbMinutes
            }));
        }
Esempio n. 3
0
        public ActionResult CheckInVehicle(SelectAVehicleVM viewModel, string errorMessage)
        {
            List <Vehicle> unparkedVehicles = new CheckInsVehicles().UnparkedVehicles().ToList();

            foreach (Vehicle vehicle in unparkedVehicles)
            {
                Vehicle vehicleTmp = vehicle;
            }

            // Allows the user to select a vehicle in the list of already exiting vehicles
            // or to create a new one
            return(View(new SelectAVehicleVM
            {
                ErrorMessage = errorMessage,
                Vehicles = new CheckInsVehicles().UnparkedVehicles().ToList(),
                VehicleID = viewModel.VehicleID,
            }));
        }
Esempio n. 4
0
        private IEnumerable <Vehicle> Sort(IEnumerable <Vehicle> list, string sortOrder)
        {
            ViewBag.RegistrationPlateSortParam  = string.IsNullOrEmpty(sortOrder) ? "regnum_desc" : "regnum_asc";
            ViewBag.OwnerSortParam              = sortOrder == "owner_asc" ? "owner_desc" : "owner_asc";
            ViewBag.VehicleVehicleTypeSortParam = sortOrder == "vehicletype_asc" ? "vehicletype_desc" : "vehicletype_asc";
            ViewBag.VehicleCheckInTimeSortParam = sortOrder == "checkin_asc" ? "checkin_desc" : "checkin_asc";
            ViewBag.ParkingSpotSortParam        = sortOrder == "spot_asc" ? "spot_desc" : "spot_asc";
            ViewBag.VehicleFeeSortParam         = sortOrder == "fee_asc" ? "fee_desc" : "fee_asc";

            ViewBag.LabelSortParam       = sortOrder == "label_asc" ? "label_desc" : "label_asc";
            ViewBag.AvailableSortParam   = sortOrder == "available_asc" ? "available_desc" : "available_asc";
            ViewBag.VehicleTypeSortParam = sortOrder == "vehicletype_asc" ? "vehicletype_desc" : "vehicletype_asc";
            ViewBag.FeeSortParam         = sortOrder == "fee_asc" ? "fee_desc" : "fee_asc";

            switch (sortOrder)
            {
            case "regnum_desc":
                list = list.OrderByDescending(v => v.RegistrationPlate);
                break;

            case "vehicletype_asc":
                list = list.OrderBy(v => v.VehicleType.Type);
                break;

            case "vehicletype_desc":
                list = list.OrderByDescending(v => v.VehicleType.Type);
                break;

            case "owner_asc":
                list = list.OrderBy(v => v.Owner);
                break;

            case "owner_desc":
                list = list.OrderByDescending(v => v.Owner);
                break;

            case "checkin_asc":
                list = new CheckInsVehicles().InnerJoin(list)
                       .OrderBy(v_ch_p => v_ch_p.CheckIn == null)
                       .ThenBy(v_ch_p => GetCheckInTime(v_ch_p.CheckIn))
                       .Select(v_ch_p => v_ch_p.Vehicle);
                break;

            case "checkin_desc":
                list = new CheckInsVehicles().InnerJoin(list)
                       .OrderBy(v_ch_p => v_ch_p.CheckIn == null)
                       .ThenByDescending(v_ch_p => GetCheckInTime(v_ch_p.CheckIn))
                       .Select(v_ch_p => v_ch_p.Vehicle);
                break;

            case "spot_asc":
                list = new CheckInsVehicles().InnerJoin(list)
                       .OrderBy(v_ch_p => v_ch_p.CheckIn == null)
                       .ThenBy(v_ch_p => GetLabel(v_ch_p.ParkingSpot))
                       .Select(v_ch_p => v_ch_p.Vehicle);
                break;

            case "spot_desc":
                list = new CheckInsVehicles().InnerJoin(list)
                       .OrderBy(v_ch_p => v_ch_p.CheckIn == null)
                       .ThenByDescending(v_ch_p => GetLabel(v_ch_p.ParkingSpot))
                       .Select(v_ch_p => v_ch_p.Vehicle);
                break;

            case "fee_asc":
                list = new CheckInsVehicles().InnerJoin(list)
                       .OrderBy(v_ch_p => v_ch_p.CheckIn == null)
                       .ThenBy(v_ch_p => GetFee(v_ch_p))
                       .Select(v_ch_p => v_ch_p.Vehicle);
                break;

            case "fee_desc":
                list = new CheckInsVehicles().InnerJoin(list)
                       .OrderBy(v_ch_p => v_ch_p.CheckIn == null)
                       .ThenByDescending(v_ch_p => GetFee(v_ch_p))
                       .Select(v_ch_p => v_ch_p.Vehicle);
                break;

            default:
                list = list.OrderBy(v => v.RegistrationPlate);
                break;
            }

            return(list);
        }