Beispiel #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);
            }
        }
Beispiel #2
0
 public static List <CalendarEntry> GetAllCalendarEntriesForUser(int userId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.CalendarEntries.Where(x => x.UserId == userId).ToList());
     }
 }
Beispiel #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());
     }
 }
Beispiel #4
0
 public static List <PostedNote> GetAllNotesOfType(int noteTypeId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.PostedNotes.Where(x => x.NoteTypeId == noteTypeId).ToList());
     }
 }
Beispiel #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));
     }
 }
Beispiel #6
0
 public static PostedNote GetNote(int noteId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.PostedNotes.FirstOrDefault(x => x.NoteId == noteId));
     }
 }
Beispiel #7
0
 public static List <CompletedChore> GetAllCompletedChoreItems(int sharedChoreId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.CompletedChores.Where(x => x.SharedChoreId == sharedChoreId).ToList());
     }
 }
Beispiel #8
0
 public static SharedChore GetSharedChore(int sharedChoreId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.SharedChores.FirstOrDefault(x => x.SharedChoreId == sharedChoreId));
     }
 }
Beispiel #9
0
 public static CalendarEntry GetEntry(int calendarId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.CalendarEntries.First(x => x.CalendarId == calendarId));
     }
 }
Beispiel #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);
            }
        }
Beispiel #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));
     }
 }
Beispiel #12
0
 public static List <SharedChoreMembership> GetSharedChoreMembershipsForUser(int userId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.SharedChoreMemberships.Where(x => x.UserId == userId).ToList());
     }
 }
Beispiel #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());
     }
 }
Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #16
0
 public static List <NoteTypeMembership> GetMembershipsForType(int typeId)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         return(scope.NoteTypeMemberships.Where(x => x.NoteTypeId == typeId).ToList());
     }
 }
Beispiel #17
0
 public static void AddCalendar(CalendarEntry toAdd)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.CalendarEntries.Add(toAdd);
         scope.SaveChanges();
     }
 }
Beispiel #18
0
 public static void PermanentlyDeleteNote(PostedNote toDelete)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.PostedNotes.Remove(toDelete);
         scope.SaveChanges();
     }
 }
Beispiel #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();
     }
 }
Beispiel #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();
     }
 }
Beispiel #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();
     }
 }
Beispiel #22
0
 public static void RemoveNoteTypeMembership(NoteTypeMembership toRemove)
 {
     using (ProMaDB scope = new ProMaDB())
     {
         scope.NoteTypeMemberships.Attach(toRemove);
         scope.NoteTypeMemberships.Remove(toRemove);
         scope.SaveChanges();
     }
 }
Beispiel #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();
     }
 }
Beispiel #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();
     }
 }
Beispiel #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);
        }
Beispiel #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);
            }
        }
Beispiel #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);
        }
Beispiel #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);
            }
        }
Beispiel #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);
        }
Beispiel #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);
        }