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());
        }
Exemplo n.º 2
0
        public async Task GetFollowingTest()
        {
            var following = await _userService.GetFollowing(user1.Id);

            Assert.AreEqual(0, following.Count);

            _followerService.Insert(new Follower
            {
                User      = user1,
                UserId    = user1.Id,
                Follows   = user2,
                FollowsId = user2.Id
            });
            await _unitOfWork.SaveChangesAsync();

            following = await _userService.GetFollowing(user1.Id);

            Assert.IsTrue(following.Contains(user2));
        }
        public async Task TryFindByUserAndFollowsIdGoodFlowTest()
        {
            _followerService.Insert(new Follower
            {
                User      = user1,
                UserId    = user1.Id,
                Follows   = user2,
                FollowsId = user2.Id
            });
            await _unitOfWork.SaveChangesAsync();

            var value = _followerService.TryFindByUserAndFollowsId(user1.Id, user2.Id, out var follower);

            Assert.IsTrue(value);
        }
Exemplo n.º 4
0
        public async Task GetTimeLineForUserIdAsyncForOwnAndFollowingKweetsTest()
        {
            _followerService.Insert(
                new Follower
            {
                Id        = 1,
                Date      = new DateTime(2018, 3, 6),
                User      = user1,
                UserId    = user1.Id,
                Follows   = user2,
                FollowsId = user2.Id
            });

            await _unitOfWork.SaveChangesAsync();

            var kweets = await _kweetService.GetTimeLineForUserIdAsync(1, 0, 10);

            Assert.AreEqual(5, kweets.Count);
        }
        public HttpResponseMessage InsertCurrentByHandle(string handle, FollowerRequest data)
        {
            BaseResponse response = null;

            try
            {
                if (ModelState.IsValid)
                {
                    IdentityUser user       = _userService.GetCurrentUser();
                    Account      followedLG = _accountSrv.GetAccountByHandle(handle);
                    if (followedLG != null)
                    {
                        FollowNewsletter nwsInfo = new FollowNewsletter();
                        nwsInfo.Email   = user.Email;
                        nwsInfo.Handle  = handle;
                        data.FollowerID = user.Id;
                        data.ProfileUID = followedLG.UserId;


                        _followerSevice.Insert(data, nwsInfo);
                        response = new SuccessResponse();
                        return(Request.CreateResponse(HttpStatusCode.OK, response));
                    }
                    else
                    {
                        throw new Exception("Account does not exist");
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, ModelState));
                }
            }
            catch (Exception ex)
            {
                response = new ErrorResponse(ex.Message);
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, response));
            }
        }