public SessionViewModel ToSessionViewModel(Session session)
        {
            if (session == null)
            {
                return(null);
            }

            var speakerSessions = _context.SpeakerSessions
                                  .Include(ss => ss.Session)
                                  .Include(ss => ss.Speaker)
                                  .Include(ss => ss.Speaker.CodecampUser)
                                  .Where(ss => ss.SessionId == session.SessionId)
                                  .ToList();

            var sessionViewModel = new SessionViewModel
            {
                SessionId       = session.SessionId,
                Name            = session.Name,
                Description     = session.Description,
                SkillLevel      = SkillLevel.GetSkillLevelDescription(session.SkillLevel),
                Keywords        = session.Keywords,
                IsApproved      = session.IsApproved,
                SpeakerSessions = speakerSessions,
                EventName       = session.Event.Name
            };

            return(sessionViewModel);
        }
Exemple #2
0
        public async Task <List <ScheduleViewModel> > GetScheduleViewModelToBuildSchedule(int eventId)
        {
            var scheduleToBuild
            // Get the sessions
                = from session in _context.Sessions
                  // Speaker/session information
                  join _speakerSession in _context.SpeakerSessions
                  on session.SessionId equals _speakerSession.SessionId
                  into speakerSessionLeftJoin
                  // Get schedule info if it exists
                  join _schedule in _context.CodecampSchedule
                  on session.SessionId equals _schedule.SessionId
                  into scheduleLeftJoin
                  from schedule in scheduleLeftJoin.DefaultIfEmpty()
                  // Get track information if it exists
                  join _track in _context.Tracks
                  on schedule.TrackId equals _track.TrackId
                  into trackLeftJoin
                  // Get timeslot inforation if it exists
                  join _timeslot in _context.Timeslots
                  on schedule.TimeslotId equals _timeslot.TimeslotId
                  into timeslotLeftJoin
                  from track in trackLeftJoin.DefaultIfEmpty()
                  from timeslot in timeslotLeftJoin.DefaultIfEmpty()
                  where session.EventId == eventId
                  select new ScheduleViewModel
                {
                SessionId       = session.SessionId,
                Name            = session.Name,
                Description     = session.Description,
                SkillLevelId    = session.SkillLevel,
                SkillLevel      = SkillLevel.GetSkillLevelDescription(session.SkillLevel),
                Keywords        = session.Keywords,
                IsApproved      = session.IsApproved,
                SpeakerSessions = speakerSessionLeftJoin.ToList(),
                TrackId         = track != null ? track.TrackId : (int?)null,
                TrackName       = track != null ? track.Name : string.Empty,
                RoomNumber      = track != null ? track.RoomNumber : string.Empty,
                TimeslotId      = timeslot != null ? timeslot.TimeslotId : (int?)null,
                StartTime       = timeslot != null ? timeslot.StartTime : (DateTime?)null,
                EndTime         = timeslot != null ? timeslot.EndTime : (DateTime?)null
                };

            scheduleToBuild = scheduleToBuild
                              .OrderBy(s => s.TrackName)
                              .ThenBy(s => s.StartTime);

            return(await scheduleToBuild.ToListAsync());
        }
        public SessionViewModel ToSessionViewModel(Session session, string userId = null)
        {
            if (session == null)
            {
                return(null);
            }

            var speakerSessions = _context.SpeakerSessions
                                  .Include(ss => ss.Session)
                                  .Include(ss => ss.Speaker)
                                  .Include(ss => ss.Speaker.CodecampUser)
                                  .Where(ss => ss.SessionId == session.SessionId)
                                  .ToList();

            var track = session.TrackId.HasValue
                ? _context.Tracks.FirstOrDefault(t => t.TrackId == session.TrackId.Value)
                : null;

            var timeslot = session.TimeslotId.HasValue
                ? _context.Timeslots.FirstOrDefault(t => t.TimeslotId == session.TimeslotId.Value)
                : null;

            var sessionViewModel = new SessionViewModel
            {
                SessionId      = session.SessionId,
                Name           = session.Name,
                Description    = session.Description,
                SkillLevel     = SkillLevel.GetSkillLevelDescription(session.SkillLevel),
                Keywords       = session.Keywords,
                IsApproved     = session.IsApproved,
                EventName      = session.Event.Name,
                IsUserFavorite = userId == null ? false : session.AttendeeSessions
                                 .Exists(_as => _as.CodecampUserId == userId &&
                                         _as.SessionId == session.SessionId),
                TimeslotId   = timeslot != null ? session.TimeslotId : (int?)null,
                TimeslotName = timeslot != null ? timeslot.Name : string.Empty,
                StartTime    = timeslot != null ? timeslot.StartTime : (DateTime?)null,
                EndTime      = timeslot != null ? timeslot.EndTime : (DateTime?)null,
                TrackId      = track != null ? track.TrackId : (int?)null,
                TrackName    = track != null ? track.Name : string.Empty,
                RoomNumber   = track != null ? track.RoomNumber : string.Empty,
                SpeakerNames = string.Join(",", speakerSessions.Select(ss => ss.Speaker.CodecampUser.FullName))
            };

            return(sessionViewModel);
        }
        /// <summary>
        /// Convert a Session to a SessionViewModel
        /// </summary>
        /// <param name="sessions">IQueryable<Session> object</param>
        /// <returns>IQueryable<SessionViewModel> object</returns>
        public IQueryable <SessionViewModel> ToSessionViewModel(IQueryable <Session> sessions)
        {
            if (sessions == null)
            {
                return(null);
            }

            var sessionViewModels = from session in sessions
                                    select new SessionViewModel
            {
                SessionId   = session.SessionId,
                Name        = session.Name,
                Description = session.Description,
                SkillLevel  = SkillLevel.GetSkillLevelDescription(session.SkillLevel),
                Keywords    = session.Keywords,
                IsApproved  = session.IsApproved,
                EventName   = session.Event.Name,
            };

            return(sessionViewModels);
        }
Exemple #5
0
        public List <ScheduleViewModel> ToScheduleViewModel(List <Schedule> schedule)
        {
            var scheduleViewModel
                = from _schedule in schedule
                  // Get session information
                  join session in _context.Sessions on _schedule.SessionId equals session.SessionId
                  // Get event information
                  join _event in _context.Events on _schedule.Session.EventId equals _event.EventId
                  // Get track information
                  join track in _context.Tracks on _schedule.TrackId
                  equals track.TrackId
                  // Get timeslot information
                  join timeslot in _context.Timeslots on _schedule.TimeslotId
                  equals timeslot.TimeslotId
                  // Get speakerSession information
                  join _speakerSession in _context.SpeakerSessions
                  on _schedule.SessionId equals _speakerSession.SessionId
                  into speakerSessionsGroupJoin
                  select new ScheduleViewModel
                {
                SessionId       = _schedule.SessionId,
                Name            = session.Name,
                Description     = session.Description,
                SkillLevelId    = session.SkillLevel,
                SkillLevel      = SkillLevel.GetSkillLevelDescription(session.SkillLevel),
                Keywords        = session.Keywords,
                IsApproved      = session.IsApproved,
                SpeakerSessions = speakerSessionsGroupJoin.ToList(),
                TrackId         = _schedule.TrackId,
                TrackName       = track.Name,
                RoomNumber      = track.RoomNumber,
                TimeslotId      = _schedule.TimeslotId,
                StartTime       = timeslot.StartTime,
                EndTime         = timeslot.EndTime
                };

            return(scheduleViewModel.ToList());
        }
        /// <summary>
        /// Convert a Session to a SessionViewModel
        /// </summary>
        /// <param name="sessions">IQueryable<Session> object</param>
        /// <returns>IQueryable<SessionViewModel> object</returns>
        public IQueryable <SessionViewModel> ToSessionViewModel(IQueryable <Session> sessions,
                                                                string userId = null)
        {
            if (sessions == null)
            {
                return(null);
            }

            var tempSession = from _session in sessions
                              join speakerSession in _context.SpeakerSessions on _session.SessionId equals speakerSession.SessionId
                              join speaker in _context.Speakers on speakerSession.SpeakerId equals speaker.SpeakerId
                              join codecampUser in _context.CodecampUsers on speaker.CodecampUserId equals codecampUser.Id
                              join _timeslot in _context.Timeslots on _session.TimeslotId equals _timeslot.TimeslotId into timeslotLeftJoin
                              join _track in _context.Tracks on _session.TrackId equals _track.TrackId into trackLeftJoin
                              from timeslot in timeslotLeftJoin.DefaultIfEmpty()
                              from track in trackLeftJoin.DefaultIfEmpty()
                              select new SessionViewModel
            {
                SessionId      = _session.SessionId,
                Name           = _session.Name,
                Description    = _session.Description,
                SkillLevel     = SkillLevel.GetSkillLevelDescription(_session.SkillLevel),
                Keywords       = _session.Keywords,
                IsApproved     = _session.IsApproved,
                EventName      = _session.Event.Name,
                IsUserFavorite = userId == null ? false : _session.AttendeeSessions
                                 .Exists(_as => _as.CodecampUserId == userId &&
                                         _as.SessionId == _session.SessionId),
                TimeslotId   = timeslot != null ? timeslot.TimeslotId : (int?)null,
                TimeslotName = timeslot != null ? timeslot.Name : string.Empty,
                StartTime    = timeslot != null ? timeslot.StartTime : DateTime.MinValue,
                EndTime      = timeslot != null ? timeslot.EndTime : DateTime.MinValue,
                TrackId      = track != null ? track.TrackId : (int?)null,
                TrackName    = track != null ? track.Name : string.Empty,
                RoomNumber   = track != null ? track.RoomNumber : string.Empty,
                SpeakerNames = codecampUser.FullName
            };

            var session = from _session in tempSession
                          group _session by new
            {
                _session.SessionId,
                _session.Name,
                _session.Description,
                _session.SkillLevel,
                _session.Keywords,
                _session.IsApproved,
                _session.EventName,
                _session.IsUserFavorite,
                _session.TimeslotId,
                _session.TimeslotName,
                _session.StartTime,
                _session.EndTime,
                _session.TrackId,
                _session.TrackName,
                _session.RoomNumber,
            } into groupSession
                select new SessionViewModel
            {
                SessionId      = groupSession.Key.SessionId,
                Name           = groupSession.Key.Name,
                Description    = groupSession.Key.Description,
                SkillLevel     = groupSession.Key.SkillLevel,
                Keywords       = groupSession.Key.Keywords,
                IsApproved     = groupSession.Key.IsApproved,
                EventName      = groupSession.Key.EventName,
                IsUserFavorite = groupSession.Key.IsUserFavorite,
                TimeslotId     = groupSession.Key.TimeslotId,
                TimeslotName   = groupSession.Key.TimeslotName,
                StartTime      = groupSession.Key.StartTime,
                EndTime        = groupSession.Key.EndTime,
                TrackId        = groupSession.Key.TrackId,
                TrackName      = groupSession.Key.TrackName,
                RoomNumber     = groupSession.Key.RoomNumber,
                SpeakerNames   = string.Join(",", groupSession.Select(gs => gs.SpeakerNames))
            };

            session = session
                      .OrderBy(s => s.TrackName)
                      .ThenBy(s => s.StartTime.Value.TimeOfDay);

            return(session);
        }
Exemple #7
0
        public async Task <List <ScheduleViewModel> > GetScheduleViewModel(int eventId)
        {
            var tempSchedule
            // Get the sessions
                = from session in _context.Sessions
                  // Speaker/session information
                  join speakerSession in _context.SpeakerSessions on session.SessionId equals speakerSession.SessionId
                  join speaker in _context.Speakers on speakerSession.SpeakerId equals speaker.SpeakerId
                  join codecampUser in _context.CodecampUsers on speaker.CodecampUserId equals codecampUser.Id
                  // Get track information if it exists
                  join _track in _context.Tracks
                  on session.TrackId equals _track.TrackId
                  into trackLeftJoin
                  // Get timeslot inforation if it exists
                  join _timeslot in _context.Timeslots
                  on session.TimeslotId equals _timeslot.TimeslotId
                  into timeslotLeftJoin
                  from track in trackLeftJoin.DefaultIfEmpty()
                  from timeslot in timeslotLeftJoin.DefaultIfEmpty()
                  where session.EventId == eventId
                  select new ScheduleViewModel
                {
                SessionId    = session.SessionId,
                Name         = session.Name,
                Description  = session.Description,
                SkillLevelId = session.SkillLevel,
                SkillLevel   = SkillLevel.GetSkillLevelDescription(session.SkillLevel),
                Keywords     = session.Keywords,
                IsApproved   = session.IsApproved,
                Speakers     = codecampUser.FullName,
                TrackId      = track != null ? track.TrackId : (int?)null,
                TrackName    = track != null ? track.Name : string.Empty,
                RoomNumber   = track != null ? track.RoomNumber : string.Empty,
                TimeslotId   = timeslot != null ? timeslot.TimeslotId : (int?)null,
                StartTime    = timeslot != null ? timeslot.StartTime : DateTime.MinValue,
                EndTime      = timeslot != null ? timeslot.EndTime : DateTime.MinValue
                };

            var schedule = from _schedule in tempSchedule
                           group _schedule by new
            {
                _schedule.SessionId,
                _schedule.Name,
                _schedule.Description,
                _schedule.SkillLevelId,
                _schedule.SkillLevel,
                _schedule.Keywords,
                _schedule.IsApproved,
                _schedule.TrackId,
                _schedule.TrackName,
                _schedule.RoomNumber,
                _schedule.TimeslotId,
                _schedule.StartTime,
                _schedule.EndTime
            } into groupSchedule
                select new ScheduleViewModel
            {
                SessionId    = groupSchedule.Key.SessionId,
                Name         = groupSchedule.Key.Name,
                Description  = groupSchedule.Key.Description,
                SkillLevelId = groupSchedule.Key.SkillLevelId,
                SkillLevel   = groupSchedule.Key.SkillLevel,
                Keywords     = groupSchedule.Key.Keywords,
                IsApproved   = groupSchedule.Key.IsApproved,
                TrackId      = groupSchedule.Key.TrackId,
                TrackName    = groupSchedule.Key.TrackName,
                RoomNumber   = groupSchedule.Key.RoomNumber,
                TimeslotId   = groupSchedule.Key.TimeslotId,
                StartTime    = groupSchedule.Key.StartTime,
                EndTime      = groupSchedule.Key.EndTime,
                Speakers     = string.Join(",", groupSchedule.Select(gs => gs.Speakers))
            };

            schedule = schedule
                       .OrderByDescending(s => s.IsApproved)
                       .ThenBy(s => s.TrackName)
                       .ThenBy(s => s.StartTime.Value.TimeOfDay);

            return(await schedule.ToListAsync());
        }