Esempio n. 1
0
        public ActionResult GetProducts(JqGridRequest request, string hiddenColumns)
        {
            var list = ProductDataSource.LatestProducts;

            var pageIndex    = request.page - 1;
            var pageSize     = request.rows;
            var totalRecords = list.Count;
            var totalPages   = (int)Math.Ceiling(totalRecords / (float)pageSize);

            var productsQuery = list.AsQueryable();

            productsQuery = new JqGridSearch(request, this.Request.Form, DateTimeType.Persian).ApplyFilter(productsQuery);
            productsQuery = productsQuery.OrderBy(request.sidx + " " + request.sord);

            if (string.IsNullOrWhiteSpace(request.oper))
            {
                productsQuery = productsQuery
                                .Skip(pageIndex * pageSize)
                                .Take(pageSize);
            }
            else if (request.oper == "excel")
            {
                productsQuery = productsQuery
                                .Skip(pageIndex * pageSize);
            }

            var productsList = productsQuery.ToList();

            if (!string.IsNullOrWhiteSpace(request.oper) && request.oper == "excel")
            {
                new ProductsPdfReport().CreatePdfReport(productsList,
                                                        hiddenColumns == null ? new string[] { } : hiddenColumns.Split(','));
            }

            var productsData = new JqGridData
            {
                Total   = totalPages,
                Page    = request.page,
                Records = totalRecords,
                Rows    = (productsList.Select(product => new JqGridRowData
                {
                    Id = product.Id,
                    RowCells = new List <object>
                    {
                        product.Id.ToString(CultureInfo.InvariantCulture),
                        product.Name,
                        product.AddDate.ToPersianDate(),
                        product.Price.ToString(CultureInfo.InvariantCulture)
                    }
                })).ToArray()
            };

            return(Json(productsData, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult GetProducts(JqGridRequest request)
        {
            var list = ProductDataSource.LatestProducts;

            var pageIndex = request.page - 1;
            var pageSize = request.rows;
            var totalRecords = list.Count;
            var totalPages = (int)Math.Ceiling(totalRecords / (float)pageSize);

            var productsQuery = list.AsQueryable();

            productsQuery = new JqGridSearch().ApplyFilter(productsQuery, request, this.Request.Form);
            productsQuery = productsQuery.OrderBy(request.sidx + " " + request.sord);

            if (string.IsNullOrWhiteSpace(request.oper))
            {
                productsQuery = productsQuery
                                    .Skip(pageIndex * pageSize)
                                    .Take(pageSize);
            }
            else if (request.oper == "excel")
            {
                productsQuery = productsQuery
                                    .Skip(pageIndex * pageSize);
            }

            var productsList = productsQuery.ToList();

            if (!string.IsNullOrWhiteSpace(request.oper) && request.oper == "excel")
            {
                new ProductsPdfReport().CreatePdfReport(productsList);
            }

            var productsData = new JqGridData
            {
                Total = totalPages,
                Page = request.page,
                Records = totalRecords,
                Rows = (productsList.Select(product => new JqGridRowData
                {
                    Id = product.Id,
                    RowCells = new List<string>
                    {
                        product.Id.ToString(CultureInfo.InvariantCulture),
                        product.Name,
                        product.AddDate.ToString("yyyy-MM-dd"),
                        product.Price.ToString(CultureInfo.InvariantCulture)
                    }
                })).ToArray()
            };

            return Json(productsData, JsonRequestBehavior.AllowGet);
        }
Esempio n. 3
0
        public async Task <DataGridViewModel <ProductDataGridViewModel> > GetDataGridSource(string orderBy, JqGridRequest request, NameValueCollection form, DateTimeType dateTimeType, int page, int pageSize)
        {
            var usersQuery = _products.AsQueryable();

            var query = new JqGridSearch(request, form, dateTimeType).ApplyFilter(usersQuery);

            var dataGridModel = new DataGridViewModel <ProductDataGridViewModel>
            {
                Records = await query.AsQueryable().OrderBy(orderBy)
                          .Skip(page * pageSize)
                          .Take(pageSize).ProjectTo <ProductDataGridViewModel>(null, _mappingEngine).ToListAsync(),

                TotalCount = await query.AsQueryable().OrderBy(orderBy).CountAsync()
            };

            return(dataGridModel);
        }
Esempio n. 4
0
        public ActionResult GetProducts(JqGridRequest request)
        {
            var list = ProductDataSource.LatestProducts;

            var pageIndex    = request.page - 1;
            var pageSize     = request.rows;
            var totalRecords = list.Count;
            var totalPages   = (int)Math.Ceiling(totalRecords / (float)pageSize);

            var productsQuery = list.AsQueryable();

            //System.Collections.Generic.List`1[jqGrid03.Models.Product].Where(Param_0 => Param_0.Code.Value.ToString().Equals(null))}
            productsQuery = new JqGridSearch(request, this.Request.Form, DateTimeType.Persian).ApplyFilter(productsQuery);
            var productsList = productsQuery.OrderBy(request.sidx + " " + request.sord)
                               .Skip(pageIndex * pageSize)
                               .Take(pageSize)
                               .ToList();

            var productsData = new JqGridData
            {
                Total   = totalPages,
                Page    = request.page,
                Records = totalRecords,
                Rows    = (productsList.Select(product => new JqGridRowData
                {
                    Id = product.Id,
                    RowCells = new List <object>
                    {
                        product.Id.ToString(CultureInfo.InvariantCulture),
                        product.Name,
                        product.Supplier.CompanyName,
                        product.Category.Name,
                        product.Price.ToString(CultureInfo.InvariantCulture),
                        product.Code.HasValue? product.Code.Value.ToString("D") : string.Empty
                    }
                })).ToArray()
            };

            return(Json(productsData, JsonRequestBehavior.AllowGet));
        }