예제 #1
0
        public List <ProMaUser> GetFriends()
        {
            ProMaUser user = LoggedInUser;

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

            return(FriendshipHandler.GetUserFriends(user.UserId));
        }
예제 #2
0
        public List <ProMaUser> GetUsersNotAssignedToChore([FromForm] int choreId)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                ProMaUser user = DataController.LoggedInUser;

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

                // get each shared chore membership for this chore
                List <SharedChoreMembership> memberships = SharedChoreMembershipHandler.GetSharedChoreMembershipsForChore(choreId);

                return(FriendshipHandler.GetUserFriends(user.UserId).Where(x => !memberships.Any(y => y.UserId == x.UserId)).ToList());
            }
        }
예제 #3
0
        public void AssignUserToChore([FromBody] AssignUserToChoreRequestObject requestObject)
        {
            ProMaUser user = DataController.LoggedInUser;

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

            if (FriendshipHandler.GetUserFriends(user.UserId).Any(x => x.UserId == requestObject.userId))
            {
                SharedChoreMembershipHandler.AddSharedChoreMembership(requestObject.choreId, requestObject.userId);
            }
            else
            {
                throw new Exception("User not in friends list");
            }
        }
예제 #4
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);
        }