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); } }
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(); } }
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); } }
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(); }
public ActionResult Create() { Article article = new Article { Date = DateTime.Now }; return View(article); }
/// <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; }
/// <summary> /// Deprecated Method for adding a new object to the Article EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToArticle(Article article) { base.AddObject("Article", article); }