예제 #1
0
        public async Task <EmployeePagedList> QueryAsync(int clientId, int userId, int page, int size, string searchText, int?placeId, int?departmentId, int?status)
        {
            if (!await _permissionManager.HasPermission(clientId, userId, Permission.CanViewEmployee))
            {
                throw new Exception("User has not permission to perform this operation");
            }

            var employeesList = await _employeeRepository.QueryAsync(clientId);

            if (placeId != null)
            {
                employeesList = employeesList.Where(e => e.PlaceId == placeId.Value);
            }

            if (departmentId != null)
            {
                employeesList = employeesList.Where(e => e.DepartmentId == departmentId.Value);
            }

            if (status != null)
            {
                employeesList = employeesList.Where(e => e.Status == status.Value);
            }

            if (!string.IsNullOrWhiteSpace(searchText))
            {
                employeesList = employeesList.Where(e => e.Email.Contains(searchText) || e.FirstName.Contains(searchText) || e.LastName.Contains(searchText));
            }

            var employees = employeesList.OrderBy(o => o.FirstName)
                            .Skip((page - 1) * size)
                            .Take(size);

            var count = employeesList.Count();

            var pagedList = new EmployeePagedList();

            pagedList.Records      = employees.ToList().Select(u => _employeeMapper.ConvertToListModel(u)).ToList();
            pagedList.TotalRecords = count;

            return(pagedList);
        }