public async Task <ServiceResponse <IEnumerable <GetWarehouseItemDto> > > GetAllWarehouseItemsAsync(PaginationParam pagination, QueryWarehouseItemDto query) { var response = new ServiceResponse <IEnumerable <GetWarehouseItemDto> >(); try { var dbWarehouseItems = await _context.WarehouseItems .Include(x => x.Product).ThenInclude(p => p.Images) .Include(x => x.Product).ThenInclude(p => p.Category) .Where(x => x.Product.IsDeleted == false && (query.Name != null ? x.Product.Name.Contains(query.Name) : true)) .Skip(pagination.Skip()) .Take(pagination.PerPage) .ToListAsync(); var totalItemsQuantity = await _context.WarehouseItems .Include(x => x.Product) .Where(x => x.Product.IsDeleted == false && (query.Name != null ? x.Product.Name.Contains(query.Name) : true)) .CountAsync(); // response.Data = _mapper.Map<IEnumerable<GetWarehouseItemDto>>(dbWarehouseItems); response.Data = dbWarehouseItems.Select(item => _mapper.Map <GetWarehouseItemDto>(item)); response.Pagination = new Pagination { CurrentPage = pagination.Page, TotalPage = pagination.TotalPage(totalItemsQuantity), Count = totalItemsQuantity, }; return(response); } catch (BaseServiceException ex) { response.Success = false; response.Message = ex.ErrorMessage; response.Code = ex.Code; _logger.LogError(ex.Message, ex.StackTrace); return(response); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; response.Code = ErrorCode.WAREHOUSE_ITEM_UNEXPECTED_ERROR; _logger.LogError(ex.Message, ex.StackTrace); return(response); } }
public async Task <ServiceResponse <List <GetManufacturerDto> > > GetAllManufacturerAsync(PaginationParam pagination, QueryManufacturerDto query) { var response = new ServiceResponse <List <GetManufacturerDto> >(); try { var dbManufacturers = await _context.Manufacturers .Where(x => query.Name == null?true : x.Name.Contains(query.Name)) .Skip(pagination.Skip()) .Take(pagination.PerPage) .ToListAsync(); var totalItemsQuantity = await _context.Manufacturers .Where(x => query.Name == null?true : x.Name.Contains(query.Name)) .CountAsync(); response.Data = _mapper.Map <List <GetManufacturerDto> >(dbManufacturers); response.Pagination = new Pagination { CurrentPage = pagination.Page, TotalPage = pagination.TotalPage(totalItemsQuantity), Count = totalItemsQuantity, }; return(response); } catch (BaseServiceException ex) { response.Success = false; response.Message = ex.ErrorMessage; response.Code = ex.Code; _logger.LogError(ex.Message, ex.StackTrace); return(response); } catch (Exception ex) { response.Success = false; response.Message = ex.Message; response.Code = ErrorCode.MANUFACTURER_UNEXPECTED_ERROR; _logger.LogError(ex.Message, ex.StackTrace); return(response); } }