Ejemplo n.º 1
0
        private async Task HandleAsync(DayHasPassed dhp)
        {
            var jobs = await _repo.GetMaintenanceJobsToBeInvoicedAsync();

            foreach (var jobsPerCustomer in jobs.GroupBy(job => job.CustomerId))
            {
                DateTime invoiceDate = DateTime.Now;
                string   customerId  = jobsPerCustomer.Key;
                Customer customer    = await _repo.GetCustomerAsync(customerId);

                Invoice invoice = new Invoice
                {
                    InvoiceId   = $"{invoiceDate.ToString("yyyyMMddhhmmss")}-{customerId.Substring(0, 4)}",
                    InvoiceDate = invoiceDate.Date,
                    CustomerId  = customer.CustomerId,
                    JobIds      = string.Join('|', jobsPerCustomer.Select(j => j.JobId))
                };

                StringBuilder specification = new StringBuilder();
                decimal       totalAmount   = 0;
                foreach (var job in jobsPerCustomer)
                {
                    TimeSpan duration = job.EndTime.Value.Subtract(job.StartTime.Value);
                    decimal  amount   = Math.Round((decimal)duration.TotalHours * HOURLY_RATE, 2);
                    totalAmount += amount;
                    specification.AppendLine($"{job.EndTime.Value.ToString("dd-MM-yyyy")} : {job.Description} on vehicle with license {job.LicenseNumber} - Duration: {duration.TotalHours} hour - Amount: € {amount}");
                }
                invoice.Specification = specification.ToString();
                invoice.Amount        = totalAmount;

                await SendInvoice(customer, invoice);

                await _repo.RegisterInvoiceAsync(invoice);
            }
        }
Ejemplo n.º 2
0
        private async Task HandleAsync(DayHasPassed dhp)
        {
            DateTime today = DateTime.Now;

            IEnumerable <MaintenanceJob> jobsToNotify = await _repo.GetMaintenanceJobsForTodayAsync(today);

            foreach (var jobsPerCustomer in jobsToNotify.GroupBy(job => job.CustomerId))
            {
                // build notification body
                string   customerId = jobsPerCustomer.Key;
                Customer customer   = await _repo.GetCustomerAsync(customerId);

                StringBuilder body = new StringBuilder();
                body.AppendLine($"Dear {customer.Name},\n");
                body.AppendLine($"We would like to remind you that you have an appointment with us for maintenance on your vehicle(s):\n");
                foreach (MaintenanceJob job in jobsPerCustomer)
                {
                    body.AppendLine($"- {job.StartTime.ToString("dd-MM-yyyy")} at {job.StartTime.ToString("HH:mm")} : " +
                                    $"{job.Description} on vehicle with license-number {job.LicenseNumber}");
                }

                body.AppendLine($"\nPlease make sure you're present at least 10 minutes before the (first) job is planned.");
                body.AppendLine($"Once arrived, you can notify your arrival at our front-desk.\n");
                body.AppendLine($"Greetings,\n");
                body.AppendLine($"The PitStop crew");

                // send notification
                await _emailNotifier.SendEmailAsync(
                    customer.EmailAddress, "*****@*****.**", "Vehicle maintenance reminder", body.ToString());

                // remove jobs for which a notification was sent
                await _repo.RemoveMaintenanceJobsAsync(jobsPerCustomer.Select(job => job.JobId));
            }
        }
Ejemplo n.º 3
0
        private async Task HandleAsync(DayHasPassed dhp)
        {
            DateTime today = DateTime.Now;
            // Log.Information("DayHasPassed Event");
            IEnumerable <Order> ordersToNotify = await _repo.GetOrdersForTodayAsync(today);

            foreach (var ordersPerCustomer in ordersToNotify.GroupBy(order => order.CustomerId))
            {
                // build notification body
                string   customerId = ordersPerCustomer.Key;
                Customer customer   = await _repo.GetCustomerAsync(customerId);

                StringBuilder body = new StringBuilder();
                body.AppendLine($"Dear {customer.Name},\n");
                body.AppendLine($"The following order needs to be paid:\n");
                foreach (Order order in ordersPerCustomer)
                {
                    body.AppendLine($"- {order.OrderDate.ToString("dd-MM-yyyy")} : " +
                                    $"Order needs to be paid with order number {order.OrderId}");
                }

                body.AppendLine($"\nPlease pay your order in 4 days.\n");
                body.AppendLine($"Greetings,\n");
                body.AppendLine($"The Ball crew");

                Log.Information("Sent notification to: {CustomerName}", customer.Name);

                // send notification
                await _emailNotifier.SendEmailAsync(
                    customer.EmailAddress, "*****@*****.**", "Order needs to be paid", body.ToString());
            }
        }
Ejemplo n.º 4
0
 private async void Worker()
 {
     while (true)
     {
         if (DateTime.Now.Subtract(_lastCheck).Days > 0)
         {
             Log.Information($"Day has passed!");
             _lastCheck = DateTime.Now;
             DateTime     passedDay = _lastCheck.AddDays(-1);
             DayHasPassed e         = new DayHasPassed(Guid.NewGuid());
             await _messagePublisher.PublishMessageAsync(e.MessageType, e, "");
         }
         Thread.Sleep(10000);
     }
 }