public async Task <PagingResult <DepartmentDto> > GetAllAsync(int page, int pageSize, string search)
        {
            Expression <Func <Department, bool> > filter = null;

            if (!string.IsNullOrEmpty(search))
            {
                filter = x => x.Name.Contains(search);
            }

            IOrderedQueryable <Department> OrderBy(IQueryable <Department> x)
            {
                return(x.OrderByDescending(y => y.CreatedOn));
            }

            int skip = (page - 1) * pageSize;

            int totalData = await _departmentRepository.CountAsync(filter);

            List <Department> departments = await _departmentRepository.GetAllAsync(filter : filter, orderBy : OrderBy, countSkip : skip, countTake : pageSize);

            return(new PagingResult <DepartmentDto>
            {
                Data = departments.Select(DepartmentMapper.Map).ToList(),
                TotalCount = totalData
            });
        }
Beispiel #2
0
        public async Task CreateDepartment()
        {
            var databaseSizeBeforeCreate = await _departmentRepository.CountAsync();

            // Create the Department
            DepartmentDto _departmentDto = _mapper.Map <DepartmentDto>(_department);
            var           response       = await _client.PostAsync("/api/departments", TestUtil.ToJsonContent(_departmentDto));

            response.StatusCode.Should().Be(HttpStatusCode.Created);

            // Validate the Department in the database
            var departmentList = await _departmentRepository.GetAllAsync();

            departmentList.Count().Should().Be(databaseSizeBeforeCreate + 1);
            var testDepartment = departmentList.Last();

            testDepartment.DepartmentName.Should().Be(DefaultDepartmentName);
        }
Beispiel #3
0
        public async Task CanCount()
        {
            var nrCompanies = await _departmentRepository.CountAsync().ConfigureAwait(false);

            Assert.True(nrCompanies > 0);
        }