Exemplo n.º 1
0
        /*public async Task<ActionResult> Associates(int pcAssociateId)
         * {
         *  var identityName = User.Identity.Name;
         *  var users = await _activeDirectory.GetAllAdUsers();
         *  var adUsersMap = users.ToDictionary(key => key.id, value => value.displayName);
         *  var userID = users.First(adUser => adUser.userPrincipalName == identityName).id;
         *  ViewBag.AssociateId = userID;
         *  var pcAssociateUserViewModels =
         *      AutoMapper.Mapper.Map<PCAssociateViewModel>(_pcAssociatesDa.GetPCAssociate(pcAssociateId));
         *  pcAssociateUserViewModels.PCDisplayName = adUsersMap[pcAssociateUserViewModels.PCUserId];
         *  pcAssociateUserViewModels.AssociateDisplayName = adUsersMap[pcAssociateUserViewModels.AssociateUserId];
         *  pcAssociateUserViewModels.Peers.ForEach(q => q.PeerName = adUsersMap[q.PeerUserId]);
         *  return View(pcAssociateUserViewModels);
         * }*/

        public async Task <ActionResult> AssignPeersToAssociates(PCAssociateViewModel pcAssociateViewModel)
        {
            var peersForGivenAssociateByPcAssociateId = _peersDa.GetPeersForGivenAssociateByPcAssociateId(pcAssociateViewModel.PCAssociatesId);
            var users = _activeDirectoryUserDa.GetActiveDirectoryUsers().ToList()
                        .Select(p => AutoMapper.Mapper.Map <User>(p)).ToList();
            var peerViewModels = users.Where(p => p.id != pcAssociateViewModel.PCUserId && p.id != pcAssociateViewModel.AssociateUserId).ToList()
                                 .Select(p => AutoMapper.Mapper.Map <PeerViewModel>(p)).ToList();

            foreach (var peerViewModel in peerViewModels)
            {
                peerViewModel.AssociateUserId = pcAssociateViewModel.AssociateUserId;
                peerViewModel.IsSelected      = false || peersForGivenAssociateByPcAssociateId.Any(p => p.PeerUserId == peerViewModel.PeerUserId);
                peerViewModel.PCAssociateId   = pcAssociateViewModel.PCAssociatesId;
            }
            var associatePeerSelectionModel = new AssociatePeerSelectionModel();

            associatePeerSelectionModel.PeerViewModels.AddRange(peerViewModels);
            associatePeerSelectionModel.PeerListFinalized = pcAssociateViewModel.PeerListFinalized;
            return(View(associatePeerSelectionModel));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> AddPeers(AssociatePeerSelectionModel peerSelectionModel, string addPeersButton)
        {
            var peers = peerSelectionModel.PeerViewModels.Where(p => p.IsSelected == true)
                        .Select(p => AutoMapper.Mapper.Map <Peer>(p)).ToList();

            if (peers.Any())
            {
                var pcAssociateId = peers.FirstOrDefault().PCAssociateId;
                var peersForGivenAssociateByPcAssociateId = _peersDa.GetPeersForGivenAssociateByPcAssociateId(pcAssociateId);
                _peersDa.RemovePeers(peersForGivenAssociateByPcAssociateId);
                if (addPeersButton == "Finalize Peers")
                {
                    var pcAssociate = _pcAssociatesDa.GetPCAssociate(pcAssociateId);
                    pcAssociate.PeerListFinalized = true;
                    _pcAssociatesDa.EditPCAssociate(pcAssociate);

                    #region mailNotification
                    {
                        var allAdUsers = _activeDirectoryUserDa.GetActiveDirectoryUsers().ToList()
                                         .Select(p => AutoMapper.Mapper.Map <User>(p)).ToList();
                        var allAdUsersDictionary = allAdUsers.ToList().ToDictionary(p => p.id);
                        var pc        = allAdUsersDictionary[_pcAssociatesDa.GetPCAssociate(pcAssociateId).PCUserId];
                        var associate =
                            allAdUsersDictionary[_pcAssociatesDa.GetPCAssociate(pcAssociateId).AssociateUserId];
                        var peerUsers = new List <User>();
                        peers.ForEach(p => peerUsers.Add(allAdUsersDictionary[p.PeerUserId]));
                        var activeAppraisalSeason = _appraisalSeasonDa.GetActiveAppraisalSeason();
                        _notificationService.SendMessageToAssociateOnPeerListFinalization(pc, associate, peerUsers);
                        _notificationService.SendMessageToPeersOnPeerListFinalization(pc, associate, peerUsers, activeAppraisalSeason.Name);
                    }
                    #endregion
                }
            }


            _peersDa.AddPeers(peers);
            return(RedirectToAction("Index", "Home"));
        }