/* This function should compute the best product to be chosen */ /* It should take into consideration to buy the lowest quantity necessary for the lowest price */ public async Task <Product> GetCheapest(string name, double quantity, string unitOfMeasurement) { Product cheapestProduct = null; if (await Exists(name)) { double valueCoefficient = 0; IEnumerable <Product> products = await GetByName(name); foreach (var product in products) { IEnumerable <ProductStore> productStores = await _productStoresRepository.GetByProduct(product.Id); double tempCoefficient; /* Get the cheapest version of the same exact product from all stores */ tempCoefficient = product.Quantity / productStores.Min(r => r.Price); /* Compute its value */ if (tempCoefficient > valueCoefficient) { valueCoefficient = tempCoefficient; cheapestProduct = product; } } } return(cheapestProduct); }
public async Task <IActionResult> ProductPrices(Guid id) { return(Ok(await _productStoresRepository.GetByProduct(id))); }