public async Task <IActionResult> DeletePhoto(int userId, int id) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var user = await _repository.GetUser(userId); if (!user.Photos.Any(p => p.Id == id)) { return(Unauthorized()); } var photoFromRepo = await _repository.GetPhoto(id); if (photoFromRepo.IsMain) { return(BadRequest("You cannot delete your main photo")); } if (photoFromRepo.PublicId != null) { var deleteParams = new DeletionParams(photoFromRepo.PublicId); var result = _cloudinary.Destroy(deleteParams); if (result.Result == "ok") { _repository.Delete(photoFromRepo); } } if (photoFromRepo.PublicId == null) { _repository.Delete(photoFromRepo); } if (await _repository.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete the photo")); }
public async Task <IActionResult> DeleteActivity(int userId, int id) { // if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) // return Unauthorized(); var user = await _repository.GetUser(userId); var activityFromRepo = await _repository.GetActivity(id); _repository.Delete(activityFromRepo); if (await _repository.SaveAll()) { return(Ok()); } return(BadRequest("Failed to delete the activity")); }