Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
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);
        }
Ejemplo 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());
        }
Ejemplo n.º 4
0
        public void ChangeChoreItemCompletion([FromBody] ChangeChoreItemCompletionRequestObject requestObject)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                ProMaUser user = DataController.LoggedInUser;

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

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

                if (requestObject.completed)
                {
                    CompletedChoreHandler.CompleteChore(requestObject.choreId, dayForRequest, user.UserId);
                }
                else
                {
                    CompletedChoreHandler.UnCompleteChore(requestObject.choreId, dayForRequest);
                }
            }
        }