public async Task Delete(Guid userId, Guid photoId) { var photoDB = await _photosRepository.GetById(photoId); if (photoDB == null) { throw new ArgumentException("Photo not found"); } if (photoDB.UserId != userId) { throw new ArgumentException("Photo doesn't belong to user"); } await Task.WhenAll(_photosRepository.Delete(photoDB), _feedService.DeletePhotoFromFeed(userId, photoDB)); }
public ActionResult DeletePhoto(int photoId) { bool res = false; string message = string.Empty; Photo photo = _photoRepository.GetById(photoId); Announcement announcement = photo.Announcement; User owner = photo.Owner; User authenticatedUser = _userRepository.GetUserByPhone(User.Identity.Name); if (authenticatedUser == photo.Owner) { deletePhoto(photo.Url); _photoRepository.Delete(photo); _photoRepository.SaveChanges(); res = true; } if (announcement.Photos.Count < owner.Profile.MaxPhotosPerAnnouncements) { message = string.Format(Translation.Translation.PhotosLeft, owner.Profile.MaxPhotosPerAnnouncements - announcement.Photos.Count); } else { message = string.Format(Translation.Translation.LimitForPhotosIsReachedLabel, "/"); } return(Json(new { Done = res, Message = message }, "text/json")); }
public Photo GetById(int id, string waterMarkText = null) { if (string.IsNullOrEmpty(waterMarkText)) { waterMarkText = ApplicationSettings.Instance.AppSettings.ApplicationName; } Photo photo = _photosRepository.GetById(id); if (photo == null) { return(null); } if (photo.WaterMarked == null) { photo = ApplyWaterMark(photo, waterMarkText); } return(photo); }
public async Task DeleteOnMyPhoto(Guid userId, Guid commentId) { var commentDB = await _commentsRepository.GetById(commentId); if (commentDB == null) { throw new ArgumentException("Comment not found"); } var photo = await _photosRepository.GetById(commentDB.PhotoId); if (photo == null) { throw new ArgumentException("Photo not found"); } if (photo.UserId != userId) { throw new ArgumentException("Photo doesn't belong to user"); } await _commentsRepository.Delete(commentDB); }