public ActionResult Create()
        {
            var viewModel = new ItemViewModel();
            var itemTypeSelectList = GetItemTypeSelectList(viewModel);
            viewModel.ItemTypeSelectList = itemTypeSelectList;
            viewModel.IsActive = true;
            viewModel.Available = true;

            return View(viewModel);
        }
 public ActionResult Edit(ItemViewModel viewModel)
 {
     if (ModelState.IsValid)
     {
         var item = _mappingEngine.Map<ItemViewModel, Item>(viewModel);
         if (item != null) _itemRepository.Save(item);
         return RedirectToAction("Index", "Items");
     }
     var itemTypeSelectList = GetItemTypeSelectList(viewModel);
     viewModel.ItemTypeSelectList = itemTypeSelectList;
     return View(viewModel);
 }
 public ActionResult Edit(int id)
 {
     var viewModel = new ItemViewModel();
     var item = _itemRepository.GetById(id);
     if (item != null) viewModel = _mappingEngine.Map<Item, ItemViewModel>(item);
     if (viewModel != null)
     {
         var itemTypeSelectList = GetItemTypeSelectList(viewModel);
         viewModel.ItemTypeSelectList = itemTypeSelectList;
     }
     return View(viewModel);
 }
        private SelectList GetItemTypeSelectList(ItemViewModel viewModel)
        {
            var itemTypes = _itemTypeRepository.GetAllActive() ?? new List<ItemType>();

            var listItems = itemTypes.Select(x => new SelectListItem
            {
                Text = x.Description,
                Value = x.Id.ToString()
            });

            var itemTypeSelectList = new SelectList(listItems, "Value", "Text", viewModel.ItemTypeId);
            return itemTypeSelectList;
        }