コード例 #1
0
        public ActionResult CreateCategory(Category category)
        {
            if (_categoryService.GetAll().Count(c => c.Name == category.Name) > 0)
                return RedirectToAction("Create",
                        new RouteValueDictionary {
                            { "id", null},
                            { "createError", true } });

            if (ModelState.IsValid)
            {
                _categoryService.Insert(category);
                return RedirectToAction("Index");
            }
            return View(category);
        }
コード例 #2
0
        public ActionResult Delete(int id, Category model)
        {
            try
            {
                    var category = _categoryService.GetById(id);
                    _categoryService.Delete(category);
            }
            catch (DataException)
            {

                return RedirectToAction("Delete",
                    new RouteValueDictionary {
                        { "id", id },
                        { "saveChangesError", true } });
            }

            return RedirectToAction("Index");
        }
コード例 #3
0
 public void Update(Category model)
 {
     if (model == null)
         throw new ArgumentNullException("category");
     categoryRepository.Update(model);
 }
コード例 #4
0
        public ActionResult Edit(Category model)
        {
            if (ModelState.IsValid)
            {
                _categoryService.Update(model);

                return RedirectToAction("Index");
            }

            return View(model);
        }