Ejemplo n.º 1
0
        public async Task<ActionResult> Missing()
        {
            try
            {
                //Permite somente que a os e-mails sejam enviados a partir da conta da empresa ThisIsOnTop.com
                if (oUserProfile.oAccount.id == 1 && oUserProfile.oAccount.IsCompanyAccount)
                {
                    int counter = 0;
                    //var rs = base.oCore.businessControllers.bcAccount.MissingUsers(DateTime.Now, 30, 0, int.MaxValue);
                    var rs = oCore.iRepositories.IAccountRepository.Select(AccountRecordStatus.Ative);

                    foreach (var account in rs.Where(model => model.creationCountry != null && model.creationCountry == 2).ToList())
                    {
                        try
                        {
                            //Verifica se o usuário está há 30 dias sem entrar no sistema
                            if (account.lastLogon == null || (DateTime.Now - (DateTime)account.lastLogon).Days >= 30)
                            {

                                try
                                {
                                    //Define o idioma que será usado para envio do e-mail
                                    string cultureName = account.Country.language; //string.IsNullOrEmpty(account.culture) ? (string.IsNullOrEmpty(account.Country.language) ? CultureHelper.GetDefaultCulture() : account.Country.language) : account.culture;
                                    Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(CultureHelper.GetImplementedCulture(cultureName));
                                    Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
                                }
                                catch (Exception ex)
                                {
                                    //Salva o erro no arquivo de log do sistema
                                    ex.Save(new StackTrace(ex, true), ErrorLog.system);
                                }

                                //Define o assunto da mensagem
                                ViewBag.Title = String.Format(Resources.Resources.M_Missing_Title, account.name);

                                //Seguidores
                                ViewBag.Followers = oCore.businessControllers.bcConnection.Followers(account.id, 0, 1);

                                var message = new MailMessage();
                                message.From = new MailAddress(TopAppRouter.TopWelcomeEmail, "ThisIsOnTop.com");
                                message.Subject = ViewBag.Title;
                                message.Body = this.RenderRazorViewToString("~/Views/Emailing/Missing.cshtml", account);

                                //Destinatários
                                foreach (var cont in account.Contact.ToList())
                                {
                                    if (cont.IsEmail && !cont.Email.address.Contains("@thisisontop.com"))
                                    {
                                        message.To.Add(new MailAddress(cont.Email.address));
                                        await EmailSender.SendMailAsync(message);
                                        counter++;
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //Salva o erro no arquivo de log do sistema
                            var _ex = new Exception("Falha ao enviar e-mail de atualizações para o usuário " + account.id, ex);
                            _ex.Save(new StackTrace(ex, true), ErrorLog.system);
                        }
                    }

                    return Content("E-mail sent. Total sent: " + counter + " of " + rs.Count());
                }

                throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);

            }
            catch (Exception ex)
            {
                //Salva o erro no arquivo de log do sistema
                ex.Save(new StackTrace(ex, true), ErrorLog.system);

                return Content(ex.Message);
            }
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Updates()
        {
            try
            {
                //Permite somente que a os e-mails sejam enviados a partir da conta da empresa ThisIsOnTop.com
                if (oUserProfile.oAccount.id == 1 && oUserProfile.oAccount.IsCompanyAccount)
                {
                    int counter = 0;
                    var accounts = base.oCore.iRepositories.IAccountRepository.Select(AccountRecordStatus.Ative);

                    foreach (var account in accounts.ToList())
                    {
                        try
                        {
                            try
                            {
                                //Define o idioma que será usado para envio do e-mail
                                string cultureName = string.IsNullOrEmpty(account.culture) ? (string.IsNullOrEmpty(account.Country.language) ? CultureHelper.GetDefaultCulture() : account.Country.language) : account.culture;
                                Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo(CultureHelper.GetImplementedCulture(cultureName));
                                Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
                            }
                            catch (Exception ex)
                            {
                                //Salva o erro no arquivo de log do sistema
                                ex.Save(new StackTrace(ex, true), ErrorLog.system);
                            }

                            //Define o assunto da mensagem
                            ViewBag.Title = String.Format(Resources.Resources.M_Update_Title, account.name);

                            //Seguidores
                            ViewBag.Followers = oCore.businessControllers.bcConnection.Followers(account.id, 0, 1);

                            //User top post
                            Post topPost;
                            Country topCountry;
                            //var top = oCore.businessControllers.bcTop.TopList(oUserProfile.oAccount.id, 0, 1).Item1.Where(model => System.Data.Objects.EntityFunctions.DiffDays(DateTime.Now, model.creationDatetime) <= 6).ToList().FirstOrDefault();
                            var top = oCore.businessControllers.bcTop.TopList(oUserProfile.oAccount.id, 0, 1).Item1.ToList().FirstOrDefault();
                            if (top == null)
                            {
                                if (account.Country1 == null)
                                    topCountry = account.Location.LastOrDefault().Country;
                                else
                                    topCountry = account.Country1;

                                topPost = oCore.iRepositories.IPostRepository.Select(oCore.businessControllers.bcCountry.Boosted(topCountry, null, 0, 1).Item1.ToList().FirstOrDefault().id);
                            }
                            else
                            {
                                topPost = top.Post;
                                topCountry = top.Country;
                            }

                            ViewBag.TopCountry = topCountry;
                            ViewBag.TopPost = topPost;

                            var message = new MailMessage();
                            message.From = new MailAddress(TopAppRouter.TopWelcomeEmail, "ThisIsOnTop.com");
                            message.Subject = ViewBag.Title;
                            message.Body = this.RenderRazorViewToString("~/Views/Emailing/Updates.cshtml", account);

                            //Destinatários
                            foreach (var cont in account.Contact.ToList())
                            {
                                if (cont.IsEmail && !cont.Email.address.Contains("@thisisontop.com"))
                                {
                                    message.To.Add(new MailAddress(cont.Email.address));
                                    await EmailSender.SendMailAsync(message);
                                    counter++;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //Salva o erro no arquivo de log do sistema
                            var _ex = new Exception("Falha ao enviar e-mail de atualizações para o usuário " + account.id, ex);
                            _ex.Save(new StackTrace(ex, true), ErrorLog.system);
                        }
                    }

                    return Content("E-mail sent. Total sent: " + counter + " of " + accounts.Count());
                }

                throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);

            }
            catch (Exception ex)
            {
                //Salva o erro no arquivo de log do sistema
                ex.Save(new StackTrace(ex, true), ErrorLog.system);

                return Content(ex.Message);
            }
        }
Ejemplo n.º 3
0
        public async Task<ActionResult> LayoutUpdates()
        {
            try
            {
                //Permite somente que a os e-mails sejam enviados a partir da conta da empresa ThisIsOnTop.com
                if (oUserProfile.oAccount.id == 1 && oUserProfile.oAccount.IsCompanyAccount)
                {
                    int counter = 0;
                    var accounts = base.oCore.iRepositories.IAccountRepository.Select(AccountRecordStatus.Ative);

                    foreach (var account in accounts.Where(model => model.creationCountry != null && model.creationCountry == 2).ToList())
                    {
                        try
                        {
                            //Define o assunto da mensagem
                            ViewBag.Title = String.Format("{0}, diga olá para o novo layout!", account.name.Split(' ')[0]);
                            ViewBag.Bg = "https://staticqwehkp3wb9pzv.azurewebsites.net/Content/static/abctdefghi4b9da306co8c3e565pca5164a7f/_i/_mail/new_layout.jpg";

                            var message = new MailMessage();
                            message.From = new MailAddress(TopAppRouter.TopWelcomeEmail, "ThisIsOnTop.com");
                            message.Subject = ViewBag.Title;
                            message.Body = this.RenderRazorViewToString("~/Views/Emailing/LayoutUpdates.cshtml", account);

                            //Destinatários
                            foreach (var cont in account.Contact.ToList())
                            {
                                if (cont.IsEmail && !cont.Email.address.Contains("@thisisontop.com"))
                                {
                                    message.To.Add(new MailAddress(cont.Email.address));
                                    await EmailSender.SendMailAsync(message);
                                    counter++;
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            //Salva o erro no arquivo de log do sistema
                            var _ex = new Exception("Falha ao enviar e-mail de atualizações para o usuário " + account.id, ex);
                            _ex.Save(new StackTrace(ex, true), ErrorLog.system);
                        }
                    }

                    return Content("E-mail sent. Total sent: " + counter + " of " + accounts.Count());
                }

                throw new HttpException((int)HttpStatusCode.NotFound, string.Empty);

            }
            catch (Exception ex)
            {
                //Salva o erro no arquivo de log do sistema
                ex.Save(new StackTrace(ex, true), ErrorLog.system);

                return Content(ex.Message);
            }
        }