コード例 #1
0
        public async Task <IActionResult> DeletePhoto(int id)
        {
            var photoFromRepo = await _repo.GetPhoto(id);

            if (photoFromRepo == null)
            {
                return(NotFound("Photo not found"));
            }

            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("Error during photo deletion"));
        }
コード例 #2
0
 /// <summary>
 /// Удалить сущность
 /// </summary>
 /// <param name="entity"></param>
 public void Delete(T entity)
 {
     using (var transaction = PersistenceContext.CurrentSession.BeginTransaction())
     {
         Repository.Delete(entity);
         transaction.Commit();
     }
 }
コード例 #3
0
        public async Task <IActionResult> DeleteUser(int id)
        {
            if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized());
            }

            var userFromRepo = await _repo.GetUser(id);

            _repo.Delete(userFromRepo);

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

            return(BadRequest("Error during user deletion"));
        }
コード例 #4
0
        public async Task <IActionResult> DeleteHouse(int userId, int id)
        {
            // if(userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            //     return Unauthorized();

            var houseFromRepo = await _repo.GetHouse(id);

            if (houseFromRepo == null)
            {
                return(NotFound("House not found!"));
            }

            _repo.Delete(houseFromRepo);

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

            throw new Exception("Error during house deletion");
        }