public async static Task <string> SendEmailAlert(List <LastContactedDTO> companies)
        {
            var emailConfig = ConfigDictionary.EmailConfig();

            string alertCompanies = string.Empty;

            foreach (LastContactedDTO company in companies)
            {
                alertCompanies += $"<li><b>{ company.CompanyName }</b>: last contacted over <span style='color:red;font-weight:bold;'>{ Math.Floor(company.DaysSinceLastContact) }</span> days ago</li>";
            }

            string messageBody = "<html><body>" +
                                 $"<span style='display:inline-block;'><img src='https://cdn.shopify.com/s/files/applications/75204543d0fec5bbf9e7f1db609e8804_512x512.png?1594118407' style='width:50%;'/><h2>Client Communication Alert</h2></span>" +
                                 $"<p>It has been over 7 days since the following clients were last contacted:</p><br/>" +
                                 $"<ul>{ alertCompanies }</ul>" +
                                 "</body></html>";

            try
            {
                await EmailAlert.SendEmailAlert(new EmailAddress(emailConfig["LastContactedRecipientAddress"]),
                                                $"Client Communication Alert.",
                                                messageBody);

                return("Email sent!");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());

                return("Email failed to send.");
            }
        }
Exemple #2
0
        public async static Task <string> SendEmailAlert(DailyImpressionsDTO dailyImpressionsSummary)
        {
            Dictionary <string, string> emailConfig = ConfigDictionary.EmailConfig();

            string companies = string.Empty;

            foreach (CompanyDailyImpressionsSummary company in dailyImpressionsSummary.DailyImpressionsSummary)
            {
                string failingCampaigns = string.Empty;

                foreach (CampaignDailyImpressionsSummary campaign in company.Campaigns)
                {
                    failingCampaigns += $"<li>{ campaign.Name }: <span style='color:red;font-weight:bold;'>{ campaign.Impressions }</span> impressions</li>";
                }

                companies += $"<li><b>{ company.Name }</b>: <ul>{ failingCampaigns }</ul></li>";
            }

            string messageBody = "<html><body>" +
                                 $"<span style='display:inline-block;'><img src='https://cdn.shopify.com/s/files/applications/75204543d0fec5bbf9e7f1db609e8804_512x512.png?1594118407' style='width:50%;'/><h2>Google Ads Campaign Alert</h2></span>" +
                                 $"<p>The following campaigns achieved fewer than 100 impressions yesterday:</p><br/>" +
                                 $"<ul>{ companies }</ul>" +
                                 "</body></html>";

            try
            {
                await EmailAlert.SendEmailAlert(new EmailAddress(emailConfig["GoogleAdsRecipientAddress"]),
                                                $"Google Ads Campaign Alert",
                                                messageBody);

                return("Email sent!");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());

                return("Email failed to send.");
            }
        }
Exemple #3
0
        public async Task <dynamic> Get()
        {
            if (CheckClientSecret())
            {
                Entities db = new Entities();

                Dictionary <string, string> emailConfig = ConfigDictionary.EmailConfig();

                var storesRequiringUpdate = new List <StoreCustomData>();

                foreach (StoreCustomData store in db.StoreCustomDatas)
                {
                    DateTime lastUpdate = db.SalesTargetHistories
                                          .Where(x => x.StoreID == store.StoreID)
                                          .OrderByDescending(x => x.DateUpdated)
                                          .FirstOrDefault()
                                          .DateUpdated;

                    if ((DateTime.Now - lastUpdate).TotalDays > 30)
                    {
                        storesRequiringUpdate.Add(store);
                    }
                }

                if (storesRequiringUpdate.Any())
                {
                    string storeNames = string.Empty;

                    foreach (StoreCustomData store in storesRequiringUpdate)
                    {
                        storeNames += $"<li><b>{ store.StoreName }</b> - Current Sales Target: £{ store.SalesTarget }</li>";
                    }

                    string messageBody = "<html><body>" +
                                         $"<span style='display:inline-block;'><img src='https://cdn.shopify.com/s/files/applications/75204543d0fec5bbf9e7f1db609e8804_512x512.png?1594118407' style='width:50%;'/><h2>Sales Target Update Alert</h2></span>" +
                                         $"<p>It has been more than 30 days since Sales Targets were updated for the following stores:</p><br/>" +
                                         $"<ul>{ storeNames }</ul>" +
                                         "</body></html>";

                    try
                    {
                        await EmailAlert.SendEmailAlert(new EmailAddress(emailConfig["SalesTargetRecipientAddress"]), "Sales Target Update Alert", messageBody);

                        return("Email sent!");
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.ToString());

                        return("Email failed to send.");
                    }
                }
                else
                {
                    return("No updates required.");
                }
            }
            else
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden));
            }
        }