예제 #1
0
 public Paganation <EmployeeDTO> GetAll(SerachPaganationDTO <EmployeeDTO> dto)
 {
     try
     {
         var a              = new EmployeeDTO();
         var listEmployee   = _repository.Queryable();
         var listDepartment = _repositoryDepartment.Queryable();
         var listPosition   = _repositoryPosition.Queryable();
         var employeeDTO    =
             (from emp in listEmployee
              from dep in listDepartment
              from pos in listPosition
              where emp.DepartmentId == dep.Id && emp.PositionId == pos.Id
              select new EmployeeDTO
         {
             Id = emp.Id,
             Name = emp.Name,
             PositionName = pos.Name,
             DepartmentName = dep.Name
         }).OrderBy(it => it.DepartmentName)
             .ThenBy(it => it.Name)
             .Take(dto.Take)
             .Skip(dto.Skip)
             .ToList();
         var result = _mapper.Map <SerachPaganationDTO <EmployeeDTO>, Paganation <EmployeeDTO> >(dto);
         result.Data = employeeDTO;
         return(result);
     }
     catch (Exception ex)
     {
         throw new Exception($"Couldn't retrieve entities: {ex.Message}");
     }
 }
예제 #2
0
        public IActionResult GetAll([FromQuery] SerachPaganationDTO <EmployeeDTO> dto)
        {
            var result = _employeeService.GetAll(dto);

            if (result == null)
            {
                return(Ok(false));
            }
            return(Ok(result));
        }
예제 #3
0
        public Paganation <ReadProductDto> GetPage(int index)
        {
            //var PageInfo = new PaginationInfo() { index = index };
            //PageInfo.totalItem = repository.Queryable().Count();

            //var Data = repository.Queryable().Skip(0).Take(8).ToList();
            //PageInfo.data = mapper.Map<List<Product>, List<ReadProductDto>>(Data);

            //var PageResult = mapper.Map<PaginationInfo, ReadPagination>(PageInfo);
            //return PageResult;
            var PageInfo = new SerachPaganationDTO <ReadProductDto>()
            {
                PageNumber = index
            };
            var DataProduct        = repository.Queryable().Take(PageInfo.Take).Skip(PageInfo.Skip).ToList();
            var DataReadProductDto = mapper.Map <List <Product>, List <ReadProductDto> >(DataProduct);
            var TotalItem          = repository.Queryable().Count();
            var Result             = mapper.Map <SerachPaganationDTO <ReadProductDto>, Paganation <ReadProductDto> >(PageInfo);

            Result.InputData(TotalItem, DataReadProductDto);

            return(Result);
        }