public ActionResult AddTextBlock(FormCollection form) { using (var context = new SiteContainer()) { var contentItem = new ContentItem { ContentType = 1, Text = HttpUtility.HtmlDecode(form["Text"]) }; TryUpdateModel(contentItem, new[] { "SortOrder" }); context.AddToContentItem(contentItem); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = "look" }); } }
/// <summary> /// Create a new ContentItem object. /// </summary> /// <param name="id">Initial value of the Id property.</param> /// <param name="contentType">Initial value of the ContentType property.</param> /// <param name="sortOrder">Initial value of the SortOrder property.</param> public static ContentItem CreateContentItem(global::System.Int32 id, global::System.Int32 contentType, global::System.Int32 sortOrder) { ContentItem contentItem = new ContentItem(); contentItem.Id = id; contentItem.ContentType = contentType; contentItem.SortOrder = sortOrder; return contentItem; }
/// <summary> /// Deprecated Method for adding a new object to the ContentItem EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToContentItem(ContentItem contentItem) { base.AddObject("ContentItem", contentItem); }
public ActionResult AddImagesBlock(FormCollection form) { using (var context = new SiteContainer()) { var contentItem = new ContentItem { ContentType = 2 }; TryUpdateModel(contentItem, new[] { "SortOrder" }); for (int i = 0; i < Request.Files.Count; i++) { var file = Request.Files[i]; if (file == null) continue; if (string.IsNullOrEmpty(file.FileName)) continue; var ci = new ContentItemImage(); 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); ci.ImageSource = fileName; contentItem.ContentItemImages.Add(ci); } context.AddToContentItem(contentItem); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = "look" }); } }