コード例 #1
0
        public async Task <ActionResult> SummaryPartial(ShoppingCartSession shoppingCart)
        {
            var userId = User.Identity.GetUserId();
            var user   = await UserManager.FindByIdAsync(userId);

            return(PartialView(await ShoppingCartService.GetSummaryViewModel(shoppingCart, user)));
        }
コード例 #2
0
        //Sprawdza możliwości dostawy zależnie od wybranego rodzaju produktów
        private async Task <Delivery> SetDelivery(ShoppingCartSession shoppingCart)
        {
            var onlyElectronic = await CheckIfOnlyElectronic(shoppingCart);

            if (shoppingCart.Delivery == null)
            {
                if (onlyElectronic)
                {
                    return(await SetOnlyElectronicDelivery(shoppingCart));
                }

                return(await SetCourierDelivery(shoppingCart));
            }

            if (onlyElectronic)
            {
                return(await SetOnlyElectronicDelivery(shoppingCart));
            }

            if (!onlyElectronic && shoppingCart.Delivery.DeliveryType.Equals("Przesyłka elektroniczna"))
            {
                return(await SetCourierDelivery(shoppingCart));
            }

            return(shoppingCart.Delivery);
        }
コード例 #3
0
        private async Task <Payment> SetCreditCardPayment(ShoppingCartSession shoppingCart)
        {
            var creditCardPayment = await _unitOfWork.PaymentRepository.SingleOrDefault(x => x.PaymentType.Equals("Płatność kartą kredytową"));

            shoppingCart.Payment = creditCardPayment;

            return(creditCardPayment);
        }
コード例 #4
0
        private async Task <Delivery> SetCourierDelivery(ShoppingCartSession shoppingCart)
        {
            var courierDelivery = await _unitOfWork.DeliveryRepository.SingleOrDefault(x => x.DeliveryType.Equals("Przesyłka kurierska"));

            shoppingCart.Delivery = courierDelivery;

            return(courierDelivery);
        }
コード例 #5
0
        //Opcje tylko dla elektronicznych (ebook, audiobook)
        private async Task <Delivery> SetOnlyElectronicDelivery(ShoppingCartSession shoppingCart)
        {
            var electronicDelivery = await _unitOfWork.DeliveryRepository.SingleOrDefault(x => x.DeliveryType.Equals("Przesyłka elektroniczna"));

            shoppingCart.Delivery = electronicDelivery;

            return(electronicDelivery);
        }
コード例 #6
0
        public async Task <ActionResult> DeliveryData(ShoppingCartSession shoppingCart)
        {
            var userId = User.Identity.GetUserId();
            var user   = await UserManager.FindByIdAsync(userId);

            var model = ShoppingCartService.GetDeliveryData(shoppingCart, user);

            return(View(model));
        }
コード例 #7
0
        //Sprawdza czy wszystkie są elektroniczne (ebook, audiobook)
        private async Task <bool> CheckIfOnlyElectronic(ShoppingCartSession shoppingCart)
        {
            var shoppingCartLines = await MapShoppingCartLines(shoppingCart.ShoppingCartLines);

            return(shoppingCartLines.All(
                       x =>
                       x.Book.SubMainCategories.Any(
                           s => s.MainCategory.Name.Equals("Ebooki") || s.MainCategory.Name.Equals("Audiobooki"))));
        }
コード例 #8
0
        public async Task <ActionResult> Checkout(ShoppingCartSession shoppingCart)
        {
            var userId = User.Identity.GetUserId();
            var user   = await UserManager.FindByIdAsync(userId);

            var result = await ShoppingCartService.Checkout(shoppingCart, user);

            return(View(result));
        }
コード例 #9
0
 public OrderController(IOrderService orderService, IOrderItemService orderItemService, IShoppingCartService shoppingCartService, IMapper mapper, ShoppingCartSession session, ICustomerService customerService)
 {
     _orderService        = orderService;
     _orderItemService    = orderItemService;
     _shoppingCartService = shoppingCartService;
     _mapper          = mapper;
     Session          = session;
     _customerService = customerService;
 }
コード例 #10
0
        public async Task <ActionResult> Summary(ShoppingCartSession shoppingCart)
        {
            var userId = User.Identity.GetUserId();
            var user   = await UserManager.FindByIdAsync(userId);

            if (string.IsNullOrEmpty(user.FirstName) && !ShoppingCartService.IsOtherDeliveryAddress(shoppingCart))
            {
                return(RedirectToAction("UpdateMyProfileData", "Manage"));
            }

            return(View(await ShoppingCartService.GetSummaryViewModel(shoppingCart, user)));
        }
コード例 #11
0
 public HomeController(IProductItemService productItemService, IComboService comboService, IIngredientService ingredientService, IShoppingCartService shoppingCartService, IMapper mapper, ILogger <HomeController> logger, ShoppingCartSession session, ICustomizeProductService customizeProductService, ICustomizeProductIngredientService customizeProductIngredientService)
 {
     _productItemService  = productItemService;
     _comboService        = comboService;
     _ingredientService   = ingredientService;
     _shoppingCartService = shoppingCartService;
     _mapper = mapper;
     _logger = logger;
     Session = session;
     _customizeProductService           = customizeProductService;
     _customizeProductIngredientService = customizeProductIngredientService;
 }
コード例 #12
0
        public async Task <ShoppingCartViewModel> GetShoppingCartModalIndex(ShoppingCartSession shoppingCart)
        {
            var shoppingCartLines = await MapShoppingCartLines(shoppingCart.ShoppingCartLines);

            shoppingCart.ReturnUrl = shoppingCart.ReturnUrl;

            return(new ShoppingCartViewModel
            {
                ShoppingCartLines = shoppingCartLines,
                ReturnUrl = shoppingCart.ReturnUrl,
                TotalProductsValue = ComputeTotalProductValue(shoppingCartLines)
            });
        }
コード例 #13
0
        public ShoppingCartViewModel GetShoppingCartModal(ShoppingCartSession shoppingCart)
        {
            var shoppingCartLines = MapShoppingCartLinesSync(shoppingCart.ShoppingCartLines);

            shoppingCart.ReturnUrl = shoppingCart.ReturnUrl;

            return(new ShoppingCartViewModel
            {
                ShoppingCartLines = shoppingCartLines,
                ReturnUrl = shoppingCart.ReturnUrl,
                TotalProductsValue = ComputeTotalProductValue(shoppingCartLines)
            });
        }
コード例 #14
0
        public void RemoveItem(ShoppingCartSession shoppingCart, int bookId)
        {
            var line = shoppingCart.ShoppingCartLines.FirstOrDefault(l => l.BookId == bookId);

            if (line?.Quantity > 1)
            {
                line.Quantity -= 1;
            }
            else
            {
                RemoveLine(shoppingCart, bookId);
            }
        }
コード例 #15
0
        public async Task <SummaryViewModel> GetSummaryViewModel(ShoppingCartSession shoppingCart, ApplicationUser user)
        {
            var model = await GetShoppingCart(shoppingCart);

            return(new SummaryViewModel
            {
                ShoppingCartLines = model.ShoppingCartLines,
                TotalProductsValue = model.TotalProductsValue,
                TotalCost = model.TotalCost,
                Delivery = model.Delivery,
                Payment = model.Payment,
                OtherDeliveryAddress = shoppingCart.OtherDeliveryAddressViewModel,
                User = user
            });
        }
コード例 #16
0
        //sprawdza możliwości płatności w zależności od wybranego rodzaju produktu
        private async Task <Payment> SetPayment(ShoppingCartSession shoppingCart)
        {
            var onlyElectronic = await CheckIfOnlyElectronic(shoppingCart);

            if (shoppingCart.Payment == null)
            {
                return(await SetCreditCardPayment(shoppingCart));
            }

            if (onlyElectronic && (shoppingCart.Payment.PaymentType.Equals("Płatność przy odbiorze") ||
                                   shoppingCart.Payment.PaymentType.Equals("Płatność za pobraniem")))
            {
                await SetCreditCardPayment(shoppingCart);
            }

            return(shoppingCart.Payment);
        }
コード例 #17
0
        public void AddItem(ShoppingCartSession shoppingCart, int bookId)
        {
            //Wyszukuje konkretna linie koszyka, aby ją zmodyfikować
            var line = shoppingCart.ShoppingCartLines.FirstOrDefault(l => l.BookId == bookId);

            if (line == null)
            {
                shoppingCart.ShoppingCartLines.Add(new ShoppingCartLineSession
                {
                    BookId   = bookId,
                    Quantity = 1
                });
            }
            else
            {
                line.Quantity += 1;
            }
        }
コード例 #18
0
        public async Task <ShoppingCartViewModel> GetShoppingCart(ShoppingCartSession shoppingCart, string returnUrl = null)
        {
            var shoppingCartLines = await MapShoppingCartLines(shoppingCart.ShoppingCartLines);

            var delivery = await SetDelivery(shoppingCart);

            shoppingCart.ReturnUrl = returnUrl;

            return(new ShoppingCartViewModel
            {
                ReturnUrl = returnUrl,
                ShoppingCartLines = shoppingCartLines,
                TotalProductsValue = ComputeTotalProductValue(shoppingCartLines),
                TotalCost = ComputeTotalCost(shoppingCartLines, delivery.Price),
                Delivery = delivery,
                Payment = await SetPayment(shoppingCart),
                DeliveryOptions = await SetDeliveryOptions(shoppingCart),
                PaymentOptions = await SetPaymentOptions(shoppingCart)
            });
        }
コード例 #19
0
        //Zmienia stan ilości wybranego produktu
        public async Task UpdateQuantity(ShoppingCartSession shoppingCart, int bookId, int quantity)
        {
            var shoppingCartLines = shoppingCart.ShoppingCartLines;
            var line = shoppingCartLines.FirstOrDefault(l => l.BookId == bookId);
            var book = await _unitOfWork.BookRepository.Find(bookId);

            if (line == null)
            {
                if (quantity > 0 && quantity <= book.Quantity)
                {
                    shoppingCartLines.Add(new ShoppingCartLineSession
                    {
                        BookId   = bookId,
                        Quantity = quantity
                    });
                }
                else if (quantity > book.Quantity)
                {
                    shoppingCartLines.Add(new ShoppingCartLineSession
                    {
                        BookId   = bookId,
                        Quantity = book.Quantity
                    });
                }
            }
            else
            {
                if (quantity > 0 && quantity <= book.Quantity)
                {
                    line.Quantity = quantity;
                }
                else if (quantity > book.Quantity)
                {
                    line.Quantity = book.Quantity;
                }
                else
                {
                    shoppingCartLines.RemoveAll(l => l.BookId == book.Id);
                }
            }
        }
コード例 #20
0
            public async Task <Unit> Handle(ShoppingCartRequest request, CancellationToken cancellationToken)
            {
                var shoppingCartSession = new ShoppingCartSession()
                {
                    CreationDate = request.CreationSessionDate
                };

                _context.ShoppingCartSessions.Add(shoppingCartSession);

                var newRows = await _context.SaveChangesAsync();

                if (newRows == 0)
                {
                    throw new Exception("Something goes wrong creating the session");
                }

                int sessionId = shoppingCartSession.ShopingCartSessionId;

                await _context.ShoppingCartDetails.AddRangeAsync(
                    request.ProductList.Select(p =>
                                               new ShoppingCartDetail()
                {
                    ShopingCartSessionId = sessionId,
                    CreationDate         = request.CreationSessionDate,
                    SelectedProduct      = p
                }
                                               ));

                newRows = await _context.SaveChangesAsync();

                if (newRows > 0)
                {
                    return(Unit.Value);
                }
                else
                {
                    throw new Exception("Something goes wrong with the insertion of the details");
                }
            }
コード例 #21
0
        //Ustawia możliwośći dostawy
        private async Task <List <Delivery> > SetDeliveryOptions(ShoppingCartSession shoppingCart)
        {
            var deliveryOptions = new List <Delivery>();
            var onlyElectronic  = await CheckIfOnlyElectronic(shoppingCart);

            if (onlyElectronic)
            {
                var delivery =
                    await _unitOfWork.DeliveryRepository.SingleOrDefault(x => x.DeliveryType.Equals("Przesyłka elektroniczna"));

                deliveryOptions.Add(delivery);
            }

            else
            {
                var noElectronicDeliveries =
                    await _unitOfWork.DeliveryRepository.FindAll(x => !x.DeliveryType.Equals("Przesyłka elektroniczna"));

                deliveryOptions.AddRange(noElectronicDeliveries);
            }

            return(deliveryOptions);
        }
コード例 #22
0
        //Ustawia możliwości płatności
        private async Task <List <Payment> > SetPaymentOptions(ShoppingCartSession shoppingCart)
        {
            var paymentOptions = new List <Payment>();
            var onlyElectronic = await CheckIfOnlyElectronic(shoppingCart);

            if (onlyElectronic)
            {
                var payment =
                    await _unitOfWork.PaymentRepository.FindAll(x => x.PaymentType.Equals("Płatność kartą kredytową") || x.PaymentType.Equals("Płatność przelewem bankowym"));

                paymentOptions.AddRange(payment);
            }

            else
            {
                var allPaymentOptions =
                    await _unitOfWork.PaymentRepository.GetAll();

                paymentOptions.AddRange(allPaymentOptions);
            }

            return(paymentOptions);
        }
コード例 #23
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            ShoppingCartSession shoppingCart = null;

            if (controllerContext.HttpContext.Session != null)
            {
                shoppingCart = (ShoppingCartSession)controllerContext.HttpContext.Session[SessionKey];
            }

            if (shoppingCart == null)
            {
                shoppingCart = new ShoppingCartSession
                {
                    ShoppingCartLines = new List <ShoppingCartLineSession>()
                };

                if (controllerContext.HttpContext.Session != null)
                {
                    controllerContext.HttpContext.Session[SessionKey] = shoppingCart;
                }
            }

            return(shoppingCart);
        }
コード例 #24
0
        public async Task <PartialViewResult> UpdateCartModalQuantity(ShoppingCartSession shoppingCart, int bookId, int quantity)
        {
            await ShoppingCartService.UpdateQuantity(shoppingCart, bookId, quantity);

            return(PartialView("ModalIndex", await ShoppingCartService.GetShoppingCartModalIndex(shoppingCart)));
        }
コード例 #25
0
        public async Task <PartialViewResult> UpdateCartQuantity(ShoppingCartSession shoppingCart, int bookId, string returnUrl, int quantity)
        {
            await ShoppingCartService.UpdateQuantity(shoppingCart, bookId, quantity);

            return(PartialView("IndexPartial", await ShoppingCartService.GetShoppingCart(shoppingCart, returnUrl)));
        }
コード例 #26
0
        public async Task <PartialViewResult> ClearCartModal(ShoppingCartSession shoppingCart)
        {
            ShoppingCartService.Clear(shoppingCart);

            return(PartialView("ModalIndex", await ShoppingCartService.GetShoppingCartModalIndex(shoppingCart)));
        }
コード例 #27
0
        public async Task <PartialViewResult> ClearCart(ShoppingCartSession shoppingCart, string returnUrl)
        {
            ShoppingCartService.Clear(shoppingCart);

            return(PartialView("IndexPartial", await ShoppingCartService.GetShoppingCart(shoppingCart, returnUrl)));
        }
コード例 #28
0
        public async Task <PartialViewResult> RemoveAllFromCartModal(ShoppingCartSession shoppingCart, int bookId)
        {
            ShoppingCartService.RemoveLine(shoppingCart, bookId);

            return(PartialView("ModalIndex", await ShoppingCartService.GetShoppingCartModalIndex(shoppingCart)));
        }
コード例 #29
0
        public async Task <PartialViewResult> RemoveAllFromCart(ShoppingCartSession shoppingCart, int bookId, string returnUrl)
        {
            ShoppingCartService.RemoveLine(shoppingCart, bookId);

            return(PartialView("IndexPartial", await ShoppingCartService.GetShoppingCart(shoppingCart, returnUrl)));
        }
コード例 #30
0
        public async Task <PartialViewResult> AddToCart(ShoppingCartSession shoppingCart, int bookId)
        {
            ShoppingCartService.AddItem(shoppingCart, bookId);

            return(PartialView("ModalIndex", await ShoppingCartService.GetShoppingCartModalIndex(shoppingCart)));
        }