public ActionResult CheckExistCategories(string category)
 {
     CategoryModel categoryModel = new CategoryModel();
     if (categoryModel.CheckExistedCategory(category))
     {
         return Json(true);
     }
     else
     {
         return Json(false);
     }
 }
 public ActionResult AddCategory(CategoryViewModel categoryViewModel)
 {
     CategoryModel cateModel = new CategoryModel();
     if (cateModel.AddCategory(categoryViewModel.CategoryName, categoryViewModel.Status) == true)
     {
         return RedirectToAction("Index");
     }
     else
     {
         return RedirectToAction("Error");
     }
 }
Esempio n. 3
0
        public ActionResult CategoriesMenu()
        {
            var catModel = new CategoryModel();

            var citems = catModel.ListCategory();

            var cmenu = citems.Select(category => new CategoryMenuViewModel
            {
                Id = category.Id, ImangePath = category.Image, Name = category.CategoryName
            }).ToList();

            return PartialView(cmenu);
        }
 //
 // GET: /Category/
 public ActionResult Index()
 {
     var catModel = new CategoryModel();
     var listCategoryViewModel = new List<CategoryViewModel>();
     foreach (var cte in catModel.ListCategory())
     {
         var categoryViewModel = new CategoryViewModel();
         categoryViewModel.CategoryName = cte.CategoryName;
         categoryViewModel.Status = cte.Status;
         categoryViewModel.Id = cte.Id;
         listCategoryViewModel.Add(categoryViewModel);
     }
     return View(listCategoryViewModel);
 }
        //
        //Get: /Category/CategoryEdit
        public ActionResult UpdateCategory(int id)
        {
            var _catModel = new CategoryModel();
            CategoryViewModel categoryViewModel = new CategoryViewModel();
            foreach (var cate in _catModel.FindCategory(id))
            {
                categoryViewModel.CategoryName = cate.CategoryName;
                categoryViewModel.Status = cate.Status;
            }

            List<SelectListItem> listStatus = new List<SelectListItem>();
            listStatus.Add(new SelectListItem() { Text = "Đang Hoạt Động", Value = "Available", Selected = true });
            listStatus.Add(new SelectListItem() { Text = "Ngưng Hoạt Động", Value = "Not Available", Selected = false });
            ViewBag.Status = listStatus;

            return View(categoryViewModel);
        }
 public ActionResult UpdateCategory(CategoryViewModel categoryViewModel)
 {
     var _catModel = new CategoryModel();
     if (_catModel.Update(categoryViewModel.Id, categoryViewModel.CategoryName, categoryViewModel.Status) == true)
     {
         return RedirectToAction("Index");
     }
     else
     {
         return RedirectToAction("UpdateCategory/" + categoryViewModel.Id);
     }
 }