public async Task <Response <SaleApiModel> > Handle(CreateSaleCommand request, CancellationToken cancellationToken) { try { var include = new Expression <Func <Sale, object> >[] { x => x.ItemsSold }; await _repo.CreateSale(request, cancellationToken).ConfigureAwait(false); await _repo.SaveAsync(cancellationToken).ConfigureAwait(false); var thisSale = await _repo.GetOneBy(cancellationToken, include, s => s.SaleDate.Equals(request.SaleDate), s => s.GrandTotal.Equals(request.GrandTotal), s => s.SubTotal.Equals(request.SubTotal)).ConfigureAwait(false); var sale = _mapper.Map <SaleApiModel>(thisSale); var result = new Response <SaleApiModel>(sale, ResponseStatus.Success); var createSaleEvent = new SaleCreatedEvent(sale); await _mediator.Publish(createSaleEvent, cancellationToken); return(result); } catch (Exception e) { return(new Response <SaleApiModel>(new SaleApiModel(), ResponseStatus.Failure, new { e.Message, Time = DateTimeOffset.Now })); } }