Esempio n. 1
0
        public ActionResult Create(Article model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var cache = new Article
                    {
                        Date = model.Date,
                        Published = model.Published
                    };

                    context.AddToArticle(cache);

                    var lang = context.Language.FirstOrDefault(p => p.Id == model.CurrentLang);
                    if (lang != null)
                    {
                        CreateOrChangeContentLang(context, model, cache, lang);
                    }




                    var article = context.Article.First(c => c.Id == cache.Id);
                    article.CurrentLang = CurrentLang.Id;


                    if (model.SendToSubscribers)
                    {
                        using (var customerContext = new CustomerContainer())
                        {
                            var activeSubscribers = customerContext.Subscriber.Where(s => s.Active).ToList();
                            foreach (var subscriber in activeSubscribers)
                            {
                                var emailStatus = MailHelper.CreateSendEmailStatusInstance(article.Id, subscriber.Id);
                                customerContext.AddToSendEmailStatus(emailStatus);
                            }
                            customerContext.SaveChanges();


                            var newThread = new Thread(new ThreadStart(Listelli.Controllers.HomeController.ProcessSendEmail));
                            newThread.Start();
                            HttpContext.Application["mailSender"] = newThread;



                            //string articleText = HttpUtility.HtmlDecode(article.Description)
                            //                                .Replace("src=\"", "src=\"http://listelli.ua");
                            //List<MailAddress> addresses = new List<MailAddress>();
                            //foreach (var item in customerContext.Subscriber.Where(s => s.Active))
                            //    addresses.Add(new MailAddress(item.Email));

                            //string subscribeEmailFrom = ConfigurationManager.AppSettings["subscribeEmailFrom"];
                            //var emailFrom = new MailAddress(subscribeEmailFrom, "Listelli");

                            //MailHelper.SendTemplateByPortions(emailFrom, addresses, article.Title, "Newsletter.htm", null, true,
                            //                        articleText);
                        }
                    }
                    return RedirectToAction("Articles", "Home", new { area = "" });
                }
            }
            catch
            {
                return View();
            }
        }
Esempio n. 2
0
        private void CreateOrChangeContentLang(SiteContainer context, Article instance, Article cache, Language lang)
        {
            ArticleLang contenttLang = null;
            if (cache != null)
            {
                contenttLang = context.ArticleLang.FirstOrDefault(p => p.ArticleId == cache.Id && p.LanguageId == lang.Id);
            }
            if (contenttLang == null)
            {
                var newPostLang = new ArticleLang
                {
                    ArticleId = instance.Id,
                    LanguageId = lang.Id,
                    Title = instance.Title,
                    Description = HttpUtility.HtmlDecode(instance.Description)
                };
                context.AddToArticleLang(newPostLang);




            }
            else
            {
                contenttLang.Title = instance.Title;
                contenttLang.Description = HttpUtility.HtmlDecode(instance.Description);
            }
            context.SaveChanges();

        }
Esempio n. 3
0
 /// <summary>
 /// Create a new Article object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="date">Initial value of the Date property.</param>
 /// <param name="published">Initial value of the Published property.</param>
 public static Article CreateArticle(global::System.Int32 id, global::System.DateTime date, global::System.Boolean published)
 {
     Article article = new Article();
     article.Id = id;
     article.Date = date;
     article.Published = published;
     return article;
 }
Esempio n. 4
0
        public ActionResult Edit(Article model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var cache = context.Article.FirstOrDefault(p => p.Id == model.Id);
                    if (cache != null)
                    {
                        TryUpdateModel(cache, new[] { "Date", "Published" });

                        var lang = context.Language.FirstOrDefault(p => p.Id == model.CurrentLang);
                        if (lang != null)
                        {
                            CreateOrChangeContentLang(context, model, cache, lang);
                        }
                    }


                    var article = context.Article.First(c => c.Id == cache.Id);
                    article.CurrentLang = CurrentLang.Id;


                    if (model.SendToSubscribers)
                    {
                        using (var customerContext = new CustomerContainer())
                        {
                            var existedStatuses = customerContext.SendEmailStatus.Where(s => s.ArticleId == article.Id).ToList();
                            var activeSubscribers = customerContext.Subscriber.Where(s => s.Active).ToList();

                            foreach (var subscriber in activeSubscribers)
                            {
                                var existedStatus =
                                    existedStatuses.FirstOrDefault(
                                        s => s.SubscriberId == subscriber.Id && s.ArticleId == article.Id);

                                if (existedStatus == null)
                                {

                                    var emailStatus = MailHelper.CreateSendEmailStatusInstance(article.Id, subscriber.Id);

                                    customerContext.AddToSendEmailStatus(emailStatus);
                                }
                            }
                            customerContext.SaveChanges();



                            var newThread = new Thread(new ThreadStart(Listelli.Controllers.HomeController.ProcessSendEmail));
                            newThread.Start();
                            HttpContext.Application["mailSender"] = newThread;

                        }
                    }

                    return RedirectToAction("Articles", "Home", new { area = "" });
                }
            }
            catch
            {
                return View();
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Article EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToArticle(Article article)
 {
     base.AddObject("Article", article);
 }