public async Task <IActionResult> GetStockItemsAsync(int pageSize = 10, int pageNumber = 1, int?lastEditedBy = null, int?colorID = null, int?outerPackageID = null, int?supplierID = null, int?unitPackageID = null) { Logger?.LogDebug("'{0}' has been invoked", nameof(GetStockItemsAsync)); var response = new PagedResponse <StockItem>(); try { // Get the "proposed" query from repository var query = DbContext.GetStockItems(); // Set paging values response.PageSize = pageSize; response.PageNumber = pageNumber; // Get the total rows response.ItemsCount = await query.CountAsync(); // Get the specific page from database response.Model = await query.Paging(pageSize, pageNumber).ToListAsync(); response.Message = string.Format("Page {0} of {1}, Total of products: { 2}.", pageNumber, response.PageCount, response.ItemsCount); Logger?.LogInformation("The stock items have been retrieved successfully."); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = "There was an internal error,p lease contact to technical support."; Logger?.LogCritical("There was an error on '{0}' invocation: { 1} ", nameof(GetStockItemsAsync), ex); } return(response.ToHttpResponse()); }
public async Task <IActionResult> GetStockItemsAsync(int pageSize = 10, int pageNumber = 1, int?lastEditedBy = null, int?colorID = null, int?outerPackageID = null, int?supplierID = null, int?unitPackageID = null) { Logger?.LogDebug("'{0}' foi chamada", nameof(GetStockItemsAsync)); var response = new PagedResponse <StockItem>(); try { // Get da query "proposta" do repositório var query = _context.GetStockItems(); // Seta o valor das páginas response.PageSize = pageSize; response.PageNumber = pageNumber; // Get o total de linhas response.ItemsCount = await query.CountAsync(); // Get a página expecífica do banco response.Model = await query.Paging(pageSize, pageNumber).ToListAsync(); response.Message = string.Format("Página {0} de {1}, Total de produtos: {2}.", pageNumber, response.PageCount, response.ItemsCount); Logger?.LogInformation("Os itens foram trazidos com sucesso."); } catch (Exception ex) { response.DidError = true; response.ErrorMessage = "Houve um erro interno, por favor contate o suporte."; Logger?.LogCritical("Houve um erro na chamada '{0}' invocando: {1} ", nameof(GetStockItemsAsync), ex); } return(response.ToHttpResponse()); }