//C1 //public ActionResult Index() //{ // ViewData["Title"]="Danh sách khóa học"; // //Lấy danh sách chuyên mục // var lstCategory = db.Category.ToList(); // //Lấy danh sách khóa học // var lstCourse = db.Course.ToList(); // return View(Tuple.Create(lstCategory, lstCourse)); //} public ActionResult Index() { List <CategoryModelView> lstModel = new List <CategoryModelView>(); //Lấy danh sách chuyên mục var lstCategory = db.Category.ToList(); if (lstCategory != null) { foreach (var cate in lstCategory) { CategoryModelView model = new CategoryModelView(); model.Id = cate.Id; model.Name = cate.Name; //Lấy danh sách khóa học theo chuyên mục var lstCourse_bien = db.Course.Where(x => x.Category_Id == cate.Id).ToList(); if (lstCourse_bien != null) { model.lstCourse = lstCourse_bien; } lstModel.Add(model); } } return(View(lstModel)); }
public ActionResult Show() { CategoryModelView categoryVm = new CategoryModelView(); categoryVm.Categories = categoryManager.GetAll(); return(View(categoryVm)); }
public IActionResult Index() { //chỉ show danh sách sản phẩm, CategoryInfo sẽ bằng null var datamodel = new CategoryModelView(); datamodel.DataList = _db.Products.Where(x => x.Published == true && x.IsDeleted != true).ToList(); return(View(datamodel)); }
public ActionResult Delete(int Id) { CategoryModelView categoryVm = new CategoryModelView(); Category category = new Category(); category = categoryManager.GetById(Id); categoryVm = Mapper.Map <CategoryModelView>(category); return(View(categoryVm)); }
public ActionResult Show(CategoryModelView categoryVm) { var categories = categoryManager.GetAll(); if (categoryVm.Code != null) { categories = categories.Where(c => c.Code.ToLower().Contains(categoryVm.Code.ToLower())).ToList(); } if (categoryVm.CategoryName != null) { categories = categories.Where(c => c.CategoryName.ToLower().Contains(categoryVm.CategoryName.ToLower())).ToList(); } categoryVm.Categories = categories; return(View(categoryVm)); }
public IActionResult DetailByID(int id) { CategoryModelView datamodel = new CategoryModelView(); List <Category> categoryChild = _db.Categories.Where(x => x.ParentCategoryID == id).ToList(); if (categoryChild != null && categoryChild.Count > 0) { var listIDCate = categoryChild.Select(x => x.ID).ToList(); //x.CategoryID có thể null do int?, .value để không bị null datamodel.DataList = _db.Products.Where(x => (listIDCate.Contains(x.CategoryID.Value) || x.CategoryID == id) && x.Published == true && x.IsDeleted != true).ToList(); } else { datamodel.DataList = _db.Products.Where(x => x.CategoryID == id && x.Published == true && x.IsDeleted != true).ToList(); } datamodel.CategoryInfo = _db.Categories.Find(id); return(View("Index", datamodel)); }
public ActionResult Edit(CategoryModelView categoryVm) { if (ModelState.IsValid) { var category = Mapper.Map <Category>(categoryVm); if (categoryManager.Update(category)) { ViewBag.SuccessMsg = "Updated"; } else { ViewBag.FailMsg = "Failed"; } } else { ViewBag.FailMsg = "Validation Error"; } return(View(categoryVm)); }
public ActionResult Delete(CategoryModelView categoryVm) { if (ModelState.IsValid) { var category = Mapper.Map <Category>(categoryVm); if (categoryManager.Delete(category)) { ViewBag.SuccessMsg = "Deleted!"; } else { ViewBag.ErrorMsg = "Failed!"; } } else { ViewBag.ErrorMsg = "Validation!"; } return(RedirectToAction("Show", "Category")); }
public ActionResult Add() { CategoryModelView categoryVm = new CategoryModelView(); return(View()); }