Exemple #1
0
        public async Task SendSalesReportEmailAsync(DateTime date)
        {
            var orders = orderService.Get(date.AddDays(-7), date);

            if (!orders.Any())
            {
                return;
            }

            salesReportBuilder.Add(orders);
            salesReportBuilder.Add("Raport sprzedaży");

            SalesReport report = salesReportBuilder.Build();

            var recipients = userService.GetBosses();

            var sender = userService.GetBot();

            foreach (var recipient in recipients)
            {
                if (recipient.Email == null)
                {
                    continue;
                }

                var message = MailHelper.CreateSingleEmail(
                    new EmailAddress(sender.Email, $"{sender.FirstName} {sender.LastName}"),
                    new EmailAddress(recipient.Email, $"{recipient.FirstName} {recipient.LastName}"),
                    "Raport sprzedaży",
                    report.ToString(),
                    report.ToHtml());


                logger.Info($"Wysyłanie raportu do {recipient.FirstName} {recipient.LastName} <{recipient.Email}>...");

                var response = await client.SendEmailAsync(message);

                if (response.StatusCode == System.Net.HttpStatusCode.Accepted)
                {
                    ReportSent?.Invoke(this, new ReportSentEventArgs(DateTime.Now));

                    logger.Info($"Raport został wysłany.");
                }
                else
                {
                    logger.Error($"Błąd podczas wysyłania raportu.");

                    throw new ApplicationException("Błąd podczas wysyłania raportu.");
                }
            }
        }
Exemple #2
0
        public async Task SendSalesReportEmailAsync(DateTime date)
        {
            var criteria = new OrderSearchCriteria(date.AddDays(-7), date);

            var orders = orderService.Get(criteria);

            if (!orders.Any())
            {
                return;
            }

            salesReportBuilder.Add(orders);

            SalesReport report = salesReportBuilder.Create();

            IEnumerable <User> recipients = userService.GetBossesRecipients();

            var sender = userService.GetBot();

            foreach (var recipient in recipients)
            {
                await client.SendAsync(sender, recipient, report);
            }
        }