Esempio n. 1
0
        public List <FriendshipRequest> GetFriendshipRequests()
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            List <FriendshipRequest> requests = FriendshipRequestHandler.GetRequestsForUser(user.UserId).Where(x => x.RecipientId == user.UserId || x.SenderId == user.UserId).ToList();

            requests.ForEach(x => { x.Sender = ProMaUserHandler.GetUser(x.SenderId); x.Recipient = ProMaUserHandler.GetUser(x.RecipientId); });

            return(requests);
        }
Esempio n. 2
0
        public List <ProMaUser> UsersForFriendRequest([FromForm] string name)
        {
            ProMaUser user = DataController.LoggedInUser;

            if (user == null)
            {
                throw new NotLoggedInException();
            }

            if (name == null)
            {
                name = String.Empty;
            }

            List <ProMaUser> fittingUsers = ProMaUserHandler.GetAllUsers().Where(x => x.UserName.ToLower().Contains(name.ToLower()) && x.UserId != user.UserId).ToList();

            fittingUsers = fittingUsers.Where(x => x.UserName != "DemoAccount").ToList();

            List <ProMaUser> returnThis = new List <ProMaUser>();

            List <FriendshipRequest> excludeBecauseRequested      = FriendshipRequestHandler.GetRequestsForUser(user.UserId);
            List <ProMaUser>         excludeBecauseAlreadyFriends = FriendshipHandler.GetUserFriends(user.UserId);

            fittingUsers.ForEach(x =>
            {
                if (!excludeBecauseRequested.Any(y => y.SenderId == x.UserId) && !excludeBecauseRequested.Any(y => y.RecipientId == x.UserId))
                {
                    if (!excludeBecauseAlreadyFriends.Any(y => y.UserId == x.UserId))
                    {
                        returnThis.Add(x);
                    }
                }
            });

            return(returnThis);
        }