public async Task <ActionResult> Index()
        {
            User loggedInUser = null;

            if (Session[SK_CURRENT_USER] == null)
            {
                var identityName = User.Identity.Name;
                loggedInUser = AutoMapper.Mapper.Map <User>(_activeDirectoryUserDa.GetActiveDirectoryUserByEmailId(identityName));
                if (loggedInUser != null)
                {
                    loggedInUser.IsAdmin = _userRolesDA.IsAdmin(loggedInUser.id);
                    loggedInUser.IsPC    = _userRolesDA.IsUserPC(loggedInUser.id);
                }
                Session[SK_CURRENT_USER] = loggedInUser;
            }
            else
            {
                loggedInUser = (User)Session[SK_CURRENT_USER];
            }
            ViewBag.LoggedInUser = loggedInUser;
            AppraisalSeason inProgressAppraisalSeason = _appraisalSeasonDa.GetInProgressAppraisalSeason();

            ViewBag.InProgressAppraisalSeason = AutoMapper.Mapper.Map <AppraisalSeasonViewModel>(inProgressAppraisalSeason);
            if (inProgressAppraisalSeason != null && inProgressAppraisalSeason.IsActive.GetValueOrDefault())
            {
                var users = _activeDirectoryUserDa.GetActiveDirectoryUsers().ToList()
                            .Select(p => AutoMapper.Mapper.Map <User>(p)).ToList();
                var adUsersMap = users.ToDictionary(key => key.id, value => value);
                var pcAssociateUserViewModels = _pcAssocaiteDa.GetAllAssociateForGivenPCForActiveAppraisalSeason(loggedInUser.id).Select(pcAssociate => AutoMapper.Mapper.Map <PCAssociate, PCAssociateViewModel>(pcAssociate)).ToList();
                pcAssociateUserViewModels.ForEach(p => p.AssociateDisplayName          = adUsersMap[p.AssociateUserId].displayName);
                pcAssociateUserViewModels.ForEach(p => p.Peers.ForEach(q => q.PeerName = adUsersMap[q.PeerUserId].displayName));
                ViewBag.PcAssociateUserViewModels = pcAssociateUserViewModels;
                loggedInUser.PCAssociateModel     = AutoMapper.Mapper.Map <PCAssociateViewModel>(_pcAssocaiteDa.GetPCAssociateForGivenAssociateId(loggedInUser.id));
                if (loggedInUser.PCAssociateModel != null)
                {
                    loggedInUser.PC = adUsersMap[loggedInUser.PCAssociateModel.PCUserId];
                }
                var seekingFeedbackFrom = _peersDa.GetPeersForGivenAssociate(loggedInUser.id);
                loggedInUser.SeekingFeedbackFrom = seekingFeedbackFrom.Count > 0 ? seekingFeedbackFrom.Select(x => AutoMapper.Mapper.Map <PeerViewModel>(x)).ToList() : null;
                InitUserData(loggedInUser.SeekingFeedbackFrom, adUsersMap);
                var SendingFeedbackTo = _peersDa.GetUsersWhomeGivenAssociateIsPeer(loggedInUser.id);
                loggedInUser.SendingFeedbackTo = SendingFeedbackTo.Count > 0 ? SendingFeedbackTo.Select(x => AutoMapper.Mapper.Map <PeerViewModel>(x)).ToList() : null;
                InitUserData(loggedInUser.SendingFeedbackTo, adUsersMap);
            }
            return(View());
        }
Ejemplo n.º 2
0
        // GET: Associates For pc
        public async Task <ActionResult> Index()
        {
            var identityName = User.Identity.Name;
            var users        = _activeDirectoryUserDa.GetActiveDirectoryUsers().ToList()
                               .Select(p => AutoMapper.Mapper.Map <User>(p)).ToList();
            var adUsersMap = users.ToDictionary(key => key.id, value => value.displayName);
            var userID     = users.First(adUser => adUser.userPrincipalName == identityName).id;

            ViewBag.AssociateId = userID;
            var pcAssociateUserViewModels = _pcAssociatesDa.GetAllAssociateForGivenPCForActiveAppraisalSeason(userID).Select(pcAssociate => AutoMapper.Mapper.Map <PCAssociate, PCAssociateViewModel>(pcAssociate)).ToList();

            pcAssociateUserViewModels.ForEach(p => p.AssociateDisplayName          = adUsersMap[p.AssociateUserId]);
            pcAssociateUserViewModels.ForEach(p => p.Peers.ForEach(q => q.PeerName = adUsersMap[q.PeerUserId]));
            return(View(new PCAssociateViewModels()
            {
                PcAssociateViewModels = pcAssociateUserViewModels
            }));
        }