public ActionResult DeleteCategory(Category category)
        {
            var manager = new AdminManager();
            manager.DeleteCategory(category.CategoryID);

            return RedirectToAction("CategoryIndex", "Category");
        }
        public ActionResult EditCategory(Category category)
        {
            var manager = new AdminManager();
            manager.EditCategory(category);

            return RedirectToAction("CategoryIndex", "Category");
        }
Example #3
0
 public Category GetCategoryByID(int id)
 {
     var category = new Category();
     using (SqlConnection cn = new SqlConnection(_connectionString))
     {
         var p = new DynamicParameters();
         p.Add("CategoryID", id);
         category = cn.QuerySingle<Category>("GetCategory", p,
             commandType: CommandType.StoredProcedure);
     }
     return category;
 }
Example #4
0
        public void EditCategory(Category category)
        {
            using (SqlConnection cn = new SqlConnection(_connectionString))
            {
                var c = new DynamicParameters();
                c.Add("CategoryID", category.CategoryID);
                c.Add("CategoryName", category.CategoryName);

                cn.Execute("UpdateCategory", c,
                    commandType: CommandType.StoredProcedure);
            }
        }
 public ActionResult CreateCategory(Category category)
 {
     var manager = new AdminManager();
     var categoryCount = manager.GetAllCategories().Count;
     if (categoryCount == 0)
     {
         category.CategoryID = 1;
     }
     else
         category.CategoryID = manager.GetAllCategories().Count + 1;
     manager.AddCategory(category);
     return RedirectToAction("CategoryIndex", "Category");
 }
Example #6
0
        public void AddCategory(Category category)
        {
            if (GetAllCategories().Count != 0)
            {
                category.CategoryID = GetAllCategories().LastOrDefault().CategoryID + 1;
            }
            else
            {
                category.CategoryID = 1;
            }

            _categoryRepo.AddCategory(category);
        }
Example #7
0
        public void CanAddCategory()
        {
            var manager = new AdminManager();
            var toAdd = new Category();
            var count = manager.GetAllCategories().Count;

            toAdd.CategoryID = count + 1;
            toAdd.CategoryName = "TestCategory";

            manager.AddCategory(toAdd);

            var secondCount = manager.GetAllCategories().Count;
            Assert.AreEqual(count + 1, secondCount);
        }
Example #8
0
 public void EditCategory(Category category)
 {
     _categoryRepo.EditCategory(category);
 }
 public void EditCategory(Category category)
 {
     var selectedCategory = _categories.FirstOrDefault(c => c.CategoryID == category.CategoryID);
     selectedCategory.CategoryID = category.CategoryID;
     selectedCategory.CategoryName = category.CategoryName;
 }
 public void AddCategory(Category category)
 {
     _categories.Add(category);
 }