Beispiel #1
0
        //[ValidateAntiForgeryToken]
        ///<summary>
        /// Views all teams(admin, service manager and team leads)
        /// </summary>
        public ActionResult ViewAllTeams()
        {
            ActionResult oResponse      = null;
            var          viewAllTeamsVM = new TeamViewModel();
            var          userPO         = (IUserPO)Session["UserModel"];

            // Ensures authenticated
            if (userPO.Email != null && userPO.RoleID_FK >= (int)RoleEnum.Administrator && (int)RoleEnum.Team_Lead <= 3)
            {
                try
                {
                    var allTeams    = _TeamDataAccess.GetAllTeams();
                    var smAllTeams  = _TeamDataAccess.GetAllSMTeamsByUserID(userPO.UserID);
                    var smTeams     = _TeamDataAccess.GetAllSMTeams();
                    var allUsers    = _UserDataAccess.GetAllUsers();
                    var allAbsences = PointsDataAccess.ViewAllAbsences();

                    switch (userPO.RoleID_FK)
                    {
                    case 1:
                        // TODO: Add widget data to view model/view
                        // Maps from data objects to presentation objects.
                        viewAllTeamsVM.ListOfPos = TeamMapper.MapListOfDOsToListOfPOs(allTeams);
                        var bestStandingTeam   = _TeamBusinessLogic.QueryBestStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences);
                        var bottomStandingTeam = _TeamBusinessLogic.QueryWorstStandingTeam(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences);
                        var teamRanker         = _TeamBusinessLogic.QueryTeamRanker(TeamMapper.MapListOfDOsToListOfBOs(allTeams), allAbsences);
                        AssociateAdminValues(viewAllTeamsVM, bestStandingTeam, bottomStandingTeam, allAbsences, teamRanker, userPO);

                        oResponse = View(viewAllTeamsVM);
                        break;

                    case 2:
                        // TODO: Add Widget data to view model/view

                        // Maps from data objects to presentation objects.
                        viewAllTeamsVM.ListOfPos = TeamMapper.MapListOfDOsToListOfPOs(smAllTeams);
                        //var teamAbsences = allAbsences.Where(a => a.); Need to retrieve absences by Team
                        // TODO: list of service manager team absences
                        viewAllTeamsVM.ListOfTeamAbsences = AbsenceMapper.MapListOfDOsToListOfPOs(allAbsences);
                        var topEmployee = _TeamBusinessLogic.QueryBestStandingTeamMember(smTeams, allAbsences, allUsers, userPO.RoleID_FK);

                        oResponse = View(viewAllTeamsVM);
                        break;

                    case 3:
                        // TODO: Finish DA call for Team Lead lolololol
                        var getAllTeams = _TeamDataAccess.GetAllTeamsByUserID(userPO.UserID);
                        viewAllTeamsVM.ListOfPos = TeamMapper.MapListOfDOsToListOfPOs(getAllTeams);
                        var topTeamMember = _TeamBusinessLogic.QueryBestStandingTeamMember(smTeams, allAbsences, allUsers, userPO.RoleID_FK);

                        oResponse = View(viewAllTeamsVM);
                        break;

                    default:
                        oResponse = View("Index", "Home");
                        break;
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.LogError(ex, "ViewAllTeams", "Maint");
                    viewAllTeamsVM.ErrorMessage = "There was an issure retrieving the view all teams. Please try again. If the problem persists contact your IT department.";
                }
            }
            else
            {
                oResponse = RedirectToAction("Index", "Home");
            }

            return(oResponse);
        }