Exemplo n.º 1
0
        public static void PermanentlyDeleteUser(ProMaUser toDelete)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                foreach (PostedNote currentNote in PostedNoteHandler.GetNotes
                             (shownToUser: toDelete.UserId, includeInactive: true, onlyInactive: false, includeComplete: true, onlyThisNoteId: -1, includeHibernatedNotes: true))
                {
                    PostedNoteHandler.PermanentlyDeleteNote(currentNote);
                }

                foreach (NoteType currentNoteType in NoteTypeHandler.GetNoteTypesForUser(toDelete.UserId))
                {
                    NoteTypeHandler.DeleteNoteType(currentNoteType);
                }

                foreach (SharedChoreMembership currentSharedChoreMembership in SharedChoreMembershipHandler.GetSharedChoreMembershipsForUser(toDelete.UserId))
                {
                    SharedChoreHandler.PermanentlyDeleteSharedChore(currentSharedChoreMembership.SharedChoreId);
                }

                foreach (CalendarEntry currentCalendarEntry in CalendarHandler.GetAllCalendarEntriesForUser(toDelete.UserId))
                {
                    CalendarHandler.DeleteCalendar(currentCalendarEntry.CalendarId);
                }

                scope.ProMaUsers.Remove(toDelete);
                scope.SaveChanges();

                ThisCache.Remove(toDelete);
            }
        }
Exemplo n.º 2
0
        public static List <CompletedChore> GetChoreItemsForDateAndUser(int userId, DateTime day)
        {
            // first, get a list of all tasks this user is a part of
            List <SharedChoreMembership> taskMemberships = SharedChoreMembershipHandler.GetSharedChoreMembershipsForUser(userId).OrderBy(x => x.PersonalSortingOrder).ThenBy(x => x.SharedChoreId).ToList();

            // now, get the items that are for this chore item, on this day
            List <CompletedChore> existingChoreItems = GetChoreItems(taskMemberships.Select(x => x.SharedChoreId).ToList(), day);

            return(existingChoreItems);
        }
Exemplo n.º 3
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.º 4
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.º 5
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.º 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);
            }
        }