Esempio n. 1
0
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated)
            {
                if (User.IsInRole("Admin"))
                {
                    ViewData["showRequests"] = false;
                    return(View());
                }
                else
                {
                    string        idLoggedInUser = User.Identity.GetUserId();
                    EmployeeModel employee       = employeeRepository.GetEmployeeByUserId(idLoggedInUser);
                    List <VacationRequestModel> allVacationRequests;
                    allVacationRequests = new List <VacationRequestModel>();

                    if (employee.Position == PositionEnum.TeamLead)
                    {
                        List <TeamModel> teamsLeadByCurrentEmployee = teamRepository.GetAllTeamsByTeamLeadID(employee.IDEmployee);
                        foreach (TeamModel team in teamsLeadByCurrentEmployee)
                        {
                            List <VacationRequestModel> vacationsInTeam = vacationRequestRepository.GetAllVacationRequestsByTeamIdFirstStatus(team.IDTeam);
                            foreach (VacationRequestModel vacation in vacationsInTeam)
                            {
                                allVacationRequests.Add(vacation);
                            }
                        }
                    }

                    if (employee.Position == PositionEnum.BusinessUnitManager)
                    {
                        List <BusinessUnitModel> businessManagedByCurrentEmployee = businessUnitRepository.GetBusinessUnitsByManagerId(employee.IDEmployee);
                        foreach (BusinessUnitModel business in businessManagedByCurrentEmployee)
                        {
                            List <VacationRequestModel> vacationsInBusinessUnit = vacationRequestRepository.GetAllVacationRequestsByBusinessUnitIdSecondStatus(business.IDBusinessUnit);
                            foreach (VacationRequestModel vacation in vacationsInBusinessUnit)
                            {
                                allVacationRequests.Add(vacation);
                            }
                        }
                    }

                    if (allVacationRequests.Count == 0)
                    {
                        ViewData["showRequests"] = false;
                    }
                    else
                    {
                        ViewData["showRequests"] = true;
                    }
                    return(View());
                }
            }
            ViewData["showRequests"] = false;
            return(View());
        }
        public ActionResult PendingList()
        {
            string        idLoggedInUser = User.Identity.GetUserId();
            EmployeeModel employee       = employeeRepository.GetEmployeeByUserId(idLoggedInUser);
            List <VacationRequestModel> allVacationRequests;

            if (employee == null)
            {
                allVacationRequests = vacationRequestRepository.GetAllVacationRequests();
                return(View("Index", allVacationRequests));
            }
            if (employee.Position == PositionEnum.TeamLead)
            {
                allVacationRequests = new List <VacationRequestModel>();
                List <TeamModel> teamsLeadByCurrentEmployee = teamRepository.GetAllTeamsByTeamLeadID(employee.IDEmployee);
                foreach (TeamModel team in teamsLeadByCurrentEmployee)
                {
                    List <VacationRequestModel> vacationsInTeam = vacationRequestRepository.GetAllVacationRequestsByTeamIdFirstStatus(team.IDTeam);
                    foreach (VacationRequestModel vacation in vacationsInTeam)
                    {
                        allVacationRequests.Add(vacation);
                    }
                }
                return(View("PendingList", allVacationRequests));
            }
            if (employee.Position == PositionEnum.BusinessUnitManager)
            {
                allVacationRequests = new List <VacationRequestModel>();
                List <BusinessUnitModel> businessManagedByCurrentEmployee = businessUnitRepository.GetBusinessUnitsByManagerId(employee.IDEmployee);
                foreach (BusinessUnitModel business in businessManagedByCurrentEmployee)
                {
                    List <VacationRequestModel> vacationsInBusinessUnit = vacationRequestRepository.GetAllVacationRequestsByBusinessUnitIdSecondStatus(business.IDBusinessUnit);
                    foreach (VacationRequestModel vacation in vacationsInBusinessUnit)
                    {
                        allVacationRequests.Add(vacation);
                    }
                }
                return(View("PendingList", allVacationRequests));
            }
            allVacationRequests = vacationRequestRepository.GetAllVacationRequestsByEmployeeId(employee.IDEmployee);
            return(View("PendingList", allVacationRequests));
        }