public ActionResult Add(FormCollection form) { using (var context = new StructureContainer()) { var content = new Content { MainPage = false, ContentLevel = 1 }; if (!string.IsNullOrEmpty(form["parentId"])) { int parentId = Convert.ToInt32(form["parentId"]); var parent = context.Content.Where(c => c.Id == parentId).First(); content.Parent = parent; content.ContentLevel = parent.ContentLevel + 1; } TryUpdateModel(content, new[] { "Name", "Title", "MenuTitle", "PageTitle", "SortOrder", "SeoDescription", "SeoKeywords" }); content.Text = HttpUtility.HtmlDecode(form["Text"]); context.AddToContent(content); context.SaveChanges(); return RedirectToAction("Index", "Home", new { id = content.Name, area = "" }); } }
public ActionResult Edit(Content model, FormCollection form) { using (var context = new StructureContainer()) { var content = context.Content.Where(c => c.Id == model.Id).First(); TryUpdateModel(content, new[] { "Name", "Title", "PageTitle", "SortOrder", "SeoDescription", "SeoKeywords", }); content.Text = HttpUtility.HtmlDecode(form["Text"]); context.SaveChanges(); return RedirectToAction("Index", "Home", new { id = content.Name, area = "" }); } }
/// <summary> /// Create a new Content object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="title">Initial value of the Title property.</param> /// <param name="pageTitle">Initial value of the PageTitle property.</param> /// <param name="text">Initial value of the Text property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="sortOrder">Initial value of the SortOrder property.</param> /// <param name="contentLevel">Initial value of the ContentLevel property.</param> public static Content CreateContent(global::System.Int32 id, global::System.String title, global::System.String pageTitle, global::System.String text, global::System.String name, global::System.Int32 sortOrder, global::System.Int32 contentLevel) { Content content = new Content(); content.Id = id; content.Title = title; content.PageTitle = pageTitle; content.Text = text; content.Name = name; content.SortOrder = sortOrder; content.ContentLevel = contentLevel; return content; }
/// <summary> /// Deprecated Method for adding a new object to the Content EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToContent(Content content) { base.AddObject("Content", content); }