public ActionResult DeletePhoto(string PhotoId = "", string AlbumId = "") { try { int _photoId; int _albumId; PhotoInfo _photoInfo = null; AlbumInfo _albumInfo = null; if (!int.TryParse(PhotoId, out _photoId) || !int.TryParse(AlbumId, out _albumId)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (AlbumRepository Repo = new AlbumRepository()) { _albumInfo = Repo.GetAlbumById(_albumId); } if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Album does not exist."); return(RedirectToAction("Manage", "Gallery")); } using (PhotoRepository Repo = new PhotoRepository()) { _photoInfo = Repo.GetPhotoById(_photoId); if (_photoInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Photo does not exist."); return(RedirectToAction("Manage", "Gallery")); } string fullPath = Request.MapPath(_photoInfo.Path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } Repo.DeletePhoto(_photoId); TempData["Msg"] = AlertMessageProvider.SuccessMessage("Photos deleted successfully."); return(RedirectToAction("UploadPhotos", "Gallery", new { id = AlbumId })); } } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "DeletePhoto"))); } }
public ActionResult DeletePhoto(Guid id, Photo photo) { var phot = photorepo.GetPhoto(id); string fullpath = Request.MapPath("~/images/" + phot.PhotoName); if (System.IO.File.Exists(fullpath)) { System.IO.File.Delete(fullpath); photorepo.DeletePhoto(phot); } return(RedirectToAction("Index", photorepo.GetPhotos().Select(x => PhotoModelMapping.ModelToEntity(x)).ToList())); }
public async Task DeletePhoto(long id) { var photo = await _photoRepository.ReadPhoto(id); var photos = (await _photoRepository.ReadPhotos(photo.ParentFolderId)).OrderBy(f => f.Order).ToList(); await _photoRepository.DeletePhoto(id); File.Delete(photo.PhysicalPath); for (var i = photo.Order + 1; i < photos.Count; ++i) { await _photoRepository.UpdatePhotoOrder(photos[i].Id, i - 1); } }
public ActionResult PhotoDeletePartial(int Id) { photoRepo.DeletePhoto(Id); #region notused //using (PhotoExplorerEntities cx = new PhotoExplorerEntities()) //{ // //delete photo with mathcing id // cx.Photos.Remove(cx.Photos.FirstOrDefault(p => p.Id == Id)); // cx.SaveChanges(); //} #endregion return(RedirectToAction("Index")); }
public ActionResult DeletePicture(Guid id, Photo photo) { var p = photoRepo.GetPhoto(id); //var p = PhotoModelMapper.ModelToEntity(photodelete); //var p = photos.FirstOrDefault(x => x.PhotoID == id); string fullPath = Request.MapPath("~/Image/" + p.PhotoName); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); //Session["DeleteSuccess"] = "Yes"; //photos.Remove(p); photoRepo.DeletePhoto(p); } return(RedirectToAction("Index", photoRepo.GetAllPhoto().Select(x => PhotoModelMapper.ModelToEntity(x)).ToList())); }
public ActionResult DeletePhoto(Guid photoId) { var photo = Dal.GetPhotoById(photoId); string absolutePath = HttpContext.Server.MapPath((photo.PhotoUrl)); if (System.IO.File.Exists(absolutePath)) { Dal.DeletePhoto(photo.PhotoId); System.IO.File.Delete(absolutePath); return(RedirectToAction("Index", "Gallery")); } return(RedirectToAction("Index", "Gallery")); }
public HomeViewModel() { Title = "Home"; photoRepository = new PhotoRepository(); Photos = photoRepository.Photos; MessagingCenter.Subscribe <PhotoDetailsPage, Photo>(this, Constants.EDIT_PHOTO, async(obj, photo) => { var editPhoto = photo; var oldPhoto = Photos.Where((Photo arg) => arg.Id == photo.Id).FirstOrDefault(); oldPhoto = editPhoto; photoRepository.UpdatePhoto(editPhoto); }); MessagingCenter.Subscribe <PhotoDetailsPage, Photo>(this, Constants.DELETE_PHOTO, async(obj, photo) => { Photos.Remove(photo); photoRepository.DeletePhoto(photo); }); MessagingCenter.Subscribe <AddNewPhotoPage, Photo>(this, Constants.ADD_NEW_PHOTO, async(obj, photo) => { Photos.Insert(0, photo); Photo newPhoto = new Photo { AlbumId = 5, Id = photo.Id, Title = photo.Title, Url = photo.Url, ThumbnailUrl = photo.ThumbnailUrl }; photoRepository.AddPhoto(newPhoto); }); }
public ActionResult DeleteAlbum(string AlbumId = "") { try { var _photos = new List <PhotoInfo>(); int _albumId; AlbumInfo _albumInfo = null; if (!int.TryParse(AlbumId, out _albumId)) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (var transaction = new System.Transactions.TransactionScope()) { using (AlbumRepository AlbumRepo = new AlbumRepository()) { _albumInfo = AlbumRepo.GetAlbumById(_albumId); if (_albumInfo == null) { TempData["Msg"] = AlertMessageProvider.FailureMessage("Something went wrong, please try again later."); return(RedirectToAction("Manage", "Gallery")); } using (PhotoRepository PhotoRepo = new PhotoRepository()) { _photos = PhotoRepo.GetPhotoListByAlbumId(_albumId); foreach (var item in _photos) { string fullPath = Request.MapPath(item.Path); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } PhotoRepo.DeletePhoto(item.Id); } } string _imgPath = Server.MapPath(_albumInfo.CoverPhotoPath); if (!_imgPath.Contains("default-album-cover.jpg")) { if (System.IO.File.Exists(_imgPath)) { System.IO.File.Delete(_imgPath); } } AlbumRepo.DeleteAlbum(_albumId); } transaction.Complete(); } TempData["Msg"] = AlertMessageProvider.SuccessMessage("Album deleted successfully."); return(RedirectToAction("Manage", "Gallery")); } catch (Exception ex) { return(View("Error", new HandleErrorInfo(ex, "Gallery", "DeleteAlbum"))); } }
internal int DeletePhoto(int id) { return(photoRepository.DeletePhoto(id)); }
public void DeletePhoto(Photo photo) { PhotoRepository.DeletePhoto(photo); }
public IActionResult Delete(PhotoViewModel viewModel) { repository.DeletePhoto(viewModel.Id); return(RedirectToAction("Index")); }