public void ProcessRequest(BookingRequest bookingRequest)
 {
     foreach (var productRequest in bookingRequest.ProductRequests)
       {
     if (productRequest.Quantity > 0)
     {
       if (!_orderService.IsProductVariantEnabled(productRequest.VariantId))
     throw new ProductVariantNotEnabledException("Product is not available");
       var shoppingCartItem = new ShoppingCartItem
     {
       ProductVariantId = productRequest.VariantId,
       Quantity = productRequest.Quantity,
       UserId = bookingRequest.UserId
     };
       _shoppingCartRepository.Add(shoppingCartItem);
     }
       }
 }
Beispiel #2
0
 public void ProcessRequest(BookingRequest bookingRequest)
 {
     foreach (var productRequest in bookingRequest.ProductRequests)
     {
         if (productRequest.Quantity > 0)
         {
             if (!_orderService.IsProductVariantEnabled(productRequest.VariantId))
             {
                 throw new ProductVariantNotEnabledException("Product is not available");
             }
             var shoppingCartItem = new ShoppingCartItem
             {
                 ProductVariantId = productRequest.VariantId,
                 Quantity         = productRequest.Quantity,
                 UserId           = bookingRequest.UserId
             };
             _shoppingCartRepository.Add(shoppingCartItem);
         }
     }
 }
        public ActionResult StartOrder(BookingRequest bookingRequest)
        {
            if (bookingRequest.ProductRequests.Sum(r => r.Quantity) <= 0)
                ModelState.AddModelError("", "You must pick at least one room for this tour.");

            if (!string.IsNullOrWhiteSpace(bookingRequest.DiscountCode))
            {
                var validation = _discountCodeValidator.Validate(bookingRequest.DiscountCode,
                  bookingRequest.ProductRequests.Where(pr => pr.Quantity > 0).Select(pr => pr.VariantId).ToArray());
                if (!validation.IsValid)
                    ModelState.AddModelError("DiscountCode", "Sorry, this discount code is not applicable.");
            }

            if (!ModelState.IsValid) return View("ConfirmRooms", bookingRequest);

            // right now, the shopping cart doesn't really do anything
            // since we only support booking a single tour at a time
            // so, we will immediately move into the order processing phase
            bookingRequest.UserId = UserContext.UserId;

            try
            {
                _shoppingCartService.ProcessRequest(bookingRequest);
                var order = _shoppingCartService.CreatePendingOrder(UserContext.UserId);
                if (!string.IsNullOrEmpty(bookingRequest.DiscountCode))
                    _orderService.ApplyDiscountCode(order, bookingRequest.DiscountCode);
                return Redirect(Url.RouteUrl("confirm-travelers", new { orderId = order.Id }, SecureProtocol));
            }
            catch (ProductVariantNotEnabledException)
            {
                ModelState.AddModelError("", "One or more products selected are not available. Contact us for help.");
                return View("ConfirmRooms", bookingRequest);
            }
        }
        public ActionResult ConfirmRooms(string code, string package)
        {
            if (TempData["code"] != null)
            {
                code = TempData["code"].ToString();
                package = TempData["package"].ToString();
            }
            if (string.IsNullOrEmpty(code))
                return HttpNotFound();

            var departure = _tourService.FindDeparture(code);
            if (departure == null)
                return HttpNotFound();

            var bookingRequest = new BookingRequest
            {
                TourName = departure.Tour.Name,
                DepartureDate = departure.DepartureDate,
                ProductId = departure.Product.Id,
                ProductRequests = new List<ProductRequest>()
            };
            foreach (var productVariant in departure.Product.ProductVariants)
            {
                if (!productVariant.IsEnabled) continue;
                bookingRequest.ProductRequests.Add(new ProductRequest
                {
                    VariantId = productVariant.Id,
                    Price = package == "1" ? productVariant.Price : productVariant.PriceForBriter,
                    DisplayName = productVariant.DisplayName,
                    Description = productVariant.Description,
                    Quantity = 0,
                    PeoplePerRoom = CalculatePeoplePerRoom(productVariant)
                });
            }

            return View("ConfirmRooms", bookingRequest);
        }