Ejemplo n.º 1
0
        public ActionResult EditPhotoMainPage(PhotoMainPage photoMain, HttpPostedFileBase image)
        {
            if (ModelState.IsValid)
            {
                if (image != null && image.ContentLength > 0)
                {
                    var imgName = Path.GetFileName(image.FileName);
                    var path    = Path.Combine(Server.MapPath("~/Content/CarouselImages/"), System.IO.Path.GetFileName(image.FileName));
                    image.SaveAs(path);
                    photoMain.PhotoMain = "~/Content/CarouselImages/" + imgName;
                    _repository.SavePhotoMainPage(photoMain);
                }
                else if (photoMain.PhotoMainID != 0)
                {
                    photoMain = _repository.PhotosMainPage.FirstOrDefault(f => f.PhotoMainID == photoMain.PhotoMainID);

                    string fullPath = Request.MapPath(photoMain.PhotoMain); //delete from server
                    if (System.IO.File.Exists(fullPath))
                    {
                        System.IO.File.Delete(fullPath);
                    }
                    _repository.DeletePhotoMainPage(photoMain);
                }
            }
            return(RedirectToAction("Index", "Admin"));
        }
Ejemplo n.º 2
0
 public void SavePhotoMainPage(PhotoMainPage photosMainPage)
 {
     if (photosMainPage.PhotoMainID == 0)
     {
         context.PhotosMainPage.Add(photosMainPage);
     }
     else
     {
         context.Entry(photosMainPage).State = EntityState.Modified;
     }
     context.SaveChanges();
 }
Ejemplo n.º 3
0
 public void DeletePhotoMainPage(PhotoMainPage photosMainPage)
 {
     context.Entry(photosMainPage).State = EntityState.Deleted;
     context.SaveChanges();
 }