Exemplo n.º 1
0
        public IActionResult Follow(int userId)
        {
            if (userId <= 0)
            {
                return(BadRequest($"{nameof(userId)} must be lower than 1"));
            }
            if (userId.Equals(User.GetId()))
            {
                return(BadRequest($"You can't follow yourself"));
            }
            if (_followerService.TryFindByUserAndFollowsId(User.GetId(), userId, out var newFollower))
            {
                return(BadRequest($"{userId} is allready being followed"));
            }
            var follower = new Follower
            {
                Date      = DateTime.Now,
                UserId    = User.GetId(),
                FollowsId = userId
            };

            _followerService.Insert(follower);
            _unitOfWork.SaveChanges();

            return(Ok());
        }
 public void TryFindByUserAndFollowsIdShouldThrowArgumentExceptionForUserIdTest()
 {
     _followerService.TryFindByUserAndFollowsId(0, 1, out var follower);
     Assert.Fail();
 }