Exemplo n.º 1
0
        public void SendFriendRequest([FromForm] int toUser)
        {
            ProMaUser user = DataController.LoggedInUser;

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

            if (user.IsDemo)
            {
                throw new Exception("Can't send friend requests as the Demo account");
            }

            ProMaUser target = ProMaUserHandler.GetUser(toUser);

            if (target == null)
            {
                throw new Exception("No user with that ID exists");
            }

            if (target.IsDemo)
            {
                throw new Exception("Can't send friend requests to the Demo account");
            }

            FriendshipRequest newRequest = new FriendshipRequest();

            newRequest.SenderId    = user.UserId;
            newRequest.RecipientId = toUser;

            FriendshipRequestHandler.AddFriendshipRequest(newRequest);
        }
Exemplo n.º 2
0
        public void ResetCaches()
        {
            ProMaUser user = DataController.LoggedInUser;

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

            if (!user.IsAdmin)
            {
                throw new AdminAccessRequiredException();
            }

            lock (ProMaUserHandler.ThisCache)
            {
                ProMaUserHandler.ThisCache = null;
            }
            lock (NoteTypeHandler.ThisCache)
            {
                NoteTypeHandler.ThisCache = null;
            }

            CompletedChoreHandler.AddToEveryUserChoreCacheIterator();
            FriendshipRequestHandler.AddToEveryUserFriendshipCacheIterator();
        }
Exemplo n.º 3
0
        public void CancelFriendRequest([FromForm] int recipient)
        {
            ProMaUser user = DataController.LoggedInUser;

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

            FriendshipRequestHandler.RejectRequestBetweenUsers(recipient, user.UserId);
        }
Exemplo n.º 4
0
        public void RejectFriendRequest([FromForm] int fromUser)
        {
            ProMaUser user = DataController.LoggedInUser;

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

            FriendshipRequestHandler.RejectRequestBetweenUsers(user.UserId, fromUser);
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        public async Task LongPoll(int userId, int friendshipCacheVersion, int choreCacheVersion)
        {
            int newFriendshipCacheVersion = friendshipCacheVersion;
            int newChoreCacheVersion      = choreCacheVersion;

            do
            {
                await Task.Delay(100);

                newFriendshipCacheVersion = FriendshipRequestHandler.LongPollInternal(userId);
                newChoreCacheVersion      = CompletedChoreHandler.LongPollInternal(userId);
            } while
            (
                friendshipCacheVersion == newFriendshipCacheVersion &&
                choreCacheVersion == newChoreCacheVersion
            );

            await Clients.Caller.SendAsync("LongPollPop", newChoreCacheVersion, newFriendshipCacheVersion);
        }
Exemplo n.º 7
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);
        }