private void Participants_DataContextChanged(object sender, System.Windows.DependencyPropertyChangedEventArgs e)
 {
     DataContextChanged     -= Participants_DataContextChanged;
     _participantDataSummary = ((DataSummaryViewModel)DataContext).ParticipantData;
     AddPartCols();
     _participantDataSummary.ColHeaders.CollectionChanged += ColHeaders_CollectionChanged;
 }
        public ActionResult Details(int?id, string error)
        {
            bool permissionToShowParticipantDetails = false;

            if (id == null)
            {
                var loggedInUserAsParticipant = _personManager.GetParticipantByCas(User.Identity.Name.ToCasId());
                if (loggedInUserAsParticipant == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }

                id = loggedInUserAsParticipant.Id;

                permissionToShowParticipantDetails = true;
            }

            if (!User.IsInRole("Admin") && !permissionToShowParticipantDetails)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.Unauthorized));
            }


            Participant participant = _personManager.GetAllParticipants().SingleOrDefault(n => n.Id == id);

            if (participant == null)
            {
                return(HttpNotFound());
            }

            var allSessions =
                _sessionManager.GetAllSessions()
                .Include(n => n.Activity)
                .OrderBy(n => n.Activity.Name)
                .ThenBy(n => n.Name)
                .ToList();

            var userSessions = _sessionManager.GetAllSessionsForParticipantById(participant.Id)
                               .Include(n => n.Activity)
                               .OrderBy(n => n.StartDate)
                               .ToList();

            var upcomingSessions     = userSessions.Where(n => n.StartDate > DateTime.Now);
            var participatedSessions = userSessions.Where(n => n.StartDate < DateTime.Now || n.StartDate == null);


            var yearslist = _sessionManager.GetAllSessionsForParticipantById(participant.Id)
                            .Include(n => n.Activity)
                            .OrderBy(n => n.StartDate.Value.Year)
                            .Where(n => n.StartDate != null && n.StartDate < DateTime.Now)
                            .Select(n => n.StartDate.Value.Year).Distinct()
                            .OrderByDescending(n => n)
                            .ToList();

            var viewModel = new ParticipantSummaryViewModel()
            {
                PersonId         = participant.Id,
                Email            = participant.Email,
                FullName         = participant.FullName,
                Comments         = participant.Comments,
                Wishes           = participant.Wishes,
                Years            = yearslist,
                Sessions         = participatedSessions,
                UpcomingSessions = upcomingSessions,
                AllSessions      = new SelectList(
                    allSessions,
                    "Id",
                    "NameWithActivity",
                    allSessions.First().Id),
                ParticipantCasId = participant.CasId
            };

            if (!string.IsNullOrEmpty(error))
            {
                ViewBag.Error = error;
            }

            return(View(viewModel));
        }