Example #1
0
        public ActionResult EditAlbum(int id, string Opisanie, HttpPostedFileBase[] file)
        {
            using (mozartdv_34Entities de = new mozartdv_34Entities())
            {
                GalleryAlbum ga = de.GalleryAlbum.Where(x => x.Id == id).First();
                ga.Text = Opisanie;
                de.SaveChanges();

                foreach (var item in file)
                {
                    if (item != null && item.ContentLength > 0)
                    {
                        string path = System.IO.Path.Combine(Server.MapPath("~/Content/UploadImage"), System.IO.Path.GetFileName(item.FileName));
                        item.SaveAs(path);
                        GalleryFoto gf = new GalleryFoto();
                        gf.Id_Album  = id;
                        gf.PathImage = item.FileName;
                        de.GalleryFoto.Add(gf);
                        de.SaveChanges();
                    }
                }
            }

            return(RedirectToAction("EditAlbum/" + id, "AdminFoto"));
        }
Example #2
0
 public ActionResult Preview(int id)
 {
     using (mozartdv_34Entities de = new mozartdv_34Entities())
     {
         GalleryFoto firstfotofromalbum = de.GalleryFoto.Where(x => x.Id == id).FirstOrDefault();
         if (firstfotofromalbum != null)
         {
             var dir  = Server.MapPath("~/Content/UploadImage");
             var path = Path.Combine(dir, firstfotofromalbum.PathImage);
             return(base.File(path, "image"));
         }
     }
     return(View());
 }
Example #3
0
        public ActionResult DeleteFoto(int IdFoto, int IdAlbum)
        {
            using (mozartdv_34Entities de = new mozartdv_34Entities())
            {
                GalleryFoto gf       = de.GalleryFoto.Where(x => x.Id == IdFoto).First();
                string      fullPath = Request.MapPath("~/Content/UploadImage/" + gf.PathImage);
                if (System.IO.File.Exists(fullPath))
                {
                    System.IO.File.Delete(fullPath);
                    de.GalleryFoto.Remove(gf);
                    de.SaveChanges();
                }
            }

            return(RedirectToAction("EditAlbum/" + IdAlbum, "AdminFoto"));
        }