public async Task <IActionResult> GetQuote([FromBody] QuoteRequest request) { var validationResults = await _wholesalerValidation.ValidateQuoteRequest(request); if (validationResults.Any(validationResult => validationResult != ValidationResult.Success)) { return(new BadRequestObjectResult(validationResults.Where(result => result != null).Select(result => result?.ErrorMessage))); } var quote = await _wholesalerService.GenerateQuote(request); return(new OkObjectResult(quote)); }
public async Task <Quote> GenerateQuote(QuoteRequest request) { await _wholesalerValidation.ValidateQuoteRequest(request); var wholesalerStock = await _wholesalerDataAccess.GetWholesalerStock(request.WholesalerId); var quote = new Quote { WholesalerId = request.WholesalerId, QuotedItems = GetQuotedItems(request, wholesalerStock.ToModels()), }; quote.RawPrice = quote.QuotedItems.Sum(item => item.UnitPrice * item.Quantity); quote.Discount = GetDiscount(quote.RawPrice, quote.QuotedItems.Sum(item => item.Quantity)); quote.Price = quote.RawPrice - quote.Discount; return(quote); }