public ActionResult Create(ComponentTypeCreateVM data) { var model = _mapper.Map <ComponentTypeCreateVM, ComponentType>(data); _componentTypeRepo.Insert(model); return(RedirectToAction(nameof(Index), "ComponentType")); }
public ActionResult Edit(int id, ComponentTypeCreateVM data) { // Nasty hack because we are dependent on the Entity framework proxy classes in the // Repository. var model = _componentTypeRepo.Get(id); var dataMapped = _mapper.Map <ComponentTypeCreateVM, ComponentType>(data); model.AdminComment = dataMapped.AdminComment; model.ComponentInfo = dataMapped.ComponentInfo; model.ComponentName = dataMapped.ComponentName; model.Datasheet = dataMapped.Datasheet; model.Image = dataMapped.Image; model.ImageUrl = dataMapped.ImageUrl; model.Location = dataMapped.Location; model.Manufacturer = dataMapped.Manufacturer; model.Status = dataMapped.Status; model.WikiLink = dataMapped.WikiLink; // Eeeeewww model.ComponentTypeCategory.Clear(); _componentTypeRepo.Update(model); foreach (var ctc in dataMapped.ComponentTypeCategory) { model.ComponentTypeCategory.Add(ctc); } // Eeeeewww _componentTypeRepo.Update(model); return(RedirectToAction(nameof(Index), "ComponentType")); }
// GET: /ComponentType/Create public ViewResult Create() { ViewBag.CategoryList = CategorySelectList(); ViewBag.ComponentTypeList = ComponentTypesSelectList(); ViewBag.ComponentTypeStatusList = ComponentTypeStatusEnumSelectList(); var VM = new ComponentTypeCreateVM(); return(View(VM)); }