public async Task <ActionResult> DeletePhoto(int photoId) { var user = await _unitOfWork.UserRepository.GetUserByPhotoId(photoId); var photo = user.Photos.FirstOrDefault(x => x.Id == photoId); if (photo == null) { return(NotFound()); } if (photo.IsMain) { return(BadRequest("You cannot delete your main photo")); } if (photo.PublicId != null) { var results = await _photoService.DeletePhotoAsync(photo.PublicId); if (results.Error != null) { return(BadRequest(results.Error.Message)); } } user.Photos.Remove(photo); if (await _unitOfWork.Complete()) { return(Ok()); } return(BadRequest("Faield to delete the photos")); }
public async Task <ActionResult> DeletePhoto(int photoId) { var user = await _userRepository.GetUserByUserameAsync(User.GetUsername()); var photo = user.Photos.FirstOrDefault(x => x.Id == photoId); if (photo == null) { return(NotFound()); } if (photo.IsMain) { return(BadRequest("You cannot delete your main photo")); } if (photo.PublicId != null) { var result = await _photoService.DeletePhotoAsync(photo.PublicId); if (result.Error != null) { return(BadRequest(result.Error.Message)); } } user.Photos.Remove(photo); if (await _userRepository.SaveAllAsync()) { return(Ok()); } return(BadRequest("Failed to delete photo")); }
public async Task <ActionResult> RejectPhoto(int id) { var photo = await _unitOfWork.PhotoRepository.GetPhotoById(id); if (photo.PublicId != null) { var result = await _photoService.DeletePhotoAsync(photo.PublicId); if (result.Result == "ok") { _unitOfWork.PhotoRepository.DeletePhoto(photo); } } else { _unitOfWork.PhotoRepository.DeletePhoto(photo); } return(Ok()); }