Exemplo n.º 1
0
        public static void RemoveSharedChoreMembership(int sharedChoreId, int userId)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                SharedChoreMembership membership = scope.SharedChoreMemberships.FirstOrDefault(x => x.SharedChoreId == sharedChoreId && x.UserId == userId);
                scope.SharedChoreMemberships.Remove(membership);
                scope.SaveChanges();

                // while this may affect other users, we only care that it was removed from this user
                CompletedChoreHandler.AddToUserChoreCacheIterator(userId);
            }
        }
Exemplo n.º 2
0
        public static void AddSharedChore(SharedChore toAdd, int seedUserId)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                scope.SharedChores.Add(toAdd);
                scope.Entry(toAdd).State = EntityState.Added;
                scope.SaveChanges();
            }

            SharedChoreMembershipHandler.AddSharedChoreMembership(toAdd.SharedChoreId, seedUserId);

            // we just added the chore, so the only possible user on it is the logged in user
            CompletedChoreHandler.AddToUserChoreCacheIterator(seedUserId);
        }
Exemplo n.º 3
0
        public static void UnCompleteChore(int sharedChoreId, DateTime forDay)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                CompletedChore toRemove = scope.CompletedChores.FirstOrDefault(x => x.SharedChoreId == sharedChoreId && x.ChoreDate == forDay);
                scope.CompletedChores.Remove(toRemove);
                scope.SaveChanges();
            }

            // change the cache for each user in this membership
            List <SharedChoreMembership> memberships = SharedChoreMembershipHandler.GetSharedChoreMembershipsForChore(sharedChoreId);

            foreach (SharedChoreMembership curMembership in memberships)
            {
                CompletedChoreHandler.AddToUserChoreCacheIterator(curMembership.UserId);
            }
        }
Exemplo n.º 4
0
        public static void PermanentlyDeleteSharedChore(int sharedChoreId)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                SharedChore sharedChore = SharedChoreHandler.GetSharedChore(sharedChoreId);

                foreach (CompletedChore currentCompletedChore in CompletedChoreHandler.GetAllCompletedChoreItems(sharedChore.SharedChoreId))
                {
                    CompletedChoreHandler.UnCompleteChore(sharedChore.SharedChoreId, currentCompletedChore.ChoreDate);
                }

                foreach (SharedChoreMembership currentSharedChoreMembership in SharedChoreMembershipHandler.GetSharedChoreMembershipsForChore(sharedChoreId))
                {
                    SharedChoreMembershipHandler.RemoveSharedChoreMembership(sharedChoreId, currentSharedChoreMembership.UserId);
                }

                scope.Remove(sharedChore);
                scope.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public static void AddSharedChoreMembership(int choreId, int userId)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                List <SharedChoreMembership> maximumSharedChoreOrdering = GetSharedChoreMembershipsForUser(userId);

                int orderForChore = 0;

                if (maximumSharedChoreOrdering.Count > 0)
                {
                    orderForChore = maximumSharedChoreOrdering.Max(x => x.PersonalSortingOrder) + 1;
                }

                SharedChoreMembership newMembership = new SharedChoreMembership();
                newMembership.UserId               = userId;
                newMembership.SharedChoreId        = choreId;
                newMembership.PersonalSortingOrder = orderForChore;
                scope.SharedChoreMemberships.Add(newMembership);
                scope.SaveChanges();
            }

            CompletedChoreHandler.AddToUserChoreCacheIterator(userId);
        }
Exemplo n.º 6
0
        public static void CompleteChore(int sharedChoreId, DateTime forDay, int userId)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                CompletedChore newChore = new CompletedChore();
                newChore.SharedChoreId = sharedChoreId;
                newChore.ChoreDate     = forDay;
                newChore.Completed     = true;
                newChore.UserId        = userId;
                newChore.PostedTime    = ProMaUser.NowTime();

                scope.CompletedChores.Add(newChore);

                scope.SaveChanges();
            }

            // change the cache for each user in this membership
            List <SharedChoreMembership> memberships = SharedChoreMembershipHandler.GetSharedChoreMembershipsForChore(sharedChoreId);

            foreach (SharedChoreMembership curMembership in memberships)
            {
                CompletedChoreHandler.AddToUserChoreCacheIterator(curMembership.UserId);
            }
        }