/// <summary> /// Recupera os atendentes de forma paginada /// </summary> /// <param name="advancedFilter"></param> /// <returns></returns> public AtendentesEmpresaResponse GetAllPaged(FilterAtendenteEmpresaRequest advancedFilter) { var result = new AtendentesEmpresaResponse(); var sql = string.Empty; var sqlCount = string.Empty; try { using (var conn = CreateConnection()) { result.TotalGeral = (int)conn.ExecuteScalar("SELECT COUNT(*) FROM Atendente_Empresa"); sql = RecuperarQuery(advancedFilter); result.Atendentes = conn.Query <AtendenteEmpresa, Empresa, AtendenteEmpresa>(selectQuery, map: (atendente, empresa) => { atendente.Empresa = empresa; return(atendente); }, splitOn: "id_empresa_entity").Distinct().ToList(); } return(result); } catch (Exception) { throw; } }
/// <summary> /// Monta as clausulas Offset e Fetch Next /// </summary> /// <param name="advancedFilter"></param> /// <returns></returns> private static string BuildOffSetNumRows(FilterAtendenteEmpresaRequest advancedFilter) { if (advancedFilter.NumRows == 0) { return(string.Empty); } var offSetNumRowsClauses = new StringBuilder(); offSetNumRowsClauses.Append(" OFFSET " + advancedFilter.OffSet + " ROWS"); offSetNumRowsClauses.Append(" FETCH NEXT " + advancedFilter.NumRows + " ROWS ONLY"); return(offSetNumRowsClauses.ToString()); }
/// <summary> /// Monta a query /// </summary> /// <param name="advancedFilter"></param> /// <returns></returns> private static string RecuperarQuery(FilterAtendenteEmpresaRequest advancedFilter) { var sql = new StringBuilder(); var selectClause = string.Empty; var orderByClause = string.Empty; var offSetNumRows = string.Empty; selectClause = selectQuery; orderByClause = BuildOrderBy(); offSetNumRows = BuildOffSetNumRows(advancedFilter); sql.Append(selectClause); sql.Append(orderByClause); sql.Append(offSetNumRows); return(sql.ToString()); }
public IHttpActionResult GetAllPaged(FilterAtendenteEmpresaRequest advancedFilter) { try { var result = _atendenteEmpresaBusiness.GetAllPaged(advancedFilter); var lista = result.Atendentes.ToList().Select(Mapper.Map <AtendenteEmpresa, AtendenteEmpresaResponse>); var totalGeral = result.TotalGeral; var totalLinhas = lista.Count(); //Monta response _result = Ok(Retorno <IEnumerable <AtendenteEmpresaResponse> > .Criar(true, "Consulta Realizada Com Sucesso", lista, totalGeral)); //Retorna o response return(_result); } catch (Exception) { throw new HttpResponseException(HttpStatusCode.InternalServerError); } }
public AtendentesEmpresaResponse GetAllPaged(FilterAtendenteEmpresaRequest advancedFilter) { return(_repository.GetAllPaged(advancedFilter)); }