Example #1
0
        public ActionResult CreateTextBlock(ArticleItem model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var article = context.Article.First(b => b.Id == model.ArticleId);
                    var cache = new ArticleItem
                    {
                        SortOrder = model.SortOrder,
                        ContentType = 1,
                        Article = article,
                        ImageSource = ""
                    };

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

                    return RedirectToAction("Articles", "Home", new { area = "" });
                }
            }
            catch
            {
                return View();
            }
        }
Example #2
0
        public ActionResult EditTextBlock(ArticleItem model)
        {
            using (var context = new SiteContainer())
            {
                var cache = context.ArticleItem.Include("Article").First(p => p.Id == model.Id);

                TryUpdateModel(cache, new[] { "SortOrder" });

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


                return RedirectToAction("Articles", "Home", new { area = "" });
            }
        }
Example #3
0
        private void CreateOrChangeContentLang(SiteContainer context, ArticleItem instance, ArticleItem cache, Language lang)
        {

            ArticleItemLang contenttLang = null;
            if (cache != null)
            {
                contenttLang = context.ArticleItemLang.FirstOrDefault(p => p.ArticleItemId == cache.Id && p.LanguageId == lang.Id);
            }
            if (contenttLang == null)
            {
                var newPostLang = new ArticleItemLang
                {
                    ArticleItemId = instance.Id,
                    LanguageId = lang.Id,
                    Text = HttpUtility.HtmlDecode(instance.Text)
                };
                context.AddToArticleItemLang(newPostLang);
            }
            else
            {
                contenttLang.Text = HttpUtility.HtmlDecode(instance.Text);
            }
            context.SaveChanges();

        }
Example #4
0
        public ActionResult CreateImageBlock(ArticleItem model)
        {
            try
            {
                using (var context = new SiteContainer())
                {
                    var article = context.Article.Include("ArticleItems").First(b => b.Id == model.ArticleId);

                    int maxSortOrder = article.ArticleItems.Max(c => (int?)c.SortOrder) ?? 0;


                    for (int i = 0; i < Request.Files.Count; i++)
                    {
                        maxSortOrder++;
                        var file = Request.Files[i];

                        if (file == null) continue;
                        if (string.IsNullOrEmpty(file.FileName)) continue;

                        var ai = new ArticleItem {SortOrder = maxSortOrder, ContentType = 2};
                        string fileName = IOHelper.GetUniqueFileName("~/Content/Images", file.FileName);
                        string filePath = Server.MapPath("~/Content/Images");

                        filePath = Path.Combine(filePath, fileName);
                        GraphicsHelper.SaveOriginalImage(filePath, fileName, file, 1500);
                        
                        ai.ImageSource = fileName;

                        article.ArticleItems.Add(ai);
                    }

                    context.SaveChanges();


                    return RedirectToAction("Articles", "Home", new { area = "" });
                }
            }
            catch
            {
                return View();
            }
        }
Example #5
0
 /// <summary>
 /// Create a new ArticleItem object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="contentType">Initial value of the ContentType property.</param>
 /// <param name="imageSource">Initial value of the ImageSource property.</param>
 /// <param name="articleId">Initial value of the ArticleId property.</param>
 /// <param name="sortOrder">Initial value of the SortOrder property.</param>
 public static ArticleItem CreateArticleItem(global::System.Int32 id, global::System.Int32 contentType, global::System.String imageSource, global::System.Int32 articleId, global::System.Int32 sortOrder)
 {
     ArticleItem articleItem = new ArticleItem();
     articleItem.Id = id;
     articleItem.ContentType = contentType;
     articleItem.ImageSource = imageSource;
     articleItem.ArticleId = articleId;
     articleItem.SortOrder = sortOrder;
     return articleItem;
 }
Example #6
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ArticleItem EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToArticleItem(ArticleItem articleItem)
 {
     base.AddObject("ArticleItem", articleItem);
 }