Example #1
0
        public ActionResult Create(Article model)
        {
            try
            {
                model.Id = 0;
                var category = _context.Categories.First(c => c.Id == model.CategoryId);

                model.Description = HttpUtility.HtmlDecode(model.Description);

                var cache = new Article
                {
                    Category = category,
                    Published = model.Published,
                    Date = model.Date,
                    Title = model.Title,
                    Description = model.Description
                };

                _context.Articles.Add(cache);

                var lang = _context.Languages.FirstOrDefault(p => p.Id == model.CurrentLang);
                if (lang != null)
                {
                    CreateOrChangeContentLang(_context, model, cache, lang);
                }
                return RedirectToAction("Index","Category");
            }
            catch (Exception)
            {

                return View(model);
            }
        }
Example #2
0
 public ActionResult Create(FormCollection form)
 {
     try
     {
         using (var context = new SiteContainer())
         {
             Article article = new Article();
             TryUpdateModel(article, new[] { "Title", "Date" });
             article.Text = HttpUtility.HtmlDecode(form["Text"]);
             context.AddToArticle(article);
             context.SaveChanges();
         }
         return RedirectToAction("Index", "Home", new { Area = "", id = "" });
     }
     catch
     {
         return View();
     }
 }
Example #3
0
 public ActionResult Edit(Article model)
 {
     try
     {
         model.Description = HttpUtility.HtmlDecode(model.Description);
         var cache = _context.Articles.FirstOrDefault(p => p.Id == model.Id);
         if (cache != null)
         {
             TryUpdateModel(cache, new[] { "Title","Date", "Published" });
             cache.Description = model.Description;
             var lang = _context.Languages.FirstOrDefault(p => p.Id == model.CurrentLang);
             if (lang != null)
             {
                 CreateOrChangeContentLang(_context, model, cache, lang);
             }
         }
         return RedirectToAction("Index", "Category");
     }
     catch
     {
         return View(model);
     }
 }
Example #4
0
        private void CreateOrChangeContentLang(SiteContext context, Article instance, Article cache, Language lang)
        {

            ArticleLang productLang = null;
            if (cache != null)
            {
                productLang = context.ArticleLangs.FirstOrDefault(p => p.ArticleId == cache.Id && p.LanguageId == lang.Id);
            }
            if (productLang == null)
            {
                var newPostLang = new ArticleLang
                {
                    ArticleId = instance.Id,
                    LanguageId = lang.Id,
                    Title = instance.Title,
                    Description = instance.Description
                };
                context.ArticleLangs.Add(newPostLang);
            }
            else
            {
                productLang.Title = instance.Title;
                productLang.Description = instance.Description;
            }
            context.SaveChanges();

        }
Example #5
0
 public ActionResult Create()
 {
     Article article = new Article { Date = DateTime.Now };
     return View(article);
 }
Example #6
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="title">Initial value of the Title property.</param>
 public static Article CreateArticle(global::System.Int32 id, global::System.DateTime date, global::System.String title)
 {
     Article article = new Article();
     article.Id = id;
     article.Date = date;
     article.Title = title;
     return article;
 }
Example #7
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);
 }