public ActionResult Grid([SessionModelBinder(ProductGridKey)] ActionGridOptions options)
        {
            var filter = new ProductFilter(_dc);

            var query = _dc.Products.Where(ProductSpecification.Search(options.SearchString).Predicate).OrderBy(x => x.ID).AsQueryable();

            query = filter.Init(options).ApplyFilters(query);

            var model = new ProductGridModel(ProductGridKey);

            return(View(new ActionGridView <Product>(model, query).Init(options)));
        }
        public ActionResult GridSetting(ActionGridOptions options, string gridKey)
        {
            var gridModel = new ProductGridModel(ProductGridKey);

            gridModel.Init(options);
            var model = new GridSettingView(gridKey)
            {
                Columns  = gridModel.Columns.OrderBy(x => x.Value.Order).ToDictionary(x => x.Key, x => x.Value as IGridColumn),
                PageSize = gridModel.PageSize
            };

            return(View("GridSetting", model));
        }
Example #3
0
        public List <ProductGridModel> GetGrid()
        {
            List <ProductGridModel> products = new List <ProductGridModel>();

            try
            {
                //open edirik emeliyyati icra etmek ucun
                SqlChecking();
                //queryni seliqelilik olsun deye bele yaziriq
                string query = @"SELECT product.Id as ProductId,product.Name as ProductName," +
                               "product.Price as ProductPrice,category.Id as CategoryId," +
                               "category.Name as CategoryName FROM Products as product" +
                               "INNER JOIN Categories category ON product.CategoryId = category.Id";
                //command ile emri veririk
                using (SqlCommand sqlCommand = new SqlCommand(query, _SqlConnection))
                {
                    using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                    {
                        while (sqlDataReader.Read())
                        {
                            ProductGridModel product = new ProductGridModel()
                            {
                                ProductId    = Convert.ToInt32(sqlDataReader["ProductId"].ToString()),
                                ProductName  = sqlDataReader["ProductName"].ToString(),
                                ProductPrice = Convert.ToInt32(sqlDataReader["ProductPrice"].ToString()),
                                CategoryId   = Convert.ToInt32(sqlDataReader["CategoryId"].ToString()),
                                CategoryName = sqlDataReader["CategoryName"].ToString()
                            };
                            products.Add(product);
                        }
                    }
                }
            }
            catch (SqlException exception)
            {
                throw exception;
            }
            return(products);
        }