예제 #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            HomeGallery homeGallery = db.HomeGalleries.Find(id);

            db.HomeGalleries.Remove(homeGallery);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #2
0
        //
        // GET: /HomeGallery/Create

        public ActionResult Create()
        {
            var homegallery = new HomeGallery
            {
            };

            return(View(homegallery));
        }
예제 #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            HomeGallery homegallery = db.HomeGalleries.Find(id);

            System.IO.File.Delete(Server.MapPath(homegallery.Picture));
            System.IO.File.Delete(Server.MapPath(ToThumbnailPath(homegallery.Picture)));
            db.HomeGalleries.Remove(homegallery);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #4
0
 public ActionResult Edit([Bind(Include = "ID,ImagePath")] HomeGallery homeGallery)
 {
     if (ModelState.IsValid)
     {
         db.Entry(homeGallery).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(homeGallery));
 }
예제 #5
0
        public ActionResult Create(HomeGallery homegallery, IEnumerable <HttpPostedFileBase> newsPhotos)
        {
            int count = 0;

            if (ModelState.IsValid)
            {
                // The Name of the Upload component is "newsPhotos"
                if ((newsPhotos == null) || (newsPhotos.Count() == 0))
                {
                    ModelState.AddModelError("", "请检查您是否忘记上传图片了");
                    return(View(homegallery));
                }
                foreach (var file in newsPhotos)
                {
                    if (!HasFile(file))
                    {
                        ModelState.AddModelError("", "请检查您是否忘记上传图片了?");
                        return(View(homegallery));
                    }
                    // Some browsers send file names with full path. This needs to be stripped.
                    var fileName     = Path.GetFileName(file.FileName);
                    var physicalPath = Path.Combine(Server.MapPath(gallery_path), fileName);
                    while (System.IO.File.Exists(physicalPath))
                    {
                        fileName     = count.ToString() + fileName;
                        physicalPath = Path.Combine(Server.MapPath(gallery_path), fileName);
                    }
                    file.SaveAs(physicalPath);

                    string full_fileName = full_prefix + fileName;
                    string full_path     = Path.Combine(Server.MapPath(gallery_path), full_fileName);
                    ImageOpt.ScaleImage(physicalPath, full_path, full_width, full_height);

                    string thumbnail_path = Path.Combine(Server.MapPath(gallery_path), thumbnail_prefix + full_fileName);
                    ImageOpt.ScaleImage(physicalPath, thumbnail_path, thumbnail_width, thumbnail_height);

                    System.IO.File.Delete(physicalPath);

                    homegallery.Picture = Url.Content(gallery_path + "/" + full_fileName);
                }
                if (!String.IsNullOrEmpty(homegallery.HyperLink))
                {
                    homegallery.HyperLink = GetAbsoluteUrl(homegallery.HyperLink);
                }
                db.HomeGalleries.Add(homegallery);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(homegallery));
        }
예제 #6
0
        // GET: HomeGalleries/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HomeGallery homeGallery = db.HomeGalleries.Find(id);

            if (homeGallery == null)
            {
                return(HttpNotFound());
            }
            return(View(homeGallery));
        }
예제 #7
0
        public ActionResult Create(HomeGallery homeGallery, HttpPostedFileBase ImagePath)
        {
            if (ModelState.IsValid)
            {
                string ImageName = Path.GetFileName(ImagePath.FileName);
                string Image     = Server.MapPath(@"\Images\" + ImageName);
                ImagePath.SaveAs(Image);
                DataObject.ImagePath = (@"\Images\" + ImageName);
                db.HomeGalleries.Add(DataObject);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(DataObject));
        }
예제 #8
0
        //
        // GET: /HomeGallery/Delete/5

        public ActionResult Delete(int id)
        {
            HomeGallery homegallery = db.HomeGalleries.Find(id);

            return(View(homegallery));
        }