public async Task <InvoiceResponseModel> Create(InvoiceRequestModel invoiceRequest) { var invoice = InvoiceMap.InvoiceRequestToInvoice(invoiceRequest); if (!invoice.IsValid()) { AddErrors(invoice.GetErrors()); } HandlerErrors(); var company = await _companyRepository.GetById(invoice.CompanyId); if (company == null) { AddError("Company not found"); } HandlerErrors(); await _invoiceRepository.Create(invoice); company.CalculateReliability(); await _invoiceRepository.Save(); return(InvoiceMap.InvoiceToInvoiceResponse(invoice)); }
public async Task <List <InvoiceResponseModel> > GetCompanyInvoices(int companyId) { if (companyId <= 0) { AddError("The company id is Invalid"); } var invoices = await _invoiceRepository.GetCompanyInvoices(companyId); return(invoices.Select(x => InvoiceMap.InvoiceToInvoiceResponse(x)).ToList()); }
public async Task ShouldGetInvoiceById() { var Invoice = new Invoice(1); var expectedInvoice = InvoiceMap.InvoiceToInvoiceResponse(Invoice); _invoiceRepository.GetById(1).Returns(Invoice); var response = await _invoiceService.GetById(1); response.Should().BeEquivalentTo(expectedInvoice); }
public async Task <InvoiceResponseModel> GetById(int id) { if (id <= 0) { AddError("Id invalid"); } HandlerErrors(); var invoice = await _invoiceRepository.GetById(id); if (invoice == null) { AddError("Invoice not found"); } HandlerErrors(); return(InvoiceMap.InvoiceToInvoiceResponse(invoice)); }
public async Task GetCompanyInvoices() { var InvoicesOfCompanyModels = new List <InvoiceResponseModel>(); var InvoicesOfCompany = new List <Invoice>(); var InvoiceOfCompany1 = new Invoice(1); var InvoiceResponseOfCompany1 = InvoiceMap.InvoiceToInvoiceResponse(InvoiceOfCompany1); for (int i = 0; i < 5; i++) { InvoicesOfCompanyModels.Add(InvoiceResponseOfCompany1); InvoicesOfCompany.Add(InvoiceOfCompany1); } _invoiceRepository.GetCompanyInvoices(1).Returns(InvoicesOfCompany); var response = await _invoiceService.GetCompanyInvoices(1); response.Should().BeEquivalentTo(InvoicesOfCompanyModels); }