Esempio n. 1
0
 public JsonResult List(Hubs.FilterSortConfig config, int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
 {
     try
     {
         List <ViewModels.ProductViewModel> products = new List <ViewModels.ProductViewModel>();
         var userClaimPrincipal = User as ClaimsPrincipal;
         int total = 0;
         if (userClaimPrincipal.IsInRole("Admin"))
         {
             products = productRepository.GetProducts(jtStartIndex, jtPageSize, jtSorting, config);
             total    = productRepository.GetProductsTotal(0);
         }
         else
         {
             var uservm = userRepository.GetUser(User.Identity.Name);
             products = productRepository.GetProducts(uservm.Id, jtStartIndex, jtPageSize, jtSorting, config);
             total    = productRepository.GetProductsTotal(uservm.Id);
         }
         return(Json(new { Result = "OK", Records = products, TotalRecordCount = total }));
     }
     catch (Exception ex)
     {
         return(Json(new { Result = "ERROR", Message = ex.Message }));
     }
 }
Esempio n. 2
0
        public List <ProductModel> GetProducts(int userId, int startIndex, int pageSize, string sorting, Hubs.FilterSortConfig config)
        {
            var prodq = _db.Products.Where(ln => ln.Owner.ID == userId);

            if (config.Filters != null)
            {
                foreach (var filter in config.Filters)
                {
                    prodq = Filter(prodq, filter);
                }
            }

            if (!string.IsNullOrEmpty(sorting))
            {
                prodq = Sort(prodq, sorting);
            }
            else
            {
                prodq.OrderBy(ln => ln.ID);
            }

            prodq.Skip(startIndex).Take(pageSize);

            return(prodq.ToList());
        }
Esempio n. 3
0
        public List <ProductModel> GetProducts(int StartIndex, int PageSize, string sorting, Hubs.FilterSortConfig config)
        {
            IQueryable <ProductModel> prodq = _db.Products;

            if (config.Filters != null)
            {
                foreach (var filter in config.Filters)
                {
                    prodq = Filter(prodq, filter);
                }
            }

            if (!string.IsNullOrEmpty(sorting))
            {
                prodq = Sort(prodq, sorting);
            }
            else
            {
                prodq.OrderBy(ln => ln.ID);
            }

            return(prodq.Skip(StartIndex).Take(PageSize).ToList());
        }
Esempio n. 4
0
        public List <ViewModels.ProductViewModel> GetProducts(int userId, int startIndex, int pageSize, string sorting, Hubs.FilterSortConfig config)
        {
            var products = productContext.GetProducts(userId, startIndex, pageSize, sorting, config);

            return(products.ToProductViewModels());
        }