public IActionResult GetCategories() { // ViewBag.Categories = dbContext.Categories.ToList(); Console.WriteLine(" Passing at Categories - HttpGet ------"); CategoriesPageModel cate = new CategoriesPageModel(); cate.Categories = dbContext.Categories.ToList(); return(View("Categories", cate)); }
/// <summary> /// 为分类页面准备数据 /// </summary> /// <param name="category">类别ID</param> /// <param name="type">是否是最末分类 0 大类 1最末分类</param> /// <returns></returns> public CategoriesPageModel GetAllCategory(int category, int type) { CategoriesPageModel categorypagemodel = new CategoriesPageModel(); if (type == 0) { DataTable dt = dal.GetChildCategoryList(category);//得到分类消息 List <CategoriesModel> categorylist = new List <CategoriesModel>(); foreach (DataRow item in dt.Rows) { CategoriesModel model = new CategoriesModel(); model.cateid = int.Parse(item["cateid"].ToString()); model.name = item["name"].ToString(); model.path = item["path"].ToString(); model.parentid = int.Parse(item["parentid"].ToString()); categorylist.Add(model); } categorypagemodel.categories = categorylist; categorypagemodel.brands = null; } else { DataTable brandt = dal.GetBrandsByBlogcategory(category);//品牌信息 List <BrandsModel> brandslist = new List <BrandsModel>(); foreach (DataRow item in brandt.Rows) { BrandsModel model = new BrandsModel(); model.brandid = int.Parse(item["brandid"].ToString()); model.name = item["name"].ToString(); model.BelongsCategoryID = int.Parse(item["BelongsCategoryID"].ToString()); brandslist.Add(model); } categorypagemodel.brands = brandslist; categorypagemodel.categories = null; } categorypagemodel.Products = productdal.GetProductsBycategory(category, type, 0); //商品信息 DataTable prodt = productdal.GetProductsBycategory(category, type, 1); //热卖商品信息 List <ProductsModel> promodel = new List <ProductsModel>(); foreach (DataRow item in prodt.Rows) { ProductsModel model = new ProductsModel(); model.ShowimgPath = item["ShowimgPath"].ToString(); model.Shopprice = decimal.Parse(item["Shopprice"].ToString()); model.pid = int.Parse(item["pid"].ToString()); model.ProductName = item["ProductName"].ToString(); promodel.Add(model); } categorypagemodel.HotProducts = promodel; return(categorypagemodel); }
public IActionResult AddCategory(CategoriesPageModel cate) { //in this list we add the new Category, then redirect to the Categories page again if (ModelState.IsValid) { dbContext.Categories.Add(cate.OneCategory); dbContext.SaveChanges(); return(Redirect("Categories")); } else { cate.Categories = dbContext.Categories.ToList(); Console.WriteLine(" Passing at Categories - Error in model state ------"); return(View("Categories", cate)); } }
public object LoadModel() { // 根据用户选择的界面风格,计算实现要呈现的页面路径。 string papeUrl = this.GetTargetPageUrl("Categories.aspx"); if (this.IsStyle2) { // Style2 风格下,页面不需要绑定数据。数据由JS通过AJAX方式获取 return(new PageResult(papeUrl, null)); } // 为Style1 风格获取数据。 CategoriesPageModel result = new CategoriesPageModel(); result.List = BllFactory.GetCategoryBLL().GetList(); return(new PageResult(papeUrl, result)); }