public ActionResult Delete(int id) { using (var context = new ContentStorage()) { var gallery = context.Gallery.Include("GalleryItems").Include("Content").Where(g => g.Id == id).First(); var content = gallery.Content; while (gallery.GalleryItems.Any()) { var photo = gallery.GalleryItems.First(); if (!string.IsNullOrEmpty(photo.ImageSource)) { IOHelper.DeleteFile("~/Content/Photos", photo.ImageSource); IOHelper.DeleteFile("~/ImageCache/mainView", photo.ImageSource); IOHelper.DeleteFile("~/ImageCache/thumbnail", photo.ImageSource); IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", photo.ImageSource); } context.DeleteObject(gallery.GalleryItems.First()); } context.DeleteObject(gallery); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = content.Name }); } }
public ActionResult Edit(int id) { using (var context = new ContentStorage()) { var content = context.Content.Where(c => c.Id == id).First(); return View(content); } }
public ActionResult Edit(int id) { using (var context = new ContentStorage()) { var gallery = context.Gallery.Include("Content").Where(g => g.Id == id).First(); ViewData["contentName"] = gallery.Content.Name; return View(gallery); } }
public ActionResult Delete(int id) { using (var context = new ContentStorage()) { var content = context.Content.Include("Parent").Where(c => c.Id == id).First(); string parentName = content.Parent.Name; context.DeleteObject(content); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = parentName }); } }
public ActionResult Add(int id) { ViewData["id"] = id; using (var context = new ContentStorage()) { var content = context.Content.Include("Galleries").Where(c => c.Id == id).First(); int sortOrder = content.Galleries.Count > 0 ? content.Galleries.Max(c => c.SortOrder) : -1; ViewData["SortOrder"] = (sortOrder + 1).ToString(); return View(new Gallery {SortOrder = sortOrder + 1}); } }
public ActionResult Edit(int id, FormCollection form) { using (var context = new ContentStorage()) { var gallery = context.Gallery.Include("Content").Where(g => g.Id == id).First(); var content = gallery.Content; return RedirectToAction("Index", "Home", new { area = "", id = content.Name }); } }
public ActionResult Edit(int id, FormCollection form) { using (var context = new ContentStorage()) { Content content = context.Content.Where(c => c.Id == id).FirstOrDefault(); TryUpdateModel(content, new string[] { "Name", "PageTitle", "PageTitleEng", "Title", "TitleEng", "SeoKeywords", "SeoKeywordsEng", "SeoDescription", "SeoDescriptionEng", "SortOrder" }); content.Text = HttpUtility.HtmlDecode(form["Text"]); content.TextEng = HttpUtility.HtmlDecode(form["TextEng"]); content.Description = HttpUtility.HtmlDecode(form["Description"]); content.DescriptionEng = HttpUtility.HtmlDecode(form["DescriptionEng"]); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = content.Name }); } }
public ActionResult Add(int id, FormCollection form) { using (var context = new ContentStorage()) { var parentContent = context.Content.Where(c => c.Id == id).First(); var content = new Content {ContentLevel = 1}; TryUpdateModel(content, new string[] { "Name", "PageTitle", "PageTitleEng", "Title", "TitleEng", "SeoKeywords", "SeoKeywordsEng", "SeoDescription", "SeoDescriptionEng", "SortOrder" }); content.Parent = parentContent; context.AddToContent(content); context.SaveChanges(); return RedirectToAction("Index", "Home", new {area="", id = parentContent.Name}); } }
public ActionResult Add(int id, FormCollection form) { ViewData["id"] = id; using (var context = new ContentStorage()) { var content = context.Content.Where(c => c.Id == id).First(); var gallery = new Gallery { Content = content, }; TryUpdateModel(gallery, new string[] { "Description", "DescriptionEng", "SortOrder" }); context.AddToGallery(gallery); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = content.Name }); } }
public ActionResult SetPreviewPicture(int id) { using (var context = new ContentStorage()) { var photo = context.GalleryItem.Include("Gallery").Where(p => p.Id == id).First(); long galleryId = photo.Gallery.Id; var gallery = context.Gallery.Include("Content").Where(g => g.Id == galleryId).First(); gallery.ImageSource = photo.ImageSource; context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = gallery.Content.Name, galleryId = galleryId }); } }
public ActionResult AddPhoto(int galleryId, string contentName, FormCollection form) { using (var context = new ContentStorage()) { var gallery = context.Gallery.Include("GalleryItems").Where(g => g.Id == galleryId).FirstOrDefault(); if (Request.Files["logo"] != null && !string.IsNullOrEmpty(Request.Files["logo"].FileName)) { string fileName = IOHelper.GetUniqueFileName("~/Content/Photos", Request.Files["logo"].FileName); string filePath = Server.MapPath("~/Content/Photos"); filePath = Path.Combine(filePath, fileName); Request.Files["logo"].SaveAs(filePath); GraphicsHelper.SaveCachedImage("~/Content/Photos", fileName, "mainView"); GraphicsHelper.SaveCachedImage("~/Content/Photos", fileName, "galleryThumbnail"); gallery.GalleryItems.Add(new GalleryItem { ImageSource = fileName }); if (gallery.GalleryItems.Count == 1) gallery.ImageSource = fileName; context.SaveChanges(); } return RedirectToAction("Index", "Home", new { area = "", id = contentName, galleryId=galleryId }); } }
public ActionResult AddPhoto(int id) { ViewData["galleryId"] = id; using (var context = new ContentStorage()) { var gallery = context.Gallery.Include("Content").Where(g => g.Id == id).First(); ViewData["contentName"] = gallery.Content.Name; } return View(); }
public ActionResult Index(string id, int? galleryPage, int? galleryId) { using (var context = new ContentStorage()) { var menuItems = context.Content.Where(c => c.ContentLevel == 0 && c.Id != 1).OrderBy(c => c.SortOrder).ToList(); ViewData["menuItems"] = menuItems; Content content; if (id == null) content = context.Content.Where(c => c.Id == 1).FirstOrDefault(); else { content = context.Content.Include("Parent").Include("Children").Include("Galleries").Where(c => c.Name == id).FirstOrDefault(); if (content.Parent != null) ViewData["parentContentName"] = content.Parent.Name; } if (content.Children.Count > 0) { var subMenuItems = content.Children.OrderBy(c => c.SortOrder).ToList(); ViewData["subMenuItems"] = subMenuItems; } else if (content.Parent != null) { var parentContentId = content.Parent.Id; var parentContent = context.Content.Include("Children").Where(pc => pc.Id == parentContentId).First(); var subMenuItems = parentContent.Children.OrderBy(c => c.SortOrder).ToList(); ViewData["subMenuItems"] = subMenuItems; } if (content.Galleries.Count > 0) { if (galleryPage.HasValue) { ViewData["galleryPage"] = galleryPage.Value; } ViewData["Galleries"] = content.Galleries; } else { ViewData["Galleries"] = new List<Gallery>(); } if(galleryId.HasValue) { var gallery = context.Gallery.Include("GalleryItems").Where(g => g.Id == galleryId.Value).First(); ViewData["Gallery"] = gallery; ViewData["galleryId"] = galleryId.Value; }else { ViewData["Gallery"] = new Gallery(); } ViewData["contentName"] = content.Name; ViewData["contentId"] = content.Id; ViewData["contentLevel"] = content.ContentLevel; return View(content); } }