Esempio 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);
        }
Esempio n. 2
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. 3
0
        public List <CompletedChore> GetChoreItems([FromBody] GetChoreItemsRequestObject requestObject)
        {
            ProMaUser user = DataController.LoggedInUser;

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

            DateTime dayForRequest = new DateTime(requestObject.year, requestObject.month, requestObject.day).Date;

            List <CompletedChore> returnThis = CompletedChoreHandler.GetChoreItemsForDateAndUser(user.UserId, dayForRequest);

            // we need to hydrate the data appropriately
            foreach (CompletedChore curChore in returnThis)
            {
                curChore.SharedChore = SharedChoreHandler.GetSharedChore(curChore.SharedChoreId);

                if (curChore.UserId.HasValue)
                {
                    curChore.CompletedUser = ProMaUserHandler.GetUser(curChore.UserId.Value);
                }

                curChore.SharedChore.Membership = SharedChoreMembershipHandler.GetSharedChoreMembership(curChore.SharedChoreId, user.UserId);

                // find the last completed version of this chore
                // we only need to do this if this chore isn't complete, because it won't be displayed in the ui otherwise
                if (!curChore.Completed)
                {
                    CompletedChore lastCompletion = CompletedChoreHandler.GetPreviousCompletedChore(curChore);

                    if (lastCompletion != null)
                    {
                        curChore.LastDoneUser = ProMaUserHandler.GetUser(lastCompletion.UserId.Value);
                        curChore.LastDoneTime = lastCompletion.ChoreDate;
                    }
                }
            }

            return(returnThis.ToList());
        }