public async Task OnGet() { var currUser = _userManager.GetUserId(User); ShoppingCart = await LoadCart(currUser); CartItems = new GetCartItems(_context).Do(ShoppingCart.CartId); Products = new GetAllProducts(_context).Do() .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId) .Contains(prod.ProductId)); Categ = new GetAllCategories(_context).Do(); Order = new GetOrder(_context).Do(currUser, "Pending"); if (Order == null) { await new CreateOrder(_context).Do(new OrderViewModel { Status = "Pending", CustomerId = currUser, TotalOrdered = ShoppingCart.TotalInCart, }); Order = new GetOrder(_context).Do(currUser, "Pending"); } OrderInfos = new GetOrderInfo(_context).Do(Order.OrderId); if (OrderInfos == null) { OrderInfos = new OrderInfosViewModel(); } }
public async Task <IActionResult> OnGet() { var currUser = _userManager.GetUserId(User); ShoppingCart = new GetShoppingCart(_context).Do(currUser); CartItems = new GetCartItems(_context).Do(ShoppingCart.CartId); Products = new GetAllProducts(_context).Do() .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId) .Contains(prod.ProductId)); Order = new GetOrder(_context).Do(currUser, "Pending"); foreach (var cartitem in CartItems.ToList()) { await new CreateProductInOrder(_context).Do(new ProductInOrdersViewModel { OrderRefId = Order.OrderId, ProductRefId = cartitem.ProductRefId, UsedQuantity = cartitem.Quantity, }); await new UpdateProduct(_context, _fileManager).UpdateStockAfterOrder(cartitem.ProductRefId, cartitem.Quantity); } Order.Status = "Ordered"; Order.TotalOrdered = ShoppingCart.TotalInCart; await new UpdateOrder(_context).Do(Order); ShoppingCart.Status = "Closed"; await new UpdateShoppingCart(_context).Do(ShoppingCart); return(RedirectToPage("/Account/Manage/Orders", new { Area = "Identity" })); }
public async Task GivenASessionId_WhenNumberOfItemsInCartIsRequested_ThenCorrectNumberIsReturned() { GetCartItems getCartItems = new GetCartItems(_mockIRedisCacheClient.Object, _mockILogger.Object); var result = await getCartItems.GetItemsInCart("test"); Assert.AreEqual(2, result.Count); }
public async Task <IActionResult> PlaceOrder([FromForm] OrderViewModel vm) { if (ModelState.IsValid) { await new UpdateOrder(_context).Do(vm); var ShoppingCart = new GetShoppingCart(_context).Do(vm.CustomerId); var CartItems = new GetCartItems(_context).Do(ShoppingCart.CartId); var Products = new GetAllProducts(_context).Do(ShoppingCart.CartId, 0) .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId) .Contains(prod.ProductId)); foreach (var cartitem in CartItems.ToList()) { await new CreateProductInOrder(_context).Do(new ProductInOrdersViewModel { OrderRefId = vm.OrderId, ProductRefId = cartitem.ProductRefId, UsedQuantity = cartitem.Quantity, }); await new UpdateProduct(_context, _fileManager).UpdateStockAfterOrder(cartitem.ProductRefId, cartitem.Quantity); } ShoppingCart.Status = "Closed"; await new UpdateShoppingCart(_context).Do(ShoppingCart); return(Ok()); } return(BadRequest()); }
public async Task GivenASessionId_WhenAllItemsForSessionAreRequested_ThenAllItemsAreReturned() { GetCartItems getCartItems = new GetCartItems(_mockIRedisCacheClient.Object, _mockILogger.Object); var result = await getCartItems.GetItemsInCart("test"); Assert.AreEqual("three", result[0].Id); Assert.AreEqual("four", result[1].Id); }
public IList <CartItemInfo> GetCartItems(string userName, string appName, bool isShoppingCart) { var getCartItems = new GetCartItems(userName, appName, isShoppingCart); var returned = Utility.ServiceCall(requestURL + "/getcartitems", JsonConvert.SerializeObject(getCartItems)); var converted = JsonConvert.DeserializeObject <IList <CartItemInfo> >(returned); return(converted != null ? converted : new List <CartItemInfo>()); }
public async Task <IEnumerable <CartItem> > HandleAsync(GetCartItems query, CancellationToken cancellationToken) { var items = await _dbContext .CartItems .Where(i => i.SessionId == query.SessionId) .ToListAsync(cancellationToken) .ConfigureAwait(false); return(_mapper.Map <IEnumerable <CartItem> >(items)); }
public IList <CartItemInfo> GetCartItems([FromBody] GetCartItems cartitems) { return(DBFacilitator.GetList <CartItemInfo>( PostgreSQLConnectionString, GET_CART_ITEMS, new List <Tuple <string, string, NpgsqlDbType> >() { { new Tuple <string, string, NpgsqlDbType>(":Username", cartitems.Username, NpgsqlDbType.Text) }, { new Tuple <string, string, NpgsqlDbType>(":ApplicationName", cartitems.AppName, NpgsqlDbType.Text) }, { new Tuple <string, string, NpgsqlDbType>(":IsShoppingCart", cartitems.IsShoppingCart ? "Y" : "N", NpgsqlDbType.Char) } } )); }
public void OnGet() { var currUser = _userManager.GetUserId(User); ShoppingCart = new GetShoppingCart(_context).Do(currUser); CartItems = new GetCartItems(_context).Do(ShoppingCart.CartId); Products = new GetAllProducts(_context).Do() .Where(prod => CartItems.Select(cartItem => cartItem.ProductRefId) .Contains(prod.ProductId)); Categ = new GetAllCategories(_context).Do(); Order = new GetOrder(_context).Do(currUser, "Pending"); OrderInfos = new GetOrderInfo(_context).Do(Order.OrderId); }
public IList <CartItemInfo> GetCartItems(GetCartItems cartitems) { return(dal.GetCartItems(cartitems.Username, cartitems.AppName, cartitems.IsShoppingCart)); }