Esempio n. 1
0
        public async Task <IActionResult> BookARoom(ConfirmBookingModel confirm)
        {
            if (ModelState.IsValid)
            {
                var book = new Booking
                {
                    RoomID        = confirm.RoomID,
                    CustomerEmail = User.FindFirst(ClaimTypes.Name).Value,
                    CheckIn       = confirm.CheckIn,
                    CheckOut      = confirm.CheckOut
                };

                var theRooom = await _context.Room.FindAsync(confirm.RoomID);

                book.Cost = theRooom.Price * (book.CheckOut - book.CheckIn).Days;

                _context.Add(book);
                await _context.SaveChangesAsync();

                ViewBag.cost  = book.Cost;
                ViewBag.level = book.TheRoom.Level;
                //return RedirectToAction(nameof(CIndex));
            }

            ViewData["RoomID"] = new SelectList(_context.Room, "ID", "ID", confirm.RoomID);
            return(View(confirm));
        }
Esempio n. 2
0
        public IActionResult Confirm(ConfirmBookingModel model)
        {
            if (ModelState.IsValid)
            {
                string VehicalNumber = model.StateCode + "-" + model.DistrictCode
                                       + "-" + model.SeriesCode + " " + model.Number;

                model.StartDate = model.StartDate.AddHours(model.StartHour).AddMinutes(model.StartMinute);

                if ((DateTime.Now.Subtract(model.StartDate).TotalMinutes) > 0)
                {
                    ModelState.AddModelError("", "Booking time must be after current moment.");

                    return(View(model));
                }

                DateTime EndDate = model.StartDate.AddHours(model.DurationHour).AddMinutes(model.DurationMinute);

                BookingViewModel bookingModel = new BookingViewModel()
                {
                    CustomerId    = model.UserId,
                    SlotId        = model.SlotId,
                    StartDateTime = model.StartDate,
                    EndDateTime   = EndDate,
                    VehicleNumber = VehicalNumber,
                    IsActive      = true,
                    IsConfirmed   = false,
                    Amount        = Convert.ToInt32((EndDate - model.StartDate).TotalHours * model.HourlyRate)
                };

                ResponseDetails response = _apiHelper.SendApiRequest(bookingModel, "booking/add", HttpMethod.Post);

                if (response.Success)
                {
                    bookingModel = JsonConvert.DeserializeObject <BookingViewModel>
                                       (response.Data.ToString());

                    _dataProtector.ProtectBookingRouteValues(bookingModel);

                    return(RedirectToAction("Payment", new { id = _dataProtector.Protect(bookingModel.Id) }));
                }
                else
                {
                    ErrorViewModel errorModel = new ErrorViewModel
                    {
                        Message = response.Data.ToString()
                    };

                    return(View("Error", errorModel));
                }
            }
            else
            {
                ModelState.AddModelError("", "Validation error");
                return(View(model));
            }
        }
Esempio n. 3
0
        public IActionResult ConfirmBooking(Guid bookingId, ConfirmBookingModel model)
        {
            ServiceOperationResult bookingResult;

            bookingResult = _bookingService.ConfirmOfflineBooking(bookingId, model.PaymentMethodId,
                                                                  model.Travelers.Select(t => new CreateBookingTravelerDto()
            {
                Email     = t.Email,
                FirstName = t.FirstName,
                LastName  = t.LastName,
                Id        = t.Id
            }).ToList());

            return(Ok());
        }
Esempio n. 4
0
        public IActionResult Confirm(string id)
        {
            int newId = _dataProtector.Unprotect(id);

            ResponseDetails response = _apiHelper.SendApiRequest("", "slot/get/" + newId, HttpMethod.Get);

            ConfirmBookingModel model = new ConfirmBookingModel
            {
                SlotId     = newId,
                UserId     = _tokenDecoder.UserId,
                HourlyRate = JsonConvert.DeserializeObject <SlotViewModel> (response.Data.ToString()).HourlyRate
            };

            return(View(model));
        }