public IList <FullListCalendarEvents> GetAdminFirstFive()
        {
            IEnumerable <CalendarEvent>    firstFive    = _repo.Query <CalendarEvent>().Include(c => c.EventOwner).ToList().Take(5);
            IList <FullListCalendarEvents> listableFive = new List <FullListCalendarEvents>();

            foreach (CalendarEvent calEvent in firstFive)
            {
                FullListCalendarEvents listable = new FullListCalendarEvents();
                listable.Id            = calEvent.Id;
                listable.Name          = calEvent.Name;
                listable.EventDateTime = calEvent.EventDateTime;
                listable.CreatedDate   = calEvent.CreatedDate;
                listable.Location      = calEvent.Location;
                listable.EventType     = calEvent.EventType;
                listable.isActive      = calEvent.isActive;
                listable.OwnerName     = calEvent.EventOwner.UserName;
                if (calEvent.EventAlarms != null)
                {
                    listable.AlarmCount = calEvent.EventAlarms.Count();
                }

                listableFive.Add(listable);
            }
            return(listableFive);
        }
        public IList <FullListCalendarEvents> GetSharedCalendarEventsForUser(string userId)
        {
            // Get the user for userId
            ApplicationUser user = _repo.Query <ApplicationUser>().Where(u => u.Id == userId).FirstOrDefault();
            // Get a list of all the events
            IList <SharedCalendarEvent>    sharedEvents         = _repo.Query <SharedCalendarEvent>().Where(s => s.UserId == userId).Include(e => e.CalendarEvent).Include(o => o.CalendarEvent.EventOwner).ToList();
            IList <FullListCalendarEvents> listableSharedEvents = new List <FullListCalendarEvents>();

            // Convert the shared events into something we can use and display
            foreach (SharedCalendarEvent shared in sharedEvents)
            {
                FullListCalendarEvents tempEvent = this.ConvertCalendarToListable(shared.CalendarEvent);
                tempEvent.OwnerName = shared.CalendarEvent.EventOwner.UserName;
                listableSharedEvents.Add(tempEvent);
            }

            return(listableSharedEvents);
        }
        /// <summary>
        /// Converts the CalenderEvent object to a FullListCalenderEvent object so that we send back only
        /// the information we need and we can handle any infinite loops.
        /// </summary>
        /// <param name="calenderEventToConvert">The calender event to convert.</param>
        /// <returns></returns>
        private FullListCalendarEvents ConvertCalendarToListable(CalendarEvent calendarEventToConvert)
        {
            FullListCalendarEvents listableCalendarEvent = new FullListCalendarEvents();

            listableCalendarEvent.Id            = calendarEventToConvert.Id;
            listableCalendarEvent.Name          = calendarEventToConvert.Name;
            listableCalendarEvent.EventDateTime = calendarEventToConvert.EventDateTime;
            listableCalendarEvent.CreatedDate   = calendarEventToConvert.CreatedDate;
            listableCalendarEvent.Location      = calendarEventToConvert.Location;
            listableCalendarEvent.EventType     = calendarEventToConvert.Location;
            listableCalendarEvent.isActive      = calendarEventToConvert.isActive;
            if (calendarEventToConvert.EventOwner != null)
            {
                listableCalendarEvent.OwnerName = calendarEventToConvert.EventOwner.UserName;
            }
            // I did the assigning this way so that I could null-check the EventAlarms list
            if (calendarEventToConvert.EventAlarms != null)
            {
                listableCalendarEvent.AlarmCount = calendarEventToConvert.EventAlarms.Count();
            }
            return(listableCalendarEvent);
        }