public ActionResult List(SessionFilterViewModel filter, int? page, GridSortOptions sortOptions)
        {
            var user = _userService.CurrentUser;
            if (filter == null)
                filter = new SessionFilterViewModel();

            if (sortOptions.Column == null)
                sortOptions = new GridSortOptions
                {
                    Column = "End",
                    Direction = SortDirection.Ascending
                };

            page = page ?? 1;

            var sessions = _sessionService.GetAll().Where(s => s.IsAccepted == true && s.UserId != user.Id);

            // Filtering
            if (!string.IsNullOrWhiteSpace(filter.FilterText))
            {
                sessions = from c in sessions
                           where c.Title.Contains(filter.FilterText)
                        select c;
            }
            if (!filter.ShowClosed)
            {
                sessions = from c in sessions
                           where c.RegistrationClosedAt > DateTime.Now
                           select c;
            }

            if (filter.From != null)
            {
                sessions = from c in sessions
                           where c.Start >= filter.From
                           select c;
            }

            if (filter.To != null) {
                sessions = from c in sessions
                           where c.End <= filter.To
                           select c;
            }

            if (filter.SelectedTypeId != null) {
                sessions = from c in sessions
                           where (int)c.Type == filter.SelectedTypeId.Value
                           select c;
            }

            var list = from s in sessions.ToList()
                       select new SessionRowItem
                          {
                              Id = s.Id,
                              Title = s.Title,
                              End = s.End,
                              Start = s.Start,
                              RegistrationCloseAt = s.RegistrationClosedAt,
                              NumberOfRegistrants = s.Users.Count(),
                              IsAuthor = s.UserId == user.Id,
                              IsRegistered = s.Users.Any(u => u.UserId == user.Id) ,
                              TypeId = (int)s.Type
                          };

            list = list.OrderBy(sortOptions.Column, sortOptions.Direction);
            var types = (from SessionType s in SessionType.GetValues(typeof(SessionType))
                           select new SelectListItem { Text = s.ToString(), Value = ((int)s).ToString() }).ToList();
            types.Insert(0, new SelectListItem { Text = "", Value = "" });
            filter.Types = types;
            var goups = list.ToList().GroupBy(s => s.Start.Date).Select(p =>
            {
                return new SesionListItemViewModel
                {
                    Start = p.Key,
                    Sessions = p
                };
            });

            var vm = new SessionListViewModel
            {
                List = goups.ToList().AsPagination(page.Value, ListPageSize),
                SortOptions = sortOptions,
                Filter = filter,
                Page = page.Value
            };

            return View(vm);
        }
        public ActionResult List(SessionFilterViewModel filter, int? page, GridSortOptions sortOptions)
        {
            var user = _userService.CurrentUser;
            if (filter == null)
                filter = new SessionFilterViewModel();

            if (sortOptions.Column == null)
                sortOptions = new GridSortOptions
                {
                    Column = "End",
                    Direction = SortDirection.Ascending
                };

            page = page ?? 1;

            var sessions = _sessionService.GetAll().ToList().Where(s => (int)s.Status != (int)SessionStatus.InProgress);

            // Filtering
            if (!string.IsNullOrWhiteSpace(filter.FilterText))
            {
                sessions = from c in sessions
                           where c.Title.Contains(filter.FilterText)
                           select c;
            }

            if (!filter.ShowClosed)
            {
                sessions = from c in sessions
                           where c.Start > DateTime.Now
                           select c;
            }

            if (filter.From != null)
            {
                sessions = from c in sessions
                           where c.Start >= filter.From
                           select c;
            }

            if (filter.To != null)
            {
                sessions = from c in sessions
                           where c.End <= filter.To
                           select c;
            }

            if (filter.SelectedTypeId != null)
            {
                sessions = from c in sessions
                           where (int)c.Type == filter.SelectedTypeId.Value
                           select c;
            }

            var list = from s in sessions.ToList()
                       select new SessionDescriptionModel
                       {
                           SessionId = s.Id,
                           Title = s.Title,
                           End = s.End,
                           Start = s.Start,
                           RegistrationCloseAt = s.RegistrationClosedAt,
                           NumberOfRegistrants = s.Users.Count(),
                           StatusId = (int)s.Status,
                           TypeId = (int)s.Type,
                           IsAccepted = s.IsAccepted,
                           Email = s.User.Email,
                           RejectionReason = s.RejectionReason
                       };

            list = list.OrderBy(sortOptions.Column, sortOptions.Direction);
            var types = (from SessionType s in SessionType.GetValues(typeof(SessionType))
                         select new SelectListItem { Text = s.ToString(), Value = ((int)s).ToString() }).ToList();
            types.Insert(0, new SelectListItem { Text = "All", Value = "" });
            filter.Types = types;

            var vm = new AdminSessionListViewModel
            {
                Sessions = list.AsPagination(page.Value, ListPageSize),
                SortOptions = sortOptions,
                Filter = filter,
                Page = page.Value
            };

            return View(vm);
        }