Esempio n. 1
0
        // GET: api/Categoria
        public IHttpActionResult Get()
        {
            CategoriasResponse cResponse = new CategoriasResponse();

            try
            {
                List <Categoria> lista = Categoria.Listar();
                cResponse.Categorias = new List <CategoriaTO>();
                foreach (Categoria c in lista)
                {
                    CategoriaTO cTO = new CategoriaTO();
                    cTO.Id   = c.Id;
                    cTO.Nome = c.Nome;
                    cResponse.Categorias.Add(cTO);
                }
            }
            catch (Exception ex)
            {
                cResponse.Status   = -1;
                cResponse.Detalhes = ex.Message;
            }

            return(Ok(cResponse));
        }
        /// <summary>
        /// Recupera de forma paginada as categorias
        /// </summary>
        /// <param name="advancedFilter"></param>
        /// <returns></returns>
        public CategoriasResponse GetAllPaged(FilterCategoriaRequest advancedFilter)
        {
            var result   = new CategoriasResponse();
            var sql      = string.Empty;
            var sqlCount = string.Empty;

            try
            {
                using (var conn = CreateConnection())
                {
                    result.TotalGeral = (int)conn.ExecuteScalar("SELECT COUNT(*) FROM Categoria");

                    sql = RecuperarQuery(advancedFilter);

                    result.Categorias = conn.Query <Categoria>(sql).Distinct().ToList();
                }

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }