public IActionResult Calculate( [FromBody] TrolleyForCalculateDto dto) { var getTotal = productsService.GetTotal(dto); return(Ok(getTotal)); }
public double GetTotal(TrolleyForCalculateDto dto) { var productPrices = dto.Products.ToDictionary(x => x.Name, x => x.Price); var shoppingCart = dto.Quantities.ToDictionary(x => x.Name, x => x.Quantity); var total = GetBasePrice(productPrices, shoppingCart); foreach (var special in GetValidSpecials(dto.Specials, shoppingCart)) { total = Math.Min(total, GetSpecialPrice(special, productPrices, shoppingCart)); } return(total); }