public async Task <RegisteredQuote> Handle(NewQuoteRequest request, CancellationToken cancellationToken)
        {
            var quote = request.ToDTOWithDetails();

            this._dbContext.Quotes.Add(quote);
            await this._dbContext.SaveChangesAsync();

            return(await this._dbContext.Quotes.Select(x => new RegisteredQuote
            {
                Id = x.Id,
                ClientName = $"{x.Client.Names} {x.Client.LastNames}",
                Date = x.Date,
                Description = x.Description,
                Total = x.Total
            }).FirstOrDefaultAsync(x => x.Id.Equals(quote.Id)));
        }
Exemplo n.º 2
0
 public static Quote ToDTOWithDetails(this NewQuoteRequest entity)
 {
     return(new Quote
     {
         ClientId = entity.ClientId,
         Description = entity.Description,
         Total = entity.Details.Select(x => x.FinalPrice * x.Quantity).Sum(),
         Details = entity.Details.Select(x => new QuoteDetail
         {
             Cost = x.Cost,
             ProductId = x.ProductId,
             Quantity = x.Quantity,
             FinalPrice = x.FinalPrice,
             SubTotal = x.FinalPrice * x.Quantity
         }).ToHashSet()
     });
 }
 public async Task <RegisteredQuote> RegisterNewQuote([FromBody] NewQuoteRequest request)
 {
     return(await _mediator.Send(request));
 }