public void TestProduct3() { var products = new Produt { prouctItems = new List <ProdutItems>() { new ProdutItems() { productId = 1, productName = "P1", productCost = 1, productValue = 3 }, new ProdutItems() { productId = 2, productName = "P2", productCost = 2, productValue = 5 }, new ProdutItems() { productId = 3, productName = "P3", productCost = 3, productValue = 6 }, new ProdutItems() { productId = 4, productName = "P4", productCost = 4, productValue = 16 } } }; int budget = 5; Assert.AreEqual(19, ShoppingProduct.GetMaxValue(budget, products)); }
public IActionResult Post([FromBody] ShoppingProduct shoppingproduct) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (shoppingproduct.Id == 0) { var validateShoppingProduct = _shoppingproductservices.existsShopping(shoppingproduct); if (validateShoppingProduct == "OK") { _shoppingproductservices.createShoppingProduct(shoppingproduct); } else { this.ModelState.AddModelError("400", validateShoppingProduct); return(BadRequest(ModelState)); } } else { _shoppingproductservices.updateShoppingProduct(shoppingproduct); } return(Ok(shoppingproduct)); }
public static ShoppingProductBTO ShoppingProductToShoppingProductBTO(this ShoppingProduct shoppingProduct) { return(new ShoppingProductBTO { Id = shoppingProduct.id, ProductId = shoppingProduct.productId, quantity = shoppingProduct.quantity, ShoppingBasketId = shoppingProduct.shoppingBasketId }); }
public ShoppingProductJson ConvertToJson(ShoppingProduct shoppingProduct) { var shoppingProductJson = new ShoppingProductJson() { id = shoppingProduct.Id, name = shoppingProduct.Name, pricePerUnit = shoppingProduct.PricePerUnit, productId = shoppingProduct.ProductId, quantity = shoppingProduct.Quantity }; return(shoppingProductJson); }
/// <summary> /// Verifiy if an specific tuple of Product-ShoppingList already exists in the data repository /// </summary> /// <param name="shoppingproduct">An instance of ShoppingProduct object to verify</param> /// <returns>A string with the result explanation, "OK" mean Do Not Exists</returns> public string existsShopping(ShoppingProduct shoppingproduct) { var result = _repo.Query <ShoppingProduct>().Where(sp => sp.ProductId == shoppingproduct.ProductId && sp.ShoppingListId == shoppingproduct.ShoppingListId); if (result.Count() == 0) { return("OK"); } else { return("This Product already exist in this Shopping List"); } }
public void TestProduct7() { var products = new Produt { prouctItems = new List <ProdutItems>() { new ProdutItems() } }; int budget = 1; Assert.AreEqual(0, ShoppingProduct.GetMaxValue(budget, products)); }
/// <summary> /// /// </summary> /// <param name="shoppingProductModel"></param> /// <returns></returns> public ShoppingProduct CreateShoppingProduct(ShoppingProductModel shoppingProductModel) { var newShoppingProduct = new ShoppingProduct { Name = shoppingProductModel.name, Price = shoppingProductModel.pricePerUnit, Product = _productRepository.GetById(shoppingProductModel.productId), Quantity = shoppingProductModel.quantity }; _shoppingProductRepository.Add(newShoppingProduct); _context.SaveChanges(); return(newShoppingProduct); }
public void TestProduct12() { var products = new Produt { prouctItems = new List <ProdutItems>() { new ProdutItems() { productId = 1, productName = "P1", productCost = 0, productValue = 110 } } }; int budget = 1; Assert.AreEqual(0, ShoppingProduct.GetMaxValue(budget, products)); }
public static ShoppingProductModel Create(ShoppingProduct product) { if (product == null) { return(null); } var productModel = new ShoppingProductModel { id = product.Id, name = product.Name, pricePerUnit = product.Price, productId = product.Product == null ? 0 : product.Product.Id, quantity = product.Quantity }; return(productModel); }
public List <ShoppingProduct> ConvertShoppingProductJsonListToShoppingProductList(List <ShoppingProductJson> shoppingProductJsonList, int shoppingCartId) { var shoppingProductList = new List <ShoppingProduct>(); foreach (var shoppingProductJson in shoppingProductJsonList) { var shoppingProduct = new ShoppingProduct() { Id = shoppingProductJson.id, Name = shoppingProductJson.name, ProductId = shoppingProductJson.productId, PricePerUnit = shoppingProductJson.pricePerUnit, ShoppingCartId = shoppingCartId }; shoppingProductList.Add(shoppingProduct); } return(shoppingProductList); }
public async Task <ShoppingProduct> GetTotalShoppingProduct(Guid productId) { var movementsProduct = _unitOfWork.MovementRepository .Queryable() .Where(f => f.ProductId.Equals(productId) && !f.Type) .ToList(); if (movementsProduct.Count > 0) { var product = await _unitOfWork.ProductRepository.GetByIdAsync(productId); var shoppingProduct = new ShoppingProduct { Id = productId, Name = product.Name, Stock = product.Stock, ShoppingQuantity = movementsProduct.Sum(x => x.Quantity), TotalPriceShopping = movementsProduct.Sum(x => x.Quantity * x.Price) }; return(shoppingProduct); } _logger.LogInformation("The product is out of stock and purchases"); throw new BusinessException("The product is out of stock and purchases"); }
/// <summary> /// Remove a record for the ShoppingProduct entity /// </summary> /// <param name="shoppingproductToDelete">An instance of ShoppingProduct object</param> public void deleteShoppingProduct(ShoppingProduct shoppingproductToDelete) { _repo.Delete <ShoppingProduct>(shoppingproductToDelete); }
/// <summary> /// Modify a record for the ShoppingProduct entity /// </summary> /// <param name="shoppingproductToUpdate">An instance of ShoppingProduct object</param> public void updateShoppingProduct(ShoppingProduct shoppingproductToUpdate) { _repo.Update <ShoppingProduct>(shoppingproductToUpdate); }
/// <summary> /// Insert a new record in the data repository for the ShoppingProduct entity /// </summary> /// <param name="shoppingproductToCreate">An instance of a new ShoppingProduct object</param> public void createShoppingProduct(ShoppingProduct shoppingproductToCreate) { _repo.Add(shoppingproductToCreate); }
public ShoppingItem(ShoppingProduct p, int quantity) { this.Product = p; this.Quantity = quantity; this.SubTotal = p.ProductPrice * quantity; }