public async Task <IActionResult> DeletePhoto(int userId, int classifiedAdId, int photoId) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var classfiedAdFromRepo = await _classifiedAdsRepo.GetClassifiedAdDetail(classifiedAdId); if (!classfiedAdFromRepo.Photos.Any(p => p.Id == photoId)) { return(Unauthorized()); } var photoFromRepo = await _classifiedAdsRepo.GetPhoto(photoId); if (photoFromRepo.IsMain) { //return BadRequest("You cannot delete main photo"); return(BadRequest("Не можете да ја бришете главната слика")); } if (photoFromRepo.PublicId != null) { var deleteParams = new DeletionParams(photoFromRepo.PublicId); var result = _cloudinary.Destroy(deleteParams); if (result.Result == "ok") { _classifiedAdsRepo.Delete(photoFromRepo); } } if (photoFromRepo.PublicId == null) { _classifiedAdsRepo.Delete(photoFromRepo); } if (await _classifiedAdsRepo.SaveAll()) { return(Ok()); } //return BadRequest("Failed to delete the photo"); return(BadRequest("Грешка при бришење на сликата")); }
public void Delete(int id) { _repo.Delete(id); }