Esempio n. 1
0
        public ISpaceEventGroup GetGroupForDate(DateTime forDate)
        {
            var Result = new SpaceEventGroup();

            // Exact Day
            var DayIndex = Utilities.DayIndex(forDate);

            Result.Current = Context.SpaceEvents.AsQueryable().Where(s => s.DayIndex == DayIndex).ToList <ISpaceEvent>();

            // Next Day after Exact Day if needed
            if (Result.CurrentCount == 0)
            {
                // Check for next
                DayIndex = Context.SpaceEvents.AsQueryable().Where(s => s.DayIndex > DayIndex).OrderBy(s => s.DayIndex).Select(s => s.DayIndex).FirstOrDefault();

                // If none, start from 1/1
                if (DayIndex == 0)
                {
                    DayIndex = Context.SpaceEvents.AsQueryable().Where(s => s.DayIndex > 0).OrderBy(s => s.DayIndex).Select(s => s.DayIndex).FirstOrDefault();
                }

                // Grab Group
                Result.Current = Context.SpaceEvents.AsQueryable().Where(s => s.DayIndex == DayIndex).ToList <ISpaceEvent>();
            }

            // Previous
            Result.Previous = Context.SpaceEvents.AsQueryable().Where(s => s.DayIndex < DayIndex).OrderByDescending(s => s.Date).FirstOrDefault();
            if (Result.Previous == null)
            {
                Result.Previous = Context.SpaceEvents.AsQueryable().Where(s => s.DayIndex < 367).OrderByDescending(s => s.Date).FirstOrDefault();
            }

            // Later
            Result.Next = Context.SpaceEvents.AsQueryable().Where(s => s.DayIndex > DayIndex).OrderBy(s => s.Date).FirstOrDefault();
            if (Result.Next == null)
            {
                Result.Next = Context.SpaceEvents.AsQueryable().Where(s => s.DayIndex > 0).OrderBy(s => s.Date).FirstOrDefault();
            }

            return(Result);
        }
        public ISpaceEventGroup GetGroupForDate(DateTime forDate)
        {
            var SE1 = new SpaceEvent()
            {
                Name    = "Test Event 1",
                Country = "United States",
                Date    = new DateTime(1969, 1, 1)
            };
            var SE2 = new SpaceEvent()
            {
                Name    = "Test Event 2",
                Country = "United States",
                Date    = new DateTime(1980, 5, 1)
            };
            var SE2_2 = new SpaceEvent()
            {
                Name    = "Test Event 2_2",
                Country = "United States",
                Date    = new DateTime(1981, 5, 1)
            };
            var SE3 = new SpaceEvent()
            {
                Name    = "Test Event 3",
                Country = "United States",
                Date    = new DateTime(2000, 12, 1)
            };

            var Result = new SpaceEventGroup();

            Result.Previous = SE1;
            Result.Current.Add(SE2);
            Result.Current.Add(SE2_2);
            Result.Next = SE3;

            return(Result);
        }