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))); }
//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); }
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); }
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); }
//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); }
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)); }
//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")))); }
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)); }
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; }
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))); }
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; }
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) }); }
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) }); }
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); } }
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 }); }
//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); }
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; } }
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) }); }
//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); } } }
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"); } }
//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); }
//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); }
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); }
public async Task <PartialViewResult> UpdateCartModalQuantity(ShoppingCartSession shoppingCart, int bookId, int quantity) { await ShoppingCartService.UpdateQuantity(shoppingCart, bookId, quantity); return(PartialView("ModalIndex", await ShoppingCartService.GetShoppingCartModalIndex(shoppingCart))); }
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))); }
public async Task <PartialViewResult> ClearCartModal(ShoppingCartSession shoppingCart) { ShoppingCartService.Clear(shoppingCart); return(PartialView("ModalIndex", await ShoppingCartService.GetShoppingCartModalIndex(shoppingCart))); }
public async Task <PartialViewResult> ClearCart(ShoppingCartSession shoppingCart, string returnUrl) { ShoppingCartService.Clear(shoppingCart); return(PartialView("IndexPartial", await ShoppingCartService.GetShoppingCart(shoppingCart, returnUrl))); }
public async Task <PartialViewResult> RemoveAllFromCartModal(ShoppingCartSession shoppingCart, int bookId) { ShoppingCartService.RemoveLine(shoppingCart, bookId); return(PartialView("ModalIndex", await ShoppingCartService.GetShoppingCartModalIndex(shoppingCart))); }
public async Task <PartialViewResult> RemoveAllFromCart(ShoppingCartSession shoppingCart, int bookId, string returnUrl) { ShoppingCartService.RemoveLine(shoppingCart, bookId); return(PartialView("IndexPartial", await ShoppingCartService.GetShoppingCart(shoppingCart, returnUrl))); }
public async Task <PartialViewResult> AddToCart(ShoppingCartSession shoppingCart, int bookId) { ShoppingCartService.AddItem(shoppingCart, bookId); return(PartialView("ModalIndex", await ShoppingCartService.GetShoppingCartModalIndex(shoppingCart))); }