// GET: AppraisalProcesses/Start/5 public async Task <ActionResult> View(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } AppraisalSeason appraisalProcess = _appraisalSeasonDa.GetAppraisalSeason(id); if (appraisalProcess == null) { return(HttpNotFound()); } List <PCAssociateViewModel> pcAssociateViewModels = _pcAssociateDa.GetAllPcAssociatesForInProgressAppraisalSeason().Select(x => AutoMapper.Mapper.Map <PCAssociate, PCAssociateViewModel>(x)).ToList(); var users = _activeDirectoryUserDa.GetActiveDirectoryUsers().ToList() .Select(p => AutoMapper.Mapper.Map <User>(p)).ToList(); pcAssociateViewModels.ForEach(x => { x.AssociateDisplayName = users.First(p => p.id == x.AssociateUserId).displayName; x.PCDisplayName = users.First(p => p.id == x.PCUserId).displayName; }); ViewBag.PcAssociateViewModels = pcAssociateViewModels; return(View(AutoMapper.Mapper.Map <AppraisalSeason, AppraisalSeasonViewModel>(appraisalProcess))); }
/* public async Task<ActionResult> AssignAssociates(System.Guid pcID) * { * var _userList = await _activeDirectory.GetAllAdUsers(); * ViewBag.PCId = pcID; * //todo PCAssociate table may contain multiple entries for associate for multiple appraisal seasons * var allPcAssociates = _pcAssociatesDa.GetAllPcAssociates().ToDictionary(k => k.AssociateUserId); * List<PCAssociateUserViewModel> pcAssociateUsers = new List<PCAssociateUserViewModel>(); * _userList.ForEach(p => pcAssociateUsers.Add(new PCAssociateUserViewModel() * { * PCUserId = allPcAssociates.ContainsKey(p.id) ? allPcAssociates[p.id].PCUserId : Guid.Empty, * AssociateUserId = p.id, * AssociateDisplayName = p.displayName * })); * var pcAssociateUserViewModels = pcAssociateUsers * .Where(p => (p.PCUserId == pcID || p.PCUserId == Guid.Empty) && (p.AssociateUserId != pcID)).ToList(); * return View(pcAssociateUserViewModels); * } * * public ActionResult MakeAssociate(Guid associateId, Guid pcId) * { * SLAP_Data.PCAssociate pcAssociate = new SLAP_Data.PCAssociate() * { * PCUserId = pcId, * AssociateUserId = associateId * }; * * _pcAssociatesDa.AddAsociate(pcAssociate); * * _notificationService.SendMessageToAssociateOnPcAssignment( * new User {displayName = "Associate Name", mail = "*****@*****.**"}, * new User {displayName = "PC Name", mail = "*****@*****.**"}); * * return RedirectToAction("AssignAssociates", new {pcID = pcId}); * } * * public ActionResult RemoveAssociate(Guid associateId, Guid pcId) * { * _pcAssociatesDa.RemoveAssociate(associateId, pcId); * return RedirectToAction("AssignAssociates", new {pcID = pcId}); * }*/ #region newAssociatesScreen public ActionResult AssignAssociates(Guid?pcId) { if (_appraisalSeasonDa.GetActiveAppraisalSeason() != null) { return(RedirectToAction("Index", "Home")); } var _userList = _activeDirectoryUserDa.GetActiveDirectoryUsers().ToList() .Select(p => AutoMapper.Mapper.Map <User>(p)).ToList(); ViewBag.PCId = pcId; ViewBag.pcName = _userList.First(p => p.id == pcId).displayName; var pcAssociate = _pcAssociatesDa.GetPCAssociateForGivenAssociateId((Guid)pcId); var pcAsoociatePcUserId = Guid.Empty; if (pcAssociate != null) { pcAsoociatePcUserId = pcAssociate.PCUserId; } var allPcAssociates = _pcAssociatesDa.GetAllPcAssociatesForInProgressAppraisalSeason().ToDictionary(k => k.AssociateUserId); List <PCAssociateUserViewModel> pcAssociateUsers = new List <PCAssociateUserViewModel>(); _userList.ForEach(p => pcAssociateUsers.Add(new PCAssociateUserViewModel() { PCUserId = allPcAssociates.ContainsKey(p.id) ? allPcAssociates[p.id].PCUserId : Guid.Empty, Selected = allPcAssociates.ContainsKey(p.id), AssociateUserId = p.id, AssociateDisplayName = p.displayName })); var pcAssociateUserViewModels = pcAssociateUsers .Where(p => (p.PCUserId == pcId || p.PCUserId == Guid.Empty) && (p.AssociateUserId != pcId) && (pcAsoociatePcUserId != p.AssociateUserId)).ToList(); pcAssociateUserViewModels.ForEach(p => p.PCUserId = (Guid)pcId); AssociateSelectionViewModel associateSelectionViewModel = new AssociateSelectionViewModel(); associateSelectionViewModel.PcAssociateUserViewModels = pcAssociateUserViewModels; return(View(associateSelectionViewModel)); }