public ActionResult CreateConsumable(ConsumableView _ComponentView)
        {
            initViewBag();
            var anyComponent = Repository.Consumables.Any(p => string.Compare(p.Name, _ComponentView.Name) == 0);
            if (anyComponent)
            {
                ModelState.AddModelError("Name", "Комплектующий с" + " таким наименованием уже существует");
            }

            if (ModelState.IsValid)
            {

                var _Component = (Consumable)ModelMapper.Map(_ComponentView, typeof(ConsumableView), typeof(Consumable));

                Repository.CreateConsumable(_Component);

                //if (_ComponentView.ChosenModelIds!=null)
                //{
                //    Repository.CreateModelComsumable(_ComponentView.ChosenModelIds, _Component.ID);
                //}
                return RedirectToAction("Index");
            }

            return View(_ComponentView);
        }
        public ActionResult EditConsumable(ConsumableView _ComponentView)
        {
            var anyComponent = Repository.Consumables.Where(p=>p.ID!=_ComponentView.ID).Any(p => string.Compare(p.Name, _ComponentView.Name) == 0);
            if (anyComponent)
            {
                ModelState.AddModelError("Name", "Комплектующий с" + " таким наименованием уже существует");
            }
            if (ModelState.IsValid)
            {
                var _Component = Repository.Consumables.FirstOrDefault(p => p.ID == _ComponentView.ID);
                ModelMapper.Map(_ComponentView, _Component, typeof(ConsumableView), typeof(Consumable));
                Repository.UpdateConsumable(_Component);

               ///нельзя Repository.RemoveModelConsumable(_ComponentView.ChosenModelIds);
               //     Repository.CreateModelComsumable(_ComponentView.ChosenModelIds, _Component.ID);

                return RedirectToAction("Index");
            }

            return View(_ComponentView);
        }
 public ActionResult CreateConsumable()
 {
     initViewBag();
     var newComponentView = new ConsumableView();
     return View(newComponentView);
 }