Пример #1
0
        public JsonResult SendNewEventEmailToSubscribers()
        {
            List <EventDataModal>           eventdata   = _EventService.GetAllNewEvents();
            List <EventViewModal>           events      = Mapper.Map <List <EventDataModal>, List <EventViewModal> >(eventdata);
            List <EmailSubscriberDataModal> subscribers = _SubscribeService.GetAllEmailSubscriber();

            string     MailUserName        = ConfigurationManager.AppSettings["MailUserName"] != null ? ConfigurationManager.AppSettings["MailUserName"].ToString() : "";
            string     NewEventMailSubject = ConfigurationManager.AppSettings["NewEventMailSubject"] != null ? ConfigurationManager.AppSettings["NewEventMailSubject"].ToString() : "Checkout our new Event!";
            List <int> eventids            = new List <int>();

            foreach (EventViewModal evt in events)
            {
                bool   isError   = false;
                String emailhtml = MvcHelpers.RenderViewToString(this.ControllerContext, "~/Views/Subscribe/NewEventEmail.cshtml", evt);
                foreach (EmailSubscriberDataModal sb in subscribers)
                {
                    isError = EmailHelper.SendEmail(MailUserName, sb.Email, NewEventMailSubject, emailhtml, null, "", true);
                }
                if (isError)
                {
                    eventids.Add(evt.EventID);
                }
            }
            _EventService.SetEmailSentFlag(eventids);

            return(Json(new { Code = 1, Message = "Success!" }, JsonRequestBehavior.AllowGet));
        }