Пример #1
0
        public async Task <IActionResult> DeletePhoto(int imovelId, int id)
        {
            // if (imovelId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            // return Unauthorized();

            var imovel = await _repo.GetImovel(imovelId);

            if (!imovel.Fotos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }
            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo.Principal)
            {
                return(BadRequest("Foto principal não pode ser apagada!"));
            }

            if (photoFromRepo.Principal != null)
            {
                var deleteParams = new DeletionParams(photoFromRepo.PublicId);

                var result = _cloudinary.Destroy(deleteParams);

                if (result.Result == "ok")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

            if (photoFromRepo.PublicId == null)
            {
                _repo.Delete(photoFromRepo);
            }

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Falha ao deletar a foto!"));
        }
Пример #2
0
        public async Task <IActionResult> DeleteImovel(int id)
        {
            // if (imovelId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            // return Unauthorized();

            var imovelFromRepo = await _repo.GetImovel(id);

            _repo.Delete(imovelFromRepo);

            if (await _repo.SaveAll())
            {
                return(Ok());
            }

            return(BadRequest("Falha ao deletar o imóvel!"));
        }