public async Task <InvoiceDto> GenerateInvoiceAsync(GenerateInvoiceDto generateInvoiceDto) { Order order = await _orderRepository.GetOrderByIdAsync(generateInvoiceDto.OrderId); if (order == null) { throw new Exception("Order does not exist."); } Invoice invoice = new Invoice { Date = DateTime.Now, CompanyName = "Software Architectures Restaurant Kft.", StreetAddress = "Kossuth Lajos út 40.", CityCountryZIP = "1234 Budapest, Magyarország", Phone = "+36-90-123-4567", BillToName = generateInvoiceDto.BillToName, BillToStreetAddress = generateInvoiceDto.BillToStreetAddress, BillToCityCountryZIP = $"{generateInvoiceDto.BillToZIP} {generateInvoiceDto.BillToCity}, {generateInvoiceDto.BillToCountry}", BillToPhone = generateInvoiceDto.BillToPhone, Discount = generateInvoiceDto.Discount, InvoiceItems = order.OrderItems.Select(x => new InvoiceItem { Description = x.MenuItem.Name, Quantity = x.NumberOfItems, VAT = 27, UnitPrice = x.MenuItem.Price }).ToList() }; Invoice created = await _repository.GenerateInvoiceAsync(invoice); return(new InvoiceDto(created)); }
public async Task <ActionResult <InvoiceDto> > GenerateInvoice(GenerateInvoiceDto generateInvoiceDto) { if (generateInvoiceDto == null) { return(BadRequest("Invoice data must be set!")); } try { return(Ok(await _service.GenerateInvoiceAsync(generateInvoiceDto))); } catch (Exception e) { return(Conflict(e.Message)); } }