public ActionResult Create(CategoryListItemViewModel categoryListItem)
        {
            if (ModelState.IsValid)
            {
                tCategory tcategory = new tCategory();
                tcategory.Name = categoryListItem.Name;
                tcategory.Description = categoryListItem.Description;

                _db.tCategory.Add(tcategory);
                _db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(categoryListItem);
        }
        public ActionResult Edit(CategoryListItemViewModel categoryListItem)
        {
            if (ModelState.IsValid)
            {
                tCategory tcategory = _db.tCategory.Find(categoryListItem.CategoryID);

                tcategory.Name = categoryListItem.Name;
                tcategory.Description = categoryListItem.Description;

                _db.Entry(tcategory).State = EntityState.Modified;
                _db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(categoryListItem);
        }
 public ActionResult Edit(CategoryListItemViewModel categoryListItem)
 {
     return _categoryViewModel.Edit(categoryListItem);
 }
 public ActionResult Create(CategoryListItemViewModel categoryListItem)
 {
     return _categoryViewModel.Create(categoryListItem);
 }
        private List<CategoryListItemViewModel> GetCategoryList()
        {
            List<CategoryListItemViewModel> categoryList = new List<CategoryListItemViewModel>();

            //CategoryListItemViewModel listItem = new CategoryListItemViewModel();
            //listItem.CategoryID = 0;
            //listItem.Name = "Välj kategori";

            //categoryList.Add(listItem);

            foreach (var dbItem in _db.tCategory.ToList())
            {
                CategoryListItemViewModel listItem = new CategoryListItemViewModel();

                listItem.CategoryID = dbItem.CategoryID;
                listItem.Name = dbItem.Name;
                listItem.Description = dbItem.Description;

                categoryList.Add(listItem);
            }

            return categoryList;
        }
        public ActionResult GetCategoryListItem(int id)
        {
            tCategory tcategory = _db.tCategory.Find(id);

            CategoryListItemViewModel categoryItem = new CategoryListItemViewModel();

            if (tcategory == null)
            {
                return HttpNotFound();
            }
            else
            {
                categoryItem.CategoryID = tcategory.CategoryID;
                categoryItem.Name = tcategory.Name;
                categoryItem.Description = tcategory.Description;
            }

            return View(categoryItem);
        }