public IList <Invoice> Handle(GetInvoices message) { const string queryTemplate = @" SELECT i.*, u.*, c.* FROM Accounting.Invoice i JOIN Users.[User] u ON i.CreatedById = u.Id JOIN Companies.Company c ON i.CompanyId = c.Id WHERE (@IsCompanyIdDefault = 1 AND @InvoiceNumber IS NULL) OR ((@IsCompanyIdDefault = 0 AND i.CompanyID = @CompanyID) {CompOper} (@InvoiceNumber IS NOT NULL AND i.InvoiceNumber = @InvoiceNumber))"; var query = queryTemplate.Replace("{CompOper}", message.SearchOption.ToSqlOperator()); Func <Invoice, User, Company, Invoice> mapper = (invoice, user, company) => { invoice.CreatedBy = user; invoice.Company = company; return(invoice); }; return(_UnitOfWork.Query(query, mapper, new { IsCompanyIdDefault = message.CompanyId == default(Guid) ? 1 : 0, message.CompanyId, message.InvoiceNumber }).ToList()); }
public async Task <ActionResult <Invoice[]> > Get(string customer = null, int skip = 0, int take = 10) { try { var request = new GetInvoices { Customer = customer, Skip = skip, Take = take }; var invoices = await _useCases.Invoke <Invoice[]>(request); return(Ok(invoices)); } catch (Exception ex) { _logger.LogError(ex, "Error getting invoices"); while (ex.InnerException != null) { ex = ex.InnerException; } return(StatusCode(500, new { message = ex.Message, details = ex.StackTrace })); } }
public async Task <Invoice[]> Invoke(GetInvoices request) { return(await _repository.GetInvoices(request.Customer, request.Skip, request.Take)); }