示例#1
0
        public async Task <ActionResult> Associate(Guid associateId)
        {
            ViewBag.AssociateId = associateId;
            var users = _activeDirectoryUserDa.GetActiveDirectoryUsers().ToList()
                        .Select(p => AutoMapper.Mapper.Map <User>(p)).ToList();
            var userDictionary = users.ToDictionary(p => p.id);

            ViewBag.AssociateName = userDictionary[associateId].displayName;
            var peerViewModels = _peersDa.GetPeersForGivenAssociate(associateId).Select(p => AutoMapper.Mapper.Map <Peer, PeerViewModel>(p)).ToList();

            peerViewModels.ForEach(p => p.PeerName = userDictionary[p.PeerUserId].displayName);
            var userListwhomeGivenAssociateIsPeer = _peersDa.GetUsersWhomeGivenAssociateIsPeer(associateId).Select(p => AutoMapper.Mapper.Map <Peer, PeerViewModel>(p)).ToList();

            userListwhomeGivenAssociateIsPeer.ForEach(p => p.PeerName = userDictionary[p.AssociateUserId].displayName);
            return(View(peerViewModels.Concat(userListwhomeGivenAssociateIsPeer)));
        }
        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());
        }