Exemplo n.º 1
0
        public AddToFriendsResponse AddToFriends(ISession session, AddToFriendsRequest request)
        {
            var response = request.CreateResponse<AddToFriendsResponse>();
            response.Success = true;

            if (session.User.Friends.Any(i => i.Id == request.TargetUserId))
            {
                response.Success = false;
                return response;
            }

            using (var uow = UnitOfWorkFactory.Create())
            {
                uow.Attach(session.User);
                var friend = uow.UsersRepository.FirstMatching(UserSpecification.Id(request.TargetUserId));
                if (friend == null)
                {
                    response.Success = false;
                }
                else
                {
                    session.User.Friends.Add(friend);
                    uow.Commit();
                }
            } 
            return response;
        }
 public Task<AddToFriendsResponse> AddToFriends(AddToFriendsRequest request)
 {
     return ConnectionManager.SendRequestAndWaitResponse<AddToFriendsResponse>(request);
 }