public async Task <Quote> GenerateQuote(QuoteRequest request)
        {
            var wholesalerStock = await _wholesalerQuery.GetWholesalerStock(request.WholesalerId);

            var quote = new Quote
            {
                WholesalerId = request.WholesalerId,
                QuotedItems  = GetQuotedItems(request, wholesalerStock),
            };

            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);
        }
Exemple #2
0
        private async Task <ValidationResult> ValidateWholesalerStock(QuoteRequest request)
        {
            var wholesalerStock = await _wholesalerQuery.GetWholesalerStock(request.WholesalerId);

            foreach (var requestItem in request.RequestItems)
            {
                var requestedItemInStock = wholesalerStock.FirstOrDefault(stockItem => stockItem.ItemId.Equals(requestItem.ItemId));

                if (requestedItemInStock is null)
                {
                    return(new ValidationResult("Requested Item is not sold by this wholesaler"));
                }
                if (requestedItemInStock.Quantity < requestItem.Quantity)
                {
                    return(new ValidationResult($"Requested quantity for item {requestItem.ItemId} is not available at this wholesaler"));
                }
            }

            return(ValidationResult.Success);
        }