public async Task AddProductToBasket_When_ProductToAdded_Doenst_Exist_Return_BeAddedProductDoesntExist_Message() { _mockProductService.Setup(repo => repo.GetProductById("productId")).Returns(Task.FromResult(default(Product))); var response = await _basketService.AddProductToBasket(new AddProductToBasketContext { BasketId = "basketId", ProductId = "productId" }); Assert.True(response.Message == Constants.BasketService.BeAddedProductDoesntExist); }
public async Task <IActionResult> AddProductToBasket([FromBody] AddProductToBasketRequest request) { var response = await _basketService.AddProductToBasket(new AddProductToBasketContext { BasketId = request.BasketId, ProductId = request.ProductId }); if (response.IsSuccessful) { _logger.LogInformation($"Product {request.ProductId} added to basket {request.BasketId}"); } return(Ok(response)); }
public ActionResult <bool> Put(string id, [FromQuery] string productId) { try { // Add Product's id to the basket return(_basketService.AddProductToBasket(id, productId)); } catch (Exception e) { // Return message to the client explaining the issue return(StatusCode(400, e.Message)); } }
public int Execute(AddItemOptions options, Basket basket) { var result = basketService.AddProductToBasket(basket, options.ItemName, options.Quantity); if (result) { Console.WriteLine($"Successfully added {options.Quantity} {options.ItemName} to the basket"); } else { Console.WriteLine($"Could not add {options.Quantity} {options.ItemName} to the basket, please ensure it is a valid input"); } return(0); }
public async Task <ActionResult> Add(int id) { Console.WriteLine("Adding product with ID: " + id + " to basket"); if (await _productService.DoesProductIdExist(id)) { string userId = _userManager.GetUserId(User); _basketService.AddProductToBasket(id, userId); string productQuantitiesInBasket = _basketService.GetProductQuantitiesInBasketAsJsonString(userId); return(Ok(productQuantitiesInBasket)); } else { return(NotFound()); } }
public async Task <IActionResult> AddProductToBasket(string basketId, int productId) { if (!await basketService.Exists(basketId)) { return(NotFound("Basket does not exists.")); } if (!await productService.Exists(productId)) { return(NotFound("Product does not exists.")); } await basketService.AddProductToBasket(basketId, productId); return(NoContent()); }
public async Task <int> InsertProductToBasket([FromForm] string ProductID, [FromForm] int Quantity) { string UserID = HttpContext.Session.GetString("UserID"); try { if (UserID == null) { throw new UnauthorizedAccessException(); } return(await _basketService.AddProductToBasket(UserID, ProductID, Quantity)); } catch (UnauthorizedAccessException e) { HttpContext.Response.StatusCode = 401; HttpContext.Response.WriteAsync(e.Message.ToString()).Wait(); return(0); } }
public ActionResult AddToBasket(Guid productGuid) { var shopGuid = Session[SessionKeys.ClientSelectedShopGuid]; if (shopGuid == null) { return(View("~/Views/ClientCore/ShopNotFound.cshtml")); } Guid parsedShopGuid; if (!Guid.TryParse(shopGuid.ToString(), out parsedShopGuid)) { return(View("~/Views/ClientCore/ShopNotFound.cshtml")); } ServiceActionResult result = _basketService.AddProductToBasket(parsedShopGuid, productGuid, User.Identity.Name); if (result.Status == ActionStatus.Successfull) { return(View("ProductAddedToBasket")); } return(View("UnexpectedError", result)); }
public static void OpenGeneralOperations() { Console.WriteLine($"Choose operation (please enter the number):\n " + $"{(int)GeneralOperationsEnum.ListProducts} - Get list of Products\n " + $"{(int)GeneralOperationsEnum.ByProduct} - By the Product\n " + $"{(int)GeneralOperationsEnum.OpenBasket} - Open my Basket\n " + $"{(int)GeneralOperationsEnum.CloseProgram} - Close Program\n" + $"{(int)GeneralOperationsEnum.Discounts} - Get All Discounts\n"); string value = Console.ReadLine(); int operationNumber; int.TryParse(value, out operationNumber); switch (operationNumber) { case (int)GeneralOperationsEnum.ListProducts: Helpers.ShowProductsInMarket(productService.GetProducts()); break; case (int)GeneralOperationsEnum.ByProduct: Helpers.ShowProductsInMarket(productService.GetProducts()); Console.WriteLine("Choose the product (please enter Id product)"); string productId = Console.ReadLine(); Product product = productService.GetProduct(productId); if (product != null) { productService.RemoveProduct(product); basketService.AddProductToBasket(product); } else { Console.WriteLine("Product was not found please try again"); } break; case (int)GeneralOperationsEnum.OpenBasket: List <ProductResponseModel> productsInBasket = basketService.ListProducts(); List <Product> wholeProductsInBasket = basketService.ListWholeProducts(); if (wholeProductsInBasket.Any()) { BasketService basketServiceUpCast = basketService as BasketService; Dictionary <string, double> discounts = basketServiceUpCast.CheckDiscounts(wholeProductsInBasket); double basketSum = wholeProductsInBasket.Sum(x => x.Cost); foreach (var item in productsInBasket) { Console.WriteLine("\nName - {0},\n Count - {1},\n Sub-total-item - {2}", item.ProductName, item.CountProducts, wholeProductsInBasket.Where(x => x.ProductId == item.ProductId).Sum(x => x.Cost)); Console.WriteLine("Any discount applicable - {0}", discounts.FirstOrDefault(x => x.Key == item.ProductId).Value); } Console.WriteLine("Sub-total of the basket - {0}", basketSum); Console.WriteLine("Grant Total Price - {0}", Math.Abs(basketSum - discounts.Values.Sum())); Console.WriteLine(new string('-', 80)); OpenBasketOperations(); } else { Console.WriteLine("Basket is empty"); } break; case (int)GeneralOperationsEnum.CloseProgram: return; case (int)GeneralOperationsEnum.Discounts: foreach (var item in DataDiscount.DiscountDatas) { Console.WriteLine(item.Name); } break; default: Console.WriteLine("Provide operation is incorrect, please try again"); break; } Console.WriteLine(new string('-', 80)); OpenGeneralOperations(); }
public async Task <IActionResult> AddProductToBasket(EditProductToBasketInputDTO input) { return(HttpEntity(await _basketService.AddProductToBasket(input))); }