Beispiel #1
0
        public async Task <IActionResult> Index(BookViewModel bookViewModel)
        {
            if (ModelState.IsValid)
            {
                string paxId = HttpContext.Session.GetString(SessionDataKeys.PaxId);

                //Calculate Product Price
                ProductPriceDTO productPrice = await getProductPricing(bookViewModel.ProductId, bookViewModel.CheckInDate, bookViewModel.CheckInTime);

                bookViewModel.CalculateFinalPrice(productPrice);

                //Create Booking
                CreateBookingCommand createBookingCommand = new CreateBookingCommand
                {
                    Name = bookViewModel.ProductName
                };
                CreateBookingCommandItem bookingItem = new CreateBookingCommandItem()
                {
                    ProductId   = bookViewModel.ProductId,
                    DateCheckIn = bookViewModel.CheckInDate.ToJsonDateTime(bookViewModel.CheckInTime),
                };
                bookingItem.PaxId.Add(paxId);
                createBookingCommand.BookingProducts.Add(bookingItem);
                BookingProductDTO bookingProductDTO = await _heroService.BookingApi.CreateBookingAsync(createBookingCommand);

                //Validate Booking
                BookingValidationResultDTO bookResult = await _heroService.BookingApi.ValidateBookingAsync(bookingProductDTO.Id);

                if (bookResult.IsValid)
                {
                    //Create the payment
                    CreatePaymentCommand createPaymentCommand = new CreatePaymentCommand()
                    {
                        Amount    = bookViewModel.FinalPrice,
                        BookingId = bookingProductDTO.Id,
                        IsFinal   = true,
                        Method    = PaymentMethod.Cash,
                        PaxId     = paxId
                    };
                    await _heroService.PaymentApi.CreatePaymentAsync(createPaymentCommand);

                    return(RedirectToAction("Index", "Voucher", new { bookingId = bookingProductDTO.Id, paxId }));
                }
                else
                {
                    this.ModelState.AddModelError("BookValidation", "Book validation failed please retry");
                }
            }
            return(View(bookViewModel));
        }
Beispiel #2
0
        public async Task <IActionResult> CheckPrice(CheckPriceViewModel checkPriceViewModel)
        {
            string          sessionBook     = HttpContext.Session.GetString(SessionDataKeys.MyBook);
            BookViewModel   bookViewModel   = JsonConvert.DeserializeObject <BookViewModel>(sessionBook);
            ProductPriceDTO productPriceDTO = await getProductPricing(bookViewModel.ProductId, checkPriceViewModel.CheckInDate, checkPriceViewModel.CheckInTime);

            bookViewModel.CalculateFinalPrice(productPriceDTO);

            var priceSnapShot = new
            {
                DiscountAmount = $"{bookViewModel.Currency} {bookViewModel.DiscountAmount}",
                FinalPrice     = $"{bookViewModel.Currency} {bookViewModel.FinalPrice}",
                OriginalPrice  = $"{bookViewModel.Currency} {bookViewModel.OriginalPrice}",
            };

            return(Json(priceSnapShot));
        }