コード例 #1
0
        //[ValidateAntiForgeryToken]
        ///<summary>
        /// Views all absences by for a given team(TL, SM, Admin)
        /// </summary>
        /// <returns></returns>
        public ActionResult ViewAbsencesByTeamID(int teamID)
        {
            ActionResult oResponse            = null;
            var          selectedTeamAbsences = new AbsenceViewModel();
            var          userPO = (IUserPO)Session["UserModel"];

            if (userPO.Email != null && userPO.RoleID_FK <= (int)RoleEnum.Team_Lead && userPO.RoleID_FK >= (int)RoleEnum.Administrator)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        // Stores list of absences by TeamID
                        var absences = PointsDataAccess.GetAbsencesByTeamID(teamID);
                        var teamName = _TeamDataAccess.GetTeamNameByID(teamID);

                        // Retrieve lists for LINQ queries
                        var allAbsences   = PointsDataAccess.ViewAllAbsences();
                        var allTeams      = _TeamDataAccess.GetAllTeams();
                        var allUsers      = _UserDataAccess.GetAllUsers();
                        var topMemeberBOs = UserMapper.MapListOfDOsToListOfBOs(allUsers);

                        // LINQ Queries
                        var bestStandingTeam   = _TeamBusinessLogic.QueryBestStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences);
                        var bottomStandingTeam = _TeamBusinessLogic.QueryWorstStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences);
                        var topEmployee        = _TeamBusinessLogic.QueryBestStandingEmployee(allTeams, allAbsences, allUsers);
                        var teamRanker         = _TeamBusinessLogic.QueryTeamRanker(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences);
                        MapAdminObjects(selectedTeamAbsences, allTeams, absences);

                        switch (userPO.RoleID_FK)
                        {
                        // Admin
                        case 1:
                            selectedTeamAbsences.ListOfPos = AbsenceMapper.MapListOfDOsToListOfPOs(absences);
                            AssociateAdminValues(selectedTeamAbsences, teamRanker, teamName, bestStandingTeam, bottomStandingTeam, topEmployee);
                            break;

                        // Service Manager
                        case 2:
                            var teamAbsences = AbsenceMapper.MapListOfDOsToListOfPOs(absences);
                            var smTeams      = _TeamDataAccess.GetAllSMTeamsByUserID(userPO.UserID);
                            selectedTeamAbsences.SMTeams = TeamMapper.MapListOfDOsToListOfPOs(smTeams);
                            AssociateAdminValues(selectedTeamAbsences, teamRanker, teamName, bestStandingTeam, bottomStandingTeam, topEmployee);
                            //selectedTeamAbsences.ListOfPos = teamAbsences;
                            //selectedTeamAbsences.TopTeam.Team.Name = bestStandingTeam.Item1;
                            //selectedTeamAbsences.TopTeam.Absence.Point = bestStandingTeam.Item2;
                            //selectedTeamAbsences.BottomTeam.Team.Name = bottomStandingTeam.Item1;
                            //selectedTeamAbsences.BottomTeam.Absence.Point = bottomStandingTeam.Item2;
                            //selectedTeamAbsences.TopEmployee.Name = topEmployee.Item1;
                            //selectedTeamAbsences.TopEmployee.Absence.Point = topEmployee.Item2;
                            //MapServiceManagerObjects(selectedTeamAbsences, allTeams, absences);
                            //AssociateServiceManagerObjects(selectedTeamAbsences, topEmployee);

                            oResponse = View(selectedTeamAbsences);
                            break;

                        // Team Lead
                        case 3:
                            var tlAbsences = AbsenceMapper.MapListOfDOsToListOfPOs(absences);
                            selectedTeamAbsences.ListOfPos = tlAbsences;
                            AssociateAdminValues(selectedTeamAbsences, teamRanker, teamName, bestStandingTeam, bottomStandingTeam, topEmployee);
                            //selectedTeamAbsences.TopTeam.Team.Name = bestStandingTeam.Item1;
                            //selectedTeamAbsences.TopTeam.Absence.Point = bestStandingTeam.Item2;
                            //selectedTeamAbsences.BottomTeam.Team.Name = bottomStandingTeam.Item1;
                            //selectedTeamAbsences.BottomTeam.Absence.Point = bottomStandingTeam.Item2;
                            //selectedTeamAbsences.TopEmployee.Name = topEmployee.Item1;
                            //selectedTeamAbsences.TopEmployee.Absence.Point = topEmployee.Item2;

                            oResponse = View(selectedTeamAbsences);
                            break;

                        default:
                            break;
                        }

                        oResponse = View(selectedTeamAbsences);
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.LogError(ex, "ViewAbsencesByTeamID", "Maint");
                        selectedTeamAbsences.ErrorMessage = "Something went wrong retrieving the list of absences. Please try again.";
                        oResponse = View(selectedTeamAbsences);
                    }
                }
                else
                {
                    oResponse = View(selectedTeamAbsences);
                }
            }

            return(oResponse);
        }