public ActionResult Delete(int id)
        {
            Category cat = _itemsRepository.GetCategory(id);
            if (cat != null)
            {
                if (cat.CanBeDeleted == false)
                {
                    throw new InvalidOperationException("You can't delete this category!");
                }
                CategoryViewModel catModel = new CategoryViewModel();
                AutoMapper.Mapper.Map(cat, catModel);
                return View(catModel);
            }

            return HttpNotFound();
        }
        public ActionResult Create(CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                Category newCat = new Category() { Name = model.Name };
                if (_itemsRepository.CategoryExists(newCat))
                {
                    ModelState.AddModelError("", "A category with this name already exists");
                    return View();
                }
                _itemsRepository.AddCategory(newCat);
                _itemsRepository.Save();
                return RedirectToAction("Index");
            }

            //return for the user to fix the errors if we got to here
            return View();
        }
 //
 // GET: /Management/Category/Details/5
 public ActionResult Details(int id)
 {
     var cat = _itemsRepository.GetCategory(id);
     if (cat != null)
     {
         CategoryViewModel categoryModel = new CategoryViewModel();
         AutoMapper.Mapper.Map(cat, categoryModel);
         return View(categoryModel);
     }
     else
     {
         return HttpNotFound();
     }
 }
 public ActionResult Delete(CategoryViewModel catModel)
 {
     _itemsRepository.DeleteCategory(catModel.Id);
     _itemsRepository.Save();
     return RedirectToAction("Index");
 }
        public ActionResult Edit(CategoryViewModel model)
        {
            if (ModelState.IsValid)
            {
                Category editedCat = new Category() { Id = model.Id, Name = model.Name };
                if (_itemsRepository.DuplicateNameExists(editedCat))
                {
                    ModelState.AddModelError("", "A category with this name already exists.");
                    return View(model);
                }
                _itemsRepository.UpdateCategory(editedCat);
                _itemsRepository.Save();
                return RedirectToAction("Index");
            }

            //return to the user to fix the errors
            return View(model);
        }
        public ActionResult Edit(int id)
        {
            var cat = _itemsRepository.GetCategory(id);
            if (cat != null)
            {
                CategoryViewModel catModel = new CategoryViewModel()
                {
                    Name = cat.Name
                };
                return View(catModel);
            }

            return HttpNotFound();
        }