Exemple #1
0
        public List <ProductModels> GetProductList(int?page, int?limit, string sortBy, string direction, string searchString, out int total)
        {
            var    map           = new List <ProductModels>();
            var    listCode      = new List <ProductModels>();
            var    listCodeBarra = new List <ProductModels>();
            double codigo        = 0;

            map = MapProduct();

            if (!string.IsNullOrWhiteSpace(searchString))
            {
                try
                {
                    codigo = double.Parse(searchString);
                }
                catch (FormatException e)
                {
                    codigo = 0;
                }

                if (codigo != 0)
                {
                    listCode      = map.Where(p => (p.Codigo == codigo)).ToList();
                    listCodeBarra = map.Where(p => (p.CodigoBarra == searchString)).ToList();
                }

                else
                {
                    map = GetProductListQuery(map, searchString);
                }
            }

            if (listCode.Count != 0)
            {
                map = listCode;
            }

            if (listCodeBarra.Count != 0)
            {
                map = listCodeBarra;
            }

            total = map.Count();

            var productQueryable = map.AsQueryable();


            if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
            {
                if (direction.Trim().ToLower() == "asc")
                {
                    productQueryable = SortHelper.OrderBy(productQueryable, sortBy);
                }
                else
                {
                    productQueryable = SortHelper.OrderByDescending(productQueryable, sortBy);
                }
            }
            if (page.HasValue && limit.HasValue)
            {
                int start = (page.Value - 1) * limit.Value;
                productQueryable = productQueryable.Skip(start).Take(limit.Value);
            }

            return(productQueryable.ToList());
        }
Exemple #2
0
        public List <ProductModels> GetProductList(int?page, int?limit, string sortBy, string direction, string searchString, string idCategory, string idSubCategory, string idTamañoMascota, out int total)
        {
            try
            {
                int category      = 0;
                int subCategory   = 0;
                int tamañoMascota = 0;

                var map = new List <ProductModels>();

                map = MapProduct();

                if (!String.IsNullOrEmpty(idCategory) && idCategory != "0")
                {
                    category = Convert.ToInt16(idCategory);
                    map      = map.Where(x => x.IdCategory == category).ToList();
                }

                if (!String.IsNullOrEmpty(idSubCategory) && idSubCategory != "0")
                {
                    subCategory = Convert.ToInt16(idSubCategory);
                    map         = map.Where(x => x.IdSubCategory == subCategory).ToList();
                }

                if (!String.IsNullOrEmpty(idTamañoMascota) && idTamañoMascota != "0")
                {
                    tamañoMascota = Convert.ToInt16(idTamañoMascota);
                    map           = map.Where(x => x.IdTamanoMascota == tamañoMascota).ToList();
                }

                if (!string.IsNullOrWhiteSpace(searchString))
                {
                    map = GetProductListQuery(map, searchString);
                }

                total = map.Count();


                var productQueryable = map.AsQueryable();


                if (!string.IsNullOrEmpty(sortBy) && !string.IsNullOrEmpty(direction))
                {
                    if (direction.Trim().ToLower() == "asc")
                    {
                        productQueryable = SortHelper.OrderBy(productQueryable, sortBy);
                    }
                    else
                    {
                        productQueryable = SortHelper.OrderByDescending(productQueryable, sortBy);
                    }
                }
                if (page.HasValue && limit.HasValue)
                {
                    int start = (page.Value - 1) * limit.Value;
                    productQueryable = productQueryable.Skip(start).Take(limit.Value);
                }

                return(productQueryable.ToList());
            }

            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }