コード例 #1
0
        private void AssociateAdminValues(TeamViewModel viewAllTeamsVM, Tuple <string, decimal> bestStandingTeam, Tuple <string, decimal> bottomStandingTeam, List <IAbsenceDO> absenceDOs, List <Tuple <string, decimal> > teamRanker, IUserPO userPO)
        {
            // Assign values to model for widgets
            viewAllTeamsVM.TopTeam.Team.Name               = bestStandingTeam.Item1;
            viewAllTeamsVM.TopTeam.Absence.RunningTotal    = bestStandingTeam.Item2;
            viewAllTeamsVM.BottomTeam.Team.Name            = bottomStandingTeam.Item1;
            viewAllTeamsVM.BottomTeam.Absence.RunningTotal = bottomStandingTeam.Item2;

            // Map absences from DO to PO for displaying to the user
            viewAllTeamsVM.ListOfTeamAbsences = AbsenceMapper.MapListOfDOsToListOfPOs(absenceDOs);

            foreach (var absence in absenceDOs)
            {
                viewAllTeamsVM.Absences.Add(new SelectListItem()
                {
                    Text = absence.Name, Value = absence.Name
                });
            }
            foreach (var item in teamRanker)
            {
                viewAllTeamsVM.TeamRanker.Team.Name     = item.Item1;
                viewAllTeamsVM.TeamRanker.Absence.Point = item.Item2;
            }
            viewAllTeamsVM.User.RoleID_FK = userPO.RoleID_FK;
            viewAllTeamsVM.User.Email     = userPO.Email;
        }
コード例 #2
0
        // TODO: Rename and refactor to handle all role types
        private void AssociateAdminValues(AbsenceViewModel viewAllAbsenceEntries, Tuple <string, decimal> bestStandingTeam, Tuple <string, decimal> bottomStandingTeam, List <IAbsenceDO> allAbsences)
        {
            // Assign values to model for widgets
            viewAllAbsenceEntries.TopTeam.Team.Name               = bestStandingTeam.Item1;
            viewAllAbsenceEntries.TopTeam.Absence.RunningTotal    = bestStandingTeam.Item2;
            viewAllAbsenceEntries.BottomTeam.Team.Name            = bottomStandingTeam.Item1;
            viewAllAbsenceEntries.BottomTeam.Absence.RunningTotal = bottomStandingTeam.Item2;

            // Map absences from DO to PO for displaying to the user
            viewAllAbsenceEntries.ListOfPos = AbsenceMapper.MapListOfDOsToListOfPOs(allAbsences);

            //foreach (var absence in allAbsences)
            //{
            //    viewAllAbsenceEntries.Absences.Add(new SelectListItem() { Text = absence.Name, Value = absence.Name });
            //}
        }
コード例 #3
0
        ///<summary>
        /// Sends the absence form to the database to be added
        /// </summary>
        /// <returns></returns>
        public ActionResult AddAbsenceEntry(AbsenceViewModel iViewModel)
        {
            ActionResult oResponse = null;
            var          userPO    = (IUserPO)Session["UserModel"];

            // User is authenticated(Admin, Service Manager or Team Lead)
            if (userPO.Email != null && userPO.RoleID_FK < (int)RoleEnum.Service_Desk_Employee && userPO.RoleID_FK >= (int)RoleEnum.Administrator)
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        var absenceTypes   = _AbsenceDataAccess.GetAllAbsenceTypes();
                        var absenceTypePOs = AbsenceMapper.MapListOfDOsToListOfPOs(absenceTypes);

                        // Maps absence PO to DO during creation
                        IAbsenceDO lAbsenceForm = AbsenceMapper.MapAbsencePOtoDO(iViewModel.Absence);
                        var        absenceType  = absenceTypePOs.Where(at => at.AbsenceTypeID == iViewModel.Absence.AbsenceTypeID);
                        // Passes form to data access to add event to db
                        PointsDataAccess.AddAbsence(lAbsenceForm, userPO.UserID);
                        oResponse = RedirectToAction("ViewAllAbsence", "Maint");
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.LogError(ex, "AddAbsenceEntry", "Maint");
                        iViewModel.ErrorMessage = "Something went wrong when creating the absence to the system. Please try again.";
                    }
                }
                else
                {
                    oResponse = View(iViewModel);
                }
            }
            else
            {
                // User doesn't have privileges to create an absense entry, redirect to home.
                oResponse = RedirectToAction("Index", "Home");
            }

            return(oResponse);
        }
コード例 #4
0
        //[ValidateAntiForgeryToken]
        ///<summary>
        /// Retrieves form for creating a new absence entry
        /// </summary>
        public ActionResult AddAbsenceEntry()
        {
            ActionResult oResponse = null;
            var          userPO    = (IUserPO)Session["UserModel"];

            if (userPO.Email != null && userPO.RoleID_FK == (int)RoleEnum.Administrator)
            {
                var absenceVM    = new AbsenceViewModel();
                var absenceTypes = _AbsenceDataAccess.GetAllAbsenceTypes();
                var absencePOs   = AbsenceMapper.MapListOfDOsToListOfPOs(absenceTypes);
                var users        = _UserDataAccess.GetAllUsers();
                var userPOs      = UserMapper.MapListOfDOsToListOfPOs(users);
                absenceVM.Users = userPOs.ConvertAll(a =>
                {
                    return(new SelectListItem()
                    {
                        Text = a.UserID.ToString(),
                        Value = a.FirstName + " " + a.LastName,
                        Selected = false
                    });
                });
                absenceVM.AbsenceTypes = absencePOs.ConvertAll(a =>
                {
                    return(new SelectListItem()
                    {
                        Text = a.AbsenceTypeID.ToString(),
                        Value = a.Name,
                        Selected = false
                    });
                });

                oResponse = View(absenceVM);
            }
            else
            {
                // User doesn't have access to create, redirect home
                oResponse = RedirectToAction("Index", "Home");
            }

            return(oResponse);
        }
コード例 #5
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);
        }
コード例 #6
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);
        }