public async Task <IActionResult> AcceptRequest(string friendUsername)
        {
            string username = User.Identity.Name;

            if (username.ToLower() == friendUsername.ToLower())
            {
                return(BadRequest(new { Message = "Invalid username supplied" }));
            }
            try
            {
                var ret = await service.AcceptRequest(username, friendUsername);

                if (ret.Success)
                {
                    return(Ok(mapper.Map <UserResource>(ret.Resource)));
                }
                else
                {
                    return(BadRequest(new { Message = ret.Message }));
                }
            }
            catch
            {
                return(StatusCode(500));
            }
        }
Example #2
0
        public void AcceptRequest_FromOneToOtherUser_RequestAccepted()
        {
            var requestId  = 1;
            var fromUserId = 1;
            var toUserId   = 2;

            _mockUnitOfWork.Setup(m => m.Requests.GetById(requestId)).Returns(new Request()
            {
                Id = requestId, FromUserId = fromUserId, ToUserId = toUserId
            });
            _mockUnitOfWork.Setup(m => m.Users.GetById(fromUserId)).Returns(new AppUser()
            {
                Id = fromUserId
            });
            _mockUnitOfWork.Setup(m => m.Users.GetById(toUserId)).Returns(new AppUser()
            {
                Id = toUserId
            });

            _friendService.AcceptRequest(requestId);

            _mockUnitOfWork.Verify(m => m.Requests.Delete(It.Is <Request>(m => m.Id == 1)), Times.Once());
            _mockUnitOfWork.Verify(m => m.Save(), Times.Once());
        }
 public IActionResult AcceptRequest(int id)
 {
     _friendRequestService.AcceptRequest(id);
     return(Ok());
 }