public void Edit(Gallery gallery=null, Image image = null, HttpPostedFileBase file=null,int galId=0)
        {
            byte[] newdata = null;
            if (gallery != null)
            {
                if (file != null)
                {
                    gallery.GalleryMimeType = file.ContentType;
                    newdata = new WebImage(file.InputStream).GetBytes();
                    gallery.GalleryData = newdata;
                    db.Entry(gallery).State = System.Data.Entity.EntityState.Modified;
                }
                else {
                    var gal = db.Galleries.Find(gallery.ID);
                    gal.GalleryTitle = gallery.GalleryTitle;
                }

            }
            else
            {
                if (file != null)
                {
                    image.ImageMimeType = file.ContentType;
                    newdata = new WebImage(file.InputStream).GetBytes();
                    image.ImageData =newdata;
                }
                db.Entry(image).State = System.Data.Entity.EntityState.Modified;
            }
            db.SaveChanges();
        }
        public void Create(Gallery gallery = null,HttpPostedFileBase file = null,int galId=0)
        {
            byte[] newdata = null;

            if (gallery != null)
            {
                var gall = new Gallery();
                gall.GalleryMimeType = file.ContentType;
                newdata = new WebImage(file.InputStream).GetBytes(null);
                gall.GalleryTitle = gallery.GalleryTitle;
                gall.GalleryData = newdata;
                this.db.Galleries.Add(gall);
            }
            else {

                Image image2 = new Image();
                string str = Regex.Replace(file.FileName, @"\.\w+", string.Empty);
                image2.ImageTitle = str;
                image2.Sortindex = image2.ID+1;
                image2.GalleryID = galId;
                image2.ImageMimeType = file.ContentType;
                newdata = new WebImage(file.InputStream).GetBytes(null);
                image2.ImageData = newdata;
                this.db.Images.Add(image2);
            }
               db.SaveChanges();
        }
 public void Delete(Gallery gallery = null, Image image = null)
 {
     if (image != null)
     {
         db.Images.Remove(image);
         db.SaveChanges();
     }
     else {
         db.Galleries.Remove(gallery);
         db.SaveChanges();
     }
 }
 public ActionResult Create(Gallery gallery,HttpPostedFileBase file,Image image=null,int galId=0)
 {
     if (gallery == null)
     {
         if (ModelState.IsValid)
         {
             _gRepo.Create(null,file,galId);
             return RedirectToAction("Index");
         }
     }
     else
     {
         if (ModelState.IsValid)
         {
             TempData["message"] = "Галлерея - " + gallery.GalleryTitle + " создана";
             TempData["type"] = 1;
             _gRepo.Create(gallery, file, 0);
             return RedirectToAction("Index");
         }
     }
     return View();
 }
 public ActionResult Edit(Gallery gal,HttpPostedFileBase file=null)
 {
     if(ModelState.IsValid){
         TempData["message"] = "Галлерея - " + gal.GalleryTitle + " отредактированна";
         TempData["type"] = 1;
         _gRepo.Edit(gal,null,file);
     }
     return RedirectToAction("Index");
 }