public async Task <IActionResult> GetBookingPost([Bind("HireDate, ReturnDate,LocationId")] Booking booking)
        {
            if (ModelState.IsValid)
            {
                var hdate    = booking.HireDate;
                var rdate    = booking.ReturnDate;
                var location = booking.LocationId;
                HttpContext.Session.SetString("ReturnDate", rdate.ToString());
                HttpContext.Session.SetString("HireDate", hdate.ToString());
                HttpContext.Session.SetString("Location", location.ToString());

                int days = (booking.ReturnDate.Date - booking.HireDate.Date).Days;
                if (days == 0)
                {
                    days = days + 1;
                }

                var allBookings = _service.GetAllBookings();

                List <Vehicle> availableVehicles = _service.FindAvailableVehicles(booking, allBookings, location);

                var Vehicles = availableVehicles
                               .Select(result => new VehiclesViewModel
                {
                    Id         = result.Id,
                    Make       = result.Make,
                    Model      = result.Model,
                    Year       = result.Year,
                    ImageUrl   = result.ImageUrl,
                    Color      = result.Color,
                    Kilometer  = result.Kilometer,
                    RatePerDay = result.RatePerDay,
                    Price      = result.RatePerDay * days,
                });

                return(View(Vehicles));
            }
            return(RedirectToAction(nameof(GetBooking)));
        }
Example #2
0
        public ActionResult <IEnumerable <BookingIndexModel> > GetAllBookings()
        {
            var bookings = _service.GetAllBookings();

            return(Ok(_mapper.Map <IEnumerable <BookingIndexModel> >(bookings)));
        }