public ActionResult UpdateWidgetItem(int widgetType, int id, string title, string url) { using (var context = new ContentStorage()) { var widgetItem = context.Widgets.Select(w => w).Where(w => w.Id == id).FirstOrDefault(); widgetItem.Title = title; widgetItem.Url = url; context.SaveChanges(); } return Redirect("~/Widgets/" + widgetType); }
public ActionResult DeleteWidgetItem(int widgetType,int id) { using (var context = new ContentStorage()) { var widgetItem = context.Widgets.Select(w => w).Where(w => w.Id == id).FirstOrDefault(); if (widgetItem != null) { context.DeleteObject(widgetItem); context.SaveChanges(); } } return Redirect("~/Widgets/" + widgetType); }
public ActionResult AddWidgetItem(int widgetType, string title, string url) { ViewData["type"] = widgetType; string file = Request.Files["image"].FileName; if (!string.IsNullOrEmpty(file)) { string newFileName = IOHelper.GetUniqueFileName("~/Content/WidgetImages", file); string filePath = Path.Combine(Server.MapPath("~/Content/WidgetImages"), newFileName); Request.Files["image"].SaveAs(filePath); using (var context = new ContentStorage()) { var widgetItem = new Widgets { Type = widgetType, ImageSource = newFileName, Title = title, Url = url }; context.AddToWidgets(widgetItem); context.SaveChanges(); } } return RedirectToAction("Index", "Content"); }
public ActionResult DeleteArticle(string id) { using (ContentStorage context = new ContentStorage()) { List<Article> articles = context.Article.Where(a => a.Name == id).ToList(); foreach (var item in articles) { context.DeleteObject(item); } context.SaveChanges(); } return RedirectToAction("Index", "News"); }
public ActionResult AddGalleryItem(int parentId, string contentId, int galleryId) { string file = Request.Files["image"].FileName; if (!string.IsNullOrEmpty(file)) { string newFileName = IOHelper.GetUniqueFileName("~/Content/GalleryImages", file); string filePath = Path.Combine(Server.MapPath("~/Content/GalleryImages"), newFileName); string filePathTmp = Path.Combine(Server.MapPath("~/Content/GalleryImages/tmp"), newFileName); Request.Files["image"].SaveAs(filePathTmp); string imgWatermarkPath = Server.MapPath("~/Content/img/watermark.png"); Bitmap imgWatermark = new Bitmap(imgWatermarkPath); Image imgPhoto = Image.FromFile(filePathTmp); DrawWatermark(imgPhoto, imgWatermark, WatermarkPosition.BottomMiddle, Color.FromArgb(0, 255, 0), 0.7f); imgPhoto.Save(filePath, ImageFormat.Jpeg); imgPhoto.Dispose(); imgWatermark.Dispose(); System.IO.File.Delete(filePathTmp); using (var context = new ContentStorage()) { var galleryItem = new GalleryItems(); galleryItem.GalleryReference.EntityKey = new EntityKey("ContentStorage.Gallery", "Id", parentId); galleryItem.ImageSource = newFileName; context.AddToGalleryItems(galleryItem); context.SaveChanges(); } } //return RedirectToAction("Index", "Content", new { id = contentId }); return Redirect("~/Galleries/" + galleryId); /*return RedirectToAction("Index", "Galleries", new { id = contentId });*/ }
public ActionResult DeleteContentItem(int id) { using (var context = new ContentStorage()) { Content content = context.Content.Include("Children").Where(c => c.Id == id).FirstOrDefault(); string contentId = content.ContentId; if (content.Children.Count == 0) { context.DeleteObject(content); context.SaveChanges(); } return RedirectToAction("Index", "Content", new { id = "About" }); } }
public ActionResult AddEditArticle(string id, string title, string date, string keywords, string description, string text, bool isNew) { using (ContentStorage context = new ContentStorage()) { Article article; if (isNew) { article = new Article(); article.Name = id; context.AddToArticle(article); } else { article = context.Article.Where(a => a.Name == id).First(); } article.Title = title; article.Date = DateTime.Parse(date); article.Text = HttpUtility.HtmlDecode(text); article.Description = description; article.Keywords = keywords; context.SaveChanges(); } return RedirectToAction("Index", "News"); }
public ActionResult UpdateContent(int id, bool isGalleryItem, int? parentId, string contentId, string title, string description, string keywords, string text, bool? horisontal, int sortOrder, int contentLevel) { using (var context = new ContentStorage()) { Content parent = null; if (parentId != null) parent = context.Content.Select(c => c).Where(c => c.Id == parentId).First(); Content content = id != int.MinValue ? context.Content.Select(c => c).Where(c => c.Id == id).First() : new Content(); content.Parent = parent; content.ContentId = contentId; content.Title = title; content.Description = description; content.Keywords = keywords; content.Text = HttpUtility.HtmlDecode(text); content.ContentLevel = contentLevel; content.IsGalleryItem = isGalleryItem; content.SortOrder = sortOrder; if (content.Id == 0) context.AddToContent(content); context.SaveChanges(); return RedirectToAction("Index", "Content", new { id = contentId }); } }
public ActionResult SetDefaultImage(int id, string contentId, int galleryId) { using (var context = new ContentStorage()) { GalleryItems galleryItem = context.GalleryItems.Select(g => g).Where(g => g.Id == id).FirstOrDefault(); Gallery gallery = context.Gallery.Select(g => g).Where(g => g.Id == galleryId).FirstOrDefault(); gallery.ImageSource = galleryItem.ImageSource; context.SaveChanges(); } return RedirectToAction("Index", "Content", new { id = contentId }); }
public ActionResult DeleteGalleryItem(int id, string contentId, int galleryId) { using (var context = new ContentStorage()) { GalleryItems galleryItem = context.GalleryItems.Select(g => g).Where(g => g.Id == id).FirstOrDefault(); context.DeleteObject(galleryItem); context.SaveChanges(); //return RedirectToAction("Index", "Content", new { id = contentId }); return Redirect("~/Galleries/" + galleryId); } }
public ActionResult DeleteGallery(int id, string contentId) { using (var context = new ContentStorage()) { Gallery gallery = context.Gallery.Include("GalleryItems").Select(g => g).Where(g => g.Id == id).FirstOrDefault(); if (gallery.GalleryItems.Count == 0) { context.DeleteObject(gallery); context.SaveChanges(); } return RedirectToAction("Index", "Content", new { id = contentId }); } }
public ActionResult AddGallery(int parentId, string contentId,string galleryName) { using (var context = new ContentStorage()) { var galleryItem = new Gallery(); galleryItem.ContentReference.EntityKey = new EntityKey("ContentStorage.Content", "Id", parentId); galleryItem.Title = galleryName; galleryItem.ImageSource = ""; context.AddToGallery(galleryItem); context.SaveChanges(); } return RedirectToAction("Index", "Content", new { id = contentId }); }