Ejemplo n.º 1
0
 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 });
     }
 }
Ejemplo n.º 2
0
        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 });
            }
        }