コード例 #1
0
ファイル: GalleryController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult Add(FormCollection form, HttpPostedFileBase fileUpload)
        {
            using (var context = new ContentStorage())
            {
                var gallery = new Gallery();
                TryUpdateModel(gallery, new[]
                                            {
                                                "Name",
                                                "Title",
                                                "PageTitle",
                                                "SortOrder"
                                            });

                string fileName = IOHelper.GetUniqueFileName("~/Content/Photos", fileUpload.FileName);
                string filePath = Server.MapPath("~/Content/Photos");
                filePath = Path.Combine(filePath, fileName);
                fileUpload.SaveAs(filePath);

                gallery.ImageSource = fileName;

                context.AddToGallery(gallery);
                context.SaveChanges();

                return RedirectToAction("Index", "Gallery", new { Area = ""});
            }
        }
コード例 #2
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
 public ActionResult Delete(int id)
 {
     using (var context = new ContentStorage())
     {
         var content = context.Content.Where(c => c.Id == id).First();
         context.DeleteObject(content);
         context.SaveChanges();
     }
     return RedirectToAction("Index", "Home", new {id="", area = "" });
 }
コード例 #3
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult AddContent(Content model, FormCollection form)
        {
            using (var context = new ContentStorage())
            {
                model.Text = HttpUtility.HtmlDecode(form["Text"]);

                context.AddToContent(model);
                context.SaveChanges();

                return RedirectToAction("Index", "Home", new { id = model.Name, area = "" });
            }
        }
コード例 #4
0
ファイル: ContentController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult EditContent(int id, FormCollection form)
        {
            using (var context = new ContentStorage())
            {
                var content = context.Content.Where(c => c.Id == 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 = "" });
            }
        }
コード例 #5
0
ファイル: GalleryController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult AddImageToGallery(int galleryId, FormCollection form, HttpPostedFileBase fileUpload)
        {
            using (var context = new ContentStorage())
            {
                var galleryItem = new Galleryitem();
                TryUpdateModel(galleryItem, new[] { "SortOrder" });
                string fileName = IOHelper.GetUniqueFileName("~/Content/Photos", fileUpload.FileName);
                string filePath = Server.MapPath("~/Content/Photos");
                filePath = Path.Combine(filePath, fileName);
                fileUpload.SaveAs(filePath);

                galleryItem.ImageSource = fileName;

                var gallery = context.Gallery.Where(g => g.Id == galleryId).First();

                gallery.GalleryItems.Add(galleryItem);

                context.SaveChanges();


                return RedirectToAction("Details", "Gallery", new {Area = "", id = gallery.Name});
            }
        }
コード例 #6
0
ファイル: GalleryController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult DeleteGallery(int id)
        {
            using (var context = new ContentStorage())
            {
                var gallery = context.Gallery.Include("GalleryItems").Where(g=>g.Id==id).First();

                while (gallery.GalleryItems.Any())
                {
                    var galleryItem = gallery.GalleryItems.First();
                    IOHelper.DeleteFile("~/Content/Photos", galleryItem.ImageSource);
                    IOHelper.DeleteFile("~/ImageCache/thumbnail", galleryItem.ImageSource);
                    context.DeleteObject(galleryItem);
                }

                IOHelper.DeleteFile("~/Content/Photos", gallery.ImageSource);
                IOHelper.DeleteFile("~/ImageCache/thumbnail", gallery.ImageSource);
                context.DeleteObject(gallery);

                context.SaveChanges();

            }
            return RedirectToAction("Index", "Gallery", new { Area = ""});
        }
コード例 #7
0
ファイル: GalleryController.cs プロジェクト: fathurxzz/aleqx
        public ActionResult DeleteImage(int galleryId, int id)
        {
            using (var context = new ContentStorage())
            {
                var galleryItem = context.Galleryitem.Where(gi => gi.Id == id).First();
                var gallery = context.Gallery.Where(g => g.Id == galleryId).First();

                IOHelper.DeleteFile("~/Content/Photos", galleryItem.ImageSource);
                IOHelper.DeleteFile("~/ImageCache/thumbnail", galleryItem.ImageSource);
                context.DeleteObject(galleryItem);
                context.SaveChanges();

                return RedirectToAction("Details", "Gallery", new {Area = "", id = gallery.Name});
            }
        }