Example #1
0
        public async Task <IActionResult> DeletePhoto(Guid userId, Guid id)
        {
            if (userId != Guid.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var user = await _repo.GetUser(userId);

            if (!user.Photos.Any(p => p.Id == id))
            {
                return(Unauthorized());
            }

            var photoFromRepo = await _repo.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")
                {
                    _repo.Delete(photoFromRepo);
                }
            }

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

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

            return(BadRequest("Failed to delete the photo"));
        }
Example #2
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var userFromRepo = await _repo.Delete(id);

            if (userFromRepo)
            {
                return(Ok());
            }
            ;
            throw new Exception($"Updating user {id} failed on delete");
        }
 public void Delete(int id)
 {
     _projectManagementRepository.Delete(id);
 }