Пример #1
0
        public static void DeleteNoteType(NoteType toDelete)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                foreach (PostedNote curNote in PostedNoteHandler.GetAllNotesOfType(toDelete.NoteTypeId))
                {
                    PostedNote updateThis = PostedNoteHandler.GetNote(curNote.NoteId);
                    updateThis.NoteTypeId = null;
                    updateThis.Active     = false;
                    PostedNoteHandler.UpdatePostedNote(updateThis);
                }

                foreach (NoteTypeMembership membership in NoteTypeMembershipHandler.GetMembershipsForType(toDelete.NoteTypeId))
                {
                    NoteTypeMembershipHandler.RemoveNoteTypeMembership(membership);
                }

                scope.NoteTypes.Attach(toDelete);
                scope.NoteTypes.Remove(toDelete);

                scope.SaveChanges();

                ThisCache.Remove(toDelete);
            }
        }
Пример #2
0
 public static List <CalendarEntry> GetAllCalendarEntriesForUser(int userId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.CalendarEntries.Where(x => x.UserId == userId).ToList());
     }
 }
Пример #3
0
 public static List <FriendshipRequest> GetRequestsForUser(int userId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.FriendshipRequests.Where(x => x.RecipientId == userId || x.SenderId == userId).ToList());
     }
 }
Пример #4
0
 public static List <PostedNote> GetAllNotesOfType(int noteTypeId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.PostedNotes.Where(x => x.NoteTypeId == noteTypeId).ToList());
     }
 }
Пример #5
0
 public static NoteTypeMembership GetMembership(int userId, int typeId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.NoteTypeMemberships.FirstOrDefault(x => x.UserId == userId && x.NoteTypeId == typeId));
     }
 }
Пример #6
0
 public static PostedNote GetNote(int noteId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.PostedNotes.FirstOrDefault(x => x.NoteId == noteId));
     }
 }
Пример #7
0
 public static List <CompletedChore> GetAllCompletedChoreItems(int sharedChoreId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.CompletedChores.Where(x => x.SharedChoreId == sharedChoreId).ToList());
     }
 }
Пример #8
0
 public static SharedChore GetSharedChore(int sharedChoreId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.SharedChores.FirstOrDefault(x => x.SharedChoreId == sharedChoreId));
     }
 }
Пример #9
0
 public static CalendarEntry GetEntry(int calendarId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.CalendarEntries.First(x => x.CalendarId == calendarId));
     }
 }
Пример #10
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);
            }
        }
Пример #11
0
 public static SharedChoreMembership GetSharedChoreMembership(int choreId, int userId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.SharedChoreMemberships.FirstOrDefault(x => x.SharedChoreId == choreId && x.UserId == userId));
     }
 }
Пример #12
0
 public static List <SharedChoreMembership> GetSharedChoreMembershipsForUser(int userId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.SharedChoreMemberships.Where(x => x.UserId == userId).ToList());
     }
 }
Пример #13
0
 public static CompletedChore GetPreviousCompletedChore(CompletedChore beforeThis)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.CompletedChores.Where(x => x.SharedChoreId == beforeThis.SharedChoreId && x.ChoreDate < beforeThis.ChoreDate && x.Completed).OrderByDescending(x => x.ChoreDate).FirstOrDefault());
     }
 }
Пример #14
0
        public static List <CalendarEntry> GetCalendarEntriesForUser(int userId, int utcOffset)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                List <CalendarEntry> toReturn = scope.CalendarEntries.Where(x => x.UserId == userId).ToList();

                // first, remove elements that are NOT yearly if they already happened
                // we don't care about the particular time, just the date
                DateTime todaysDate = ProMaUser.NowTime(utcOffset).Date;
                toReturn = toReturn.Where(x => x.Yearly || x.ForDate.Date >= todaysDate).ToList();

                // anything that's left that has a date before today needs to have years added to it until it's correct
                // the year for Yearly reoccuring is this year if we haven't passed that month and day yet, and it's next year if it has
                toReturn.ForEach(x => {
                    if (x.Yearly)
                    {
                        int targetYearDifference = todaysDate.Year - x.ForDate.Year;

                        // it already passed, add a year
                        if (x.ForDate.Month < todaysDate.Month || (x.ForDate.Month == todaysDate.Month && x.ForDate.Day < todaysDate.Day))
                        {
                            targetYearDifference++;
                        }

                        x.ForDate = x.ForDate.AddYears(targetYearDifference);
                    }
                });


                // then sort by year, month, day
                toReturn = toReturn.OrderBy(x => x.ForDate.Year).ThenBy(x => x.ForDate.Month).ThenBy(x => x.ForDate.Day).ToList();

                return(toReturn);
            }
        }
Пример #15
0
        private static List <CompletedChore> GetChoreItems(List <int> sharedChoreIds, DateTime day)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                List <CompletedChore> completedChores = scope.CompletedChores.Where(x => sharedChoreIds.Contains(x.SharedChoreId) && x.ChoreDate == day).ToList();

                foreach (int curId in sharedChoreIds)
                {
                    if (!completedChores.Any(x => x.SharedChoreId == curId))
                    {
                        // if the item doesn't exist, we want to create it
                        CompletedChore newItem = new CompletedChore();
                        newItem.SharedChoreId = curId;
                        newItem.ChoreDate     = day;
                        completedChores.Add(newItem);
                    }
                }

                List <CompletedChore> returnThis = new List <CompletedChore>();

                foreach (int curId in sharedChoreIds)
                {
                    returnThis.Add(completedChores.First(x => curId == x.SharedChoreId));
                }

                return(returnThis);
            }
        }
Пример #16
0
 public static List <NoteTypeMembership> GetMembershipsForType(int typeId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.NoteTypeMemberships.Where(x => x.NoteTypeId == typeId).ToList());
     }
 }
Пример #17
0
 public static void AddCalendar(CalendarEntry toAdd)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.CalendarEntries.Add(toAdd);
         scope.SaveChanges();
     }
 }
Пример #18
0
 public static void PermanentlyDeleteNote(PostedNote toDelete)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.PostedNotes.Remove(toDelete);
         scope.SaveChanges();
     }
 }
Пример #19
0
 public static void UpdateSharedChoreMembership(SharedChoreMembership toUpdate)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.SharedChoreMemberships.Attach(toUpdate);
         scope.Entry(toUpdate).State = EntityState.Modified;
         scope.SaveChanges();
     }
 }
Пример #20
0
 public static void AddPostedNote(PostedNote toAdd)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.PostedNotes.Add(toAdd);
         scope.Entry(toAdd).State = EntityState.Added;
         scope.SaveChanges();
     }
 }
Пример #21
0
 public static void AddFriendship(Friendship toAdd)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.Friendships.Add(toAdd);
         scope.Entry(toAdd).State = EntityState.Added;
         scope.SaveChanges();
     }
 }
Пример #22
0
 public static void RemoveNoteTypeMembership(NoteTypeMembership toRemove)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.NoteTypeMemberships.Attach(toRemove);
         scope.NoteTypeMemberships.Remove(toRemove);
         scope.SaveChanges();
     }
 }
Пример #23
0
 public static void UpdatePostedNote(PostedNote toUpdate)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.PostedNotes.Attach(toUpdate);
         scope.Entry(toUpdate).State = EntityState.Modified;
         scope.SaveChanges();
     }
 }
Пример #24
0
 public static void DeleteCalendar(int calendarId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         CalendarEntry toDelete = scope.CalendarEntries.First(x => x.CalendarId == calendarId);
         scope.CalendarEntries.Remove(toDelete);
         scope.SaveChanges();
     }
 }
Пример #25
0
        public static void AddNoteType(NoteType toAdd)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                scope.NoteTypes.Add(toAdd);
                scope.Entry(toAdd).State = EntityState.Added;
                scope.SaveChanges();
            }

            ThisCache.Add(toAdd);
        }
Пример #26
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);
            }
        }
Пример #27
0
        public static void AddFriendshipRequest(FriendshipRequest toAdd)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                scope.FriendshipRequests.Add(toAdd);
                scope.Entry(toAdd).State = EntityState.Added;
                scope.SaveChanges();
            }

            AddToUserFriendshipCacheIterator(toAdd.SenderId);
            AddToUserFriendshipCacheIterator(toAdd.RecipientId);
        }
Пример #28
0
        public static void AddProMaUser(ProMaUser toAdd)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                scope.ProMaUsers.Add(toAdd);
                scope.Entry(toAdd).State = EntityState.Added;
                scope.SaveChanges();
            }

            lock (ThisCache)
            {
                ThisCache.Add(toAdd);
            }
        }
Пример #29
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);
        }
Пример #30
0
        public static void RemoveFriendship(int userOne, int userTwo)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                Friendship toRemove = scope.Friendships.FirstOrDefault(x => (x.MemberOneId == userOne && x.MemberTwoId == userTwo) || (x.MemberOneId == userTwo && x.MemberTwoId == userOne));

                scope.Friendships.Attach(toRemove);
                scope.Friendships.Remove(toRemove);

                scope.SaveChanges();
            }

            FriendshipRequestHandler.AddToUserFriendshipCacheIterator(userOne);
            FriendshipRequestHandler.AddToUserFriendshipCacheIterator(userTwo);
        }