public ActionResult GetPagedList([FromQuery] ProductoFilter filter) { try { var empty = new List <Producto>(); var data = productoService.GetPaged(filter); var result = PagedList <ProductoDto> .Create((IQueryable <ProductoDto>) data.AsQueryable(), filter.PageNumber, filter.PageSize); if (result == null) { return(BadRequest("No existen datos con este filtro")); } var pagination = new { totalCount = result.TotalCount, pageSize = result.PageSize, currentPage = result.CurrentPage, totalPage = result.TotalPages, HasNext = result.HasNext, HasPrevious = result.HasPrevious, data = result }; return(Ok(pagination)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public List <Producto> GetAllLazy(ProductoFilter filter, out int filteredResultsCount, out int totalResultsCount) { var result = new List <Producto>(); var outtotalResultsCount = 0; var outfilteredResultsCount = 0; filter.search = filter.search ?? ""; try { using (IDatabase db = DbContext.GetInstance()) { #region Select All var query = db.Query <Producto>(); query.Include(p => p.TipoActividad); query.Include(p => p.Distrito); query.Include(p => p.FotoPrincipal); query.Where(s => !s.isDeleted); if (!string.IsNullOrEmpty(filter.distrito)) { query.Where(p => p.fkDistrito.In(filter.distrito.SplitInt(","))); } if (!string.IsNullOrEmpty(filter.tipoActividad)) { query.Where(p => p.fkTipoActividad.In(filter.tipoActividad.SplitInt(","))); } query.Where(w => w.cProducto.ToLower().Contains(filter.search) || w.cTags.ToLower().Contains(filter.search)); query.OrderBy(p => p.cProducto); var t = query.ToPage((filter.start * filter.length) / filter.length, filter.length); outtotalResultsCount = db.Query <Producto>().Count(c => !c.isDeleted); outfilteredResultsCount = (int)t.TotalItems; result = t.Items; #endregion } } catch (Exception e) { Logger.Error(e.Message); } totalResultsCount = outtotalResultsCount; filteredResultsCount = outfilteredResultsCount; return(result); }
public ProductoSpec(ProductoFilter filter) { Query.OrderBy(x => x.Nombre).ThenByDescending(x => x.Id); if (filter.IsPagingEnabled) { Query.Skip(PaginationHelper.CalculateSkip(filter)) .Take(PaginationHelper.CalculateTake(filter)); } if (!string.IsNullOrEmpty(filter.Nombre)) { Query.Search(x => x.Nombre.ToLower(), "%" + filter.Nombre.ToLower() + "%"); } }
public JsonResult ListadoLazy(ProductoFilter model) { var dataResult = _bl.GetAllLazy(model, out var filteredResultsCount, out var totalResultsCount); dataResult.Where(p => p.cObservacionPrincipal.Length > 130).ForEach(p => { p.cObservacionPrincipal = p.cObservacionPrincipal.Substring(0, 130) + "..."; }); return(Json(new { recordsTotal = totalResultsCount, recordsFiltered = filteredResultsCount, data = dataResult }, JsonRequestBehavior.AllowGet)); }
public static List <BaseList> ListProductosAutocomplete(ProductoFilter filter) { List <BaseList> List = new List <BaseList>(); using (var con = GetConnection.UNITE()) { bool openConn = (con.State == ConnectionState.Open); if (!openConn) { con.Open(); } using (var cmd = new SqlCommand("usp_Producto_Autocomplete", con)) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@pIdEmpresa", SqlDbType.VarChar).Value = filter.IdEmpresa; cmd.Parameters.Add("@pTipo", SqlDbType.TinyInt).Value = filter.Tipo; cmd.Parameters.Add("@pDescripcion", SqlDbType.VarChar).Value = filter.Descripcion ?? string.Empty; using (var dr = cmd.ExecuteReader()) { while (dr.Read()) { string descripcion = DataReader.GetStringValue(dr, "Descripcion"); string precio = DataReader.GetDecimalValue(dr, "Precio").ToString("#.#0"); List.Add(new BaseList { Codigo = DataReader.GetStringValue(dr, "IdProducto"), Descripcion = string.Format("{0} - S/. {1}", descripcion, precio) }); } dr.Close(); } cmd.Dispose(); } if (con.State == ConnectionState.Open) { con.Close(); } } return(List); }
public IEnumerable <Producto> GetPaged(ProductoFilter Filtro) { var producto = base.FindAll(); if (Filtro.nombre != null) { producto = producto.Where(c => c.Nombre == Filtro.nombre); } if (Filtro.Codigo != null) { producto = producto.Where(c => c.CodigoProducto == Filtro.Codigo); } if (Filtro.StartDate == null && Filtro.EndDate != null) { throw new ArgumentException("Se necesita la fecha de inicio para buscar"); } if (Filtro.StartDate != null && Filtro.EndDate == null) { throw new ArgumentException("Se necesita la fecha final para buscar"); } if (Filtro.StartDate != null && Filtro.EndDate != null && producto.Count() > 0) { if (Filtro.EndDate < Filtro.StartDate) { throw new ArgumentException("La fecha inicio no puede ser mayor que la fecha final"); } producto = producto.Where(c => c.CreateDate >= Filtro.StartDate && c.CreateDate <= Filtro.EndDate); if (producto.Count() == 0) { throw new ArgumentException("No existen datos con los parametros suministrado por el usuario"); } } return(producto); }
public List <Producto> GetAllLazy(ProductoFilter filter, out int filteredResultsCount, out int totalResultsCount) { return(_da.GetAllLazy(filter, out filteredResultsCount, out totalResultsCount)); }