예제 #1
0
        public async Task IsAbleToRemoveFriendAsync()
        {
            await InsertFriend();

            var count          = GetFriendsList().Count;
            var existingFriend = GetFriendsList()[0];
            var deleteResult   = _sut.Delete(existingFriend.Id);

            Assert.AreEqual(count, GetFriendsList().Count);

            _repositoryStub.Delete(existingFriend);

            Assert.AreEqual(count - 1, GetFriendsList().Count);
        }
예제 #2
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (IsUserAuthorizedAndSelf(userId) == false)
            {
                return(Unauthorized());
            }
            // verify that the photo id (id param) belongs to the user.
            var user = await repo.GetUser(userId);

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

            var photoFromRepo = await repo.GetPhoto(id);

            if (string.IsNullOrWhiteSpace(photoFromRepo.PublicId) == false) /* photo is in Cloudinary */
            {
                var deleteParams   = new DeletionParams(photoFromRepo.PublicId);
                var deletionResult = cloudinary.Destroy(deleteParams);
                if (deletionResult.Result.Equals("ok", StringComparison.InvariantCultureIgnoreCase) == false)
                {
                    return(BadRequest("Fail to delete the selected photo (from Cloudinary)."));
                }
            }
            repo.Delete(photoFromRepo);
            if (await repo.SaveAll())
            {
                return(Ok());
            }
            return(BadRequest("Fail to delete the selected photo."));
        }
예제 #3
0
        public async Task <IActionResult> DeletePhoto(int userId, int id)
        {
            if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value))
            {
                return(Unauthorized("User not authorized"));
            }

            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("Unable to delete main photo"));
            }

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

                var destroyResult = _cloudinary.Destroy(destroyParams);

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

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

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

            return(BadRequest("Unable to delete photo"));
        }
예제 #4
0
        public async Task <IActionResult> DeleteConfirmed(long id)
        {
            var friend = await _repository.Find(id);

            _repository.Delete(friend);
            await _repository.Save();

            return(RedirectToAction(nameof(Index)));
        }
 public ActionResult RemoveFriend(int idLogged, int id)
 {
     try
     {
         repository.Delete(idLogged, id);
         return(Ok(new { success = true }));
     }
     catch (MySqlException ex)
     {
         throw ex;
     }
 }
예제 #6
0
        public async Task UnfriendPlayer(string playerId, string targetPlayerId)
        {
            Player player = await _playerRepository.GetByUsername(targetPlayerId);

            if (player == null)
            {
                throw new EntityNotFoundException();
            }
            PlayerFriend foundFriend = new PlayerFriend(playerId, targetPlayerId);

            foundFriend = await _friendListRepository.GetByUsernames(foundFriend.playerId, foundFriend.friendId);

            if (foundFriend == null)
            {
                throw new FriendNotFoundException();
            }
            await _friendListRepository.Delete(foundFriend);
        }
 private void OnDeleteExecute()
 {
     _repository.Delete(CurrentFriend.Id);
     _eventAggregator.GetEvent <UpdateFriendDetailViewEvent>().Publish();
     CurrentFriend = new Friend();
 }