コード例 #1
0
        public Category GetCategoryById(int catId)
        {
            var category = new Category();
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                var cmd = new SqlCommand("GetCategoryById", cn) { CommandType = CommandType.StoredProcedure };
                cmd.Parameters.AddWithValue("@CategoryId", catId);

                cn.Open();

                using (var dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var cat = new Category
                        {
                            CategoryId = dr.GetInt32(0),
                            CategoryName = dr.GetString(1)
                        };
                        return cat;
                    }
                }
            }
            return null;
        }
コード例 #2
0
 public void DeleteCategory(Category category)
 {
     using (var cn = new SqlConnection(Settings.GetConnectionString()))
     {
         var cmd = new SqlCommand("DeleteCategory", cn) { CommandType = CommandType.StoredProcedure };
         cmd.Parameters.AddWithValue("@CategoryId", category.CategoryId);
         cn.Open();
         cmd.ExecuteNonQuery();
     }
 }
コード例 #3
0
        public ActionResult Edit(int id, Category cat)
        {
            try
            {
                // TODO: Add update logic here

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #4
0
        public ActionResult Create(Category cat)
        {
            try
            {
                category.AddCategory(cat);

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #5
0
        public List<Category> GetAllCategories()
        {
            var category = new List<Category>();
            using (var cn = new SqlConnection(Settings.GetConnectionString()))
            {
                var cmd = new SqlCommand("GetAllCategories", cn) { CommandType = CommandType.StoredProcedure };

                cn.Open();

                using (var dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        var cat = new Category
                        {
                            CategoryId = dr.GetInt32(0),
                            CategoryName = dr.GetString(1)
                        };
                        category.Add(cat);
                    }
                }
            }
            return category;
        }
コード例 #6
0
 public void EditCategory(Category category)
 {
     _categoryRepo.EditCategory(category);
 }
コード例 #7
0
 public void DeleteCategory(Category category)
 {
     _categoryRepo.DeleteCategory(category);
 }
コード例 #8
0
 public void AddCategory(Category category)
 {
     _categoryRepo.AddCategory(category);
 }