예제 #1
0
        public RequestDTO[] GetRequestsForAdmin(string searchKey = null)
        {
            var vacationStatusTypes = _vacationStatusTypes.Get();

            var users = _users.Get();

            bool whereLinq(Employee emp) => (emp.AspNetUser.AspNetRoles.Any(role => role.Name.Equals(RoleEnum.Administrator.ToString())) ||
                                             (emp.EmployeesTeam.Count.Equals(1) &&
                                              emp.EmployeesTeam.First().TeamLeadID.Equals(ReviewerID)) ||
                                             emp.EmployeesTeam.Count.Equals(0)) && emp.Status.Equals(true);

            var employees = _employees.Get(whereLinq);

            if (employees != null)
            {
                var requestsList = _vacations.Get().Join(employees, vac => vac.EmployeeID, emp => emp.EmployeeID, (vac, emp) => new RequestDTO
                {
                    EmployeeID       = emp.EmployeeID,
                    VacationID       = vac.VacationID,
                    Name             = string.Format($"{emp.Name} {emp.Surname}"),
                    TeamName         = emp.EmployeesTeam.Count.Equals(0) ? Empty : emp.EmployeesTeam.First().TeamName,
                    Duration         = vac.Duration,
                    VacationDates    = string.Format($"{vac.DateOfBegin.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)}-{vac.DateOfEnd.ToString("dd/MM/yyyy", CultureInfo.InvariantCulture)}"),
                    EmployeesBalance = emp.VacationBalance,
                    Created          = vac.Created,
                    Status           = vacationStatusTypes.FirstOrDefault(type => type.VacationStatusTypeID.Equals(vac.VacationStatusTypeID)).VacationStatusName,
                }).OrderBy(req => FunctionHelper.VacationSortFunc(req.Status)).ThenBy(req => req.Created).ToArray();

                if (searchKey != null)
                {
                    requestsList = requestsList.Where(x => x.Name.ToLower().Contains(searchKey.ToLower()) || x.TeamName.ToLower().Contains(searchKey.ToLower())).ToArray();
                }

                return(requestsList);
            }

            return(new RequestDTO[0]);
        }
        public ProfileVacationDTO[] GetUserVacationsData(string id)
        {
            var employee         = _employees.GetById(id);
            var vacationStatuses = _vacationStatusTypes.Get();
            var vacationTypes    = _vacationTypes.Get();

            var vacations = _vacations.Get(x => x.EmployeeID.Equals(employee.EmployeeID)).Select(x => new ProfileVacationDTO
            {
                VacationType = vacationTypes.FirstOrDefault(y => y.VacationTypeID.Equals(x.VacationTypeID)).VacationTypeName,
                Comment      = x.Comment,
                DateOfBegin  = x.DateOfBegin,
                DateOfEnd    = x.DateOfEnd,
                Duration     = x.Duration,
                Status       = vacationStatuses.FirstOrDefault(y => y.VacationStatusTypeID.Equals(x.VacationStatusTypeID)).VacationStatusName,
                Created      = x.Created
            }).OrderBy(x => FunctionHelper.VacationSortFunc(x.Status)).ThenBy(x => x.Created).ToArray();

            return(vacations);
        }