コード例 #1
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);
            }
        }
コード例 #2
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);
            }
        }
コード例 #3
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);
            }
        }
コード例 #4
0
        public static void UpdateUser(ProMaUser toUpdate)
        {
            using (ProMaDB scope = new ProMaDB())
            {
                scope.ProMaUsers.Attach(toUpdate);
                scope.Entry(toUpdate).State = EntityState.Modified;
                scope.SaveChanges();
            }

            lock (ThisCache)
            {
                ThisCache.RemoveAll(x => x.UserId == toUpdate.UserId);
                ThisCache.Add(toUpdate);
            }
        }
コード例 #5
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);
            }
        }
コード例 #6
0
 public PostedNoteProMaUserPayload(ProMaUser toMake)
 {
     UserName = toMake.UserName;
 }