Ejemplo n.º 1
0
        public static void ResetPasswordMessage(ProductionUnitOwner currentProductionUnitOwner, string to, string callbackUrl)
        {
            var client = new SendGridClient(MailSendGridAPIKey);
            var from   = new EmailAddress("*****@*****.**", "Myfood Hub Bot");

            MailTemplateObject obj = new MailTemplateObject();
            var currentTemplate    = string.Empty;

            var pioneerName = string.Format("{0} #{1}", currentProductionUnitOwner.pioneerCitizenName, currentProductionUnitOwner.pioneerCitizenNumber);

            obj.firstName     = currentProductionUnitOwner.pioneerCitizenName;
            obj.pioneerNumber = currentProductionUnitOwner.pioneerCitizenNumber.ToString();
            obj.callbackurl   = callbackUrl;

            List <EmailAddress> tos = new List <EmailAddress>
            {
                new EmailAddress(currentProductionUnitOwner.contactMail, pioneerName)
            };

            if (currentProductionUnitOwner != null && currentProductionUnitOwner.language != null)
            {
                switch (currentProductionUnitOwner.language.description)
                {
                case "fr":
                    currentTemplate = TemplatePasswordRecoveryFR;
                    break;

                case "en":
                    currentTemplate = TemplatePasswordRecoveryEN;
                    break;

                case "de":
                    currentTemplate = TemplatePasswordRecoveryDE;
                    break;

                default:
                    currentTemplate = TemplatePasswordRecoveryEN;
                    break;
                }
            }
            else
            {
                currentTemplate = TemplatePasswordRecoveryEN;
            }

            var msg = MailHelper.CreateSingleTemplateEmailToMultipleRecipients(from, tos, currentTemplate, obj);
            //msg.AddCc("*****@*****.**");
            var response = client.SendEmailAsync(msg);
        }
Ejemplo n.º 2
0
        public static void PioneerUnitOfflineMessage(ProductionUnit currentProductionUnit)
        {
            var dbLog = new ApplicationDbContext();

            try
            {
                var client = new SendGridClient(MailSendGridAPIKey);
                var from   = new EmailAddress("*****@*****.**", "Myfood Hub Bot");

                MailTemplateObject obj = new MailTemplateObject();
                var currentTemplate    = string.Empty;

                if (currentProductionUnit.owner == null || currentProductionUnit.owner.contactMail == null || currentProductionUnit.owner.contactMail == string.Empty)
                {
                    dbLog.Logs.Add(Log.CreateLog(String.Format("Error with Mail Notification - Mail is missing for {0}", currentProductionUnit.info), Log.LogType.Information));
                    dbLog.SaveChanges();

                    return;
                }

                var pioneerName = string.Format("{0} #{1}", currentProductionUnit.owner.pioneerCitizenName, currentProductionUnit.owner.pioneerCitizenNumber);

                obj.firstName     = currentProductionUnit.owner.pioneerCitizenName;
                obj.pioneerNumber = currentProductionUnit.owner.pioneerCitizenNumber.ToString();
                obj.info          = currentProductionUnit.info;

                if (currentProductionUnit.productionUnitType.name.ToString().Contains("Family"))
                {
                    obj.isFamily = true;
                }
                else if (currentProductionUnit.productionUnitType.name.ToString().Contains("City"))
                {
                    obj.isFamily = false;
                }
                else
                {
                    obj.isFamily = true;
                }

                List <EmailAddress> tos = new List <EmailAddress>
                {
                    new EmailAddress(currentProductionUnit.owner.contactMail, pioneerName)
                };

                var subject     = string.Empty;
                var htmlContent = string.Empty;

                if (currentProductionUnit.owner != null && currentProductionUnit.owner.language != null)
                {
                    switch (currentProductionUnit.owner.language.description)
                    {
                    case "fr":
                        currentTemplate = TemplateGreehouseOfflineFR;
                        break;

                    case "en":
                        currentTemplate = TemplateGreehouseOfflineEN;
                        break;

                    case "de":
                        currentTemplate = TemplateGreehouseOfflineDE;
                        break;

                    default:
                        currentTemplate = TemplateGreehouseOfflineEN;
                        break;
                    }
                }
                else
                {
                    currentTemplate = TemplateGreehouseOfflineEN;
                }

                var msg = MailHelper.CreateSingleTemplateEmailToMultipleRecipients(from, tos, currentTemplate, obj);
                //msg.AddCc("*****@*****.**");
                var response = client.SendEmailAsync(msg);
            }
            catch (Exception ex)
            {
                dbLog.Logs.Add(Log.CreateErrorLog(String.Format("Error with Mail Notification"), ex));
                dbLog.SaveChanges();
            }
        }
Ejemplo n.º 3
0
        public static void PioneerUnitWeeklyMessage(ProductionUnit currentProductionUnit, List <RecommandationTemplaceObject> reco)
        {
            var db    = new ApplicationDbContext();
            var dbLog = new ApplicationDbContext();

            var infoEventType = db.EventTypes.Where(p => p.Id == 8).FirstOrDefault();

            try
            {
                var client = new SendGridClient(MailSendGridAPIKey);
                var from   = new EmailAddress("*****@*****.**", "Myfood Hub Bot");

                MailTemplateObject obj = new MailTemplateObject();
                var currentTemplate    = string.Empty;

                if (currentProductionUnit.owner == null || currentProductionUnit.owner.contactMail == null || currentProductionUnit.owner.contactMail == string.Empty)
                {
                    dbLog.Logs.Add(Log.CreateLog(String.Format("Error with Mail Notification - Mail is missing for {0}", currentProductionUnit.info), Log.LogType.Information));
                    dbLog.SaveChanges();

                    return;
                }

                var pioneerName = string.Format("{0} #{1}", currentProductionUnit.owner.pioneerCitizenName, currentProductionUnit.owner.pioneerCitizenNumber);

                obj.firstName     = currentProductionUnit.owner.pioneerCitizenName;
                obj.pioneerNumber = currentProductionUnit.owner.pioneerCitizenNumber.ToString();
                obj.info          = currentProductionUnit.info;

                if (currentProductionUnit.productionUnitType.name.ToString().Contains("Family"))
                {
                    obj.isFamily = true;
                }
                else
                {
                    obj.isFamily = false;
                }

                obj.recommandations = reco.OrderBy(r => r.order).ToList();

                if (obj.recommandations.Count > 0)
                {
                    obj.hasRecommandation = true;
                }
                else
                {
                    obj.hasRecommandation = false;

                    //var content = String.Format("",null);

                    //db.Events.Add(new Event() { date = DateTime.Now, description = content, isOpen = false, productionUnit = currentProductionUnit, eventType = infoEventType, createdBy = "MyFood Bot" });
                    //db.SaveChanges();
                }


                List <EmailAddress> tos = new List <EmailAddress>
                {
                    new EmailAddress(currentProductionUnit.owner.contactMail, pioneerName)
                };

                var subject     = string.Empty;
                var htmlContent = string.Empty;

                if (currentProductionUnit.owner != null && currentProductionUnit.owner.language != null)
                {
                    switch (currentProductionUnit.owner.language.description)
                    {
                    case "fr":
                        currentTemplate = TemplateWeeklyMessageFR;
                        break;

                    case "en":
                        currentTemplate = TemplateWeeklyMessageEN;
                        break;

                    case "de":
                        currentTemplate = TemplateWeeklyMessageDE;
                        break;

                    default:
                        currentTemplate = TemplateWeeklyMessageEN;
                        break;
                    }
                }
                else
                {
                    currentTemplate = TemplateGreehouseOfflineEN;
                }

                var msg = MailHelper.CreateSingleTemplateEmailToMultipleRecipients(from, tos, currentTemplate, obj);
                //msg.AddCc("*****@*****.**");
                var response = client.SendEmailAsync(msg);
            }
            catch (Exception ex)
            {
                dbLog.Logs.Add(Log.CreateErrorLog(String.Format("Error with Mail Notification"), ex));
                dbLog.SaveChanges();
            }
        }