public static Invoice Generate(GenerateInvoiceRequest request, IEmailer emailer) { var invoice = new Invoice(); var now = DateTime.Now; invoice.Id = Guid.NewGuid(); invoice.CreatedBy = request.GeneratedBy; invoice.CreatedOn = now; invoice.InvoiceNumber = request.InvoiceNumber; invoice.Customer = request.Customer; invoice.PeriodFrom = request.PeriodFrom.Value; invoice.PeriodTo = request.PeriodTo.Value; invoice.InvoiceDate = now; var relevantBookings = request .Customer .Bookings .Where(booking => booking.EndDate >= request.PeriodFrom && booking.EndDate <= request.PeriodTo) .ToList(); invoice.Total = relevantBookings.Sum(booking => booking.Total); invoice.SendEmail(emailer); return(invoice); }
public async Task <IActionResult> GenerateInvoice( [FromBody] GenerateInvoiceRequest request) { var invoice = await _useCase.Execute(request); return(Ok(invoice)); }
public GenerateInvoiceRequest Map(GenerateViewModel viewModel) { var request = new GenerateInvoiceRequest(); request.PeriodFrom = viewModel.PeriodFrom; request.PeriodTo = viewModel.PeriodTo; request.Customer = _customerRepository.GetById(viewModel.CustomerId.Value); var username = _userProvider.GetUsername(); request.GeneratedBy = _userRepository.GetByUsername(username); return(request); }
public async Task <Invoice> GenerateInvoice(List <EquipmentItem> equipment) { var requestAddress = new Uri($"rabbitmq://{_options.Host}/{_options.InvoiceQueue}"); var request = new GenerateInvoiceRequest { RentedEquipment = equipment }; _logger.LogInformation($"Sending InvoiceRequest for {JsonConvert.SerializeObject(request)} to {requestAddress}"); var client = _bus.CreateRequestClient <GenerateInvoiceRequest>(requestAddress); return((await client.GetResponse <GenerateInvoiceResponse>(request)).Message.Invoice); }
public static ValidationMessageCollection ValidateGenerate(GenerateInvoiceRequest request) { var validationMessages = new ValidationMessageCollection(); return(validationMessages); }
public void EmailIsGenerated() { var emailer = new Mock <IEmailer>(); string to = null; string from = null; string subject = null; string body = null; emailer .Setup(x => x.Send(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Callback(delegate(string delegateTo, string delegateFrom, string delegateSubject, string delegateBody) { to = delegateTo; from = delegateFrom; subject = delegateSubject; body = delegateBody; }); var request = new GenerateInvoiceRequest(); request.InvoiceNumber = "ABC123"; request.PeriodFrom = new DateTime(2010, 10, 1); request.PeriodTo = new DateTime(2010, 10, 10); request.Customer = new Customer() { Id = Guid.NewGuid(), GivenName = "Tom", Bookings = new List <Booking>() { new Booking() { EndDate = new DateTime(2010, 10, 2), Total = 200m }, new Booking() { EndDate = new DateTime(2010, 10, 9), Total = 150m } }, User = new User() { Id = Guid.NewGuid(), Username = "******" } }; var invoice = Invoice.Generate(request, emailer.Object); Assert.AreEqual("*****@*****.**", to); Assert.AreEqual("*****@*****.**", from); Assert.AreEqual("Invoice for period 1 Oct 2010 to 10 Oct 2010", subject); var expectedBody = new StringBuilder(); expectedBody.AppendLine("Dear Tom,"); expectedBody.AppendLine(); expectedBody.AppendLine("Please pay the outstanding amount of £350.00"); expectedBody.AppendLine(); expectedBody.AppendLine("Regards,"); expectedBody.AppendLine("The Campervibe Team"); Assert.AreEqual(expectedBody.ToString(), body); }