public async Task <IActionResult> Edit(int id, ProductMechanismViewModel productMechanism) { if (id != productMechanism.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(productMechanism.GetModel()); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProductMechanismExists(productMechanism.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //ViewData["ClientId"] = new SelectList(_context.Client, "Id", "Id", productMechanism.ClientId); ViewData["MechanismId"] = new SelectList(_context.ProductMechanism, "Id", "MechanismName", productMechanism.ProductId); productMechanism.loadLists(_context); return(View(productMechanism)); }
// GET: ProductMechanism/Create public IActionResult Create(int id) { ProductMechanismViewModel vm; vm = new ProductMechanismViewModel(_context); ViewData["ProductId"] = new SelectList(_context.ClientProduct, "Id", "ProductName"); return(View(vm)); }
public async Task <IActionResult> Create(int id, ProductMechanismViewModel productMechanism) { if (ModelState.IsValid) { productMechanism.MechanismId = id; _context.Add(productMechanism.GetModel()); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //ViewData["ClientId"] = new SelectList(_context.Client, "Id", "Id", productMechanism.ClientId); ViewData["MechanismId"] = new SelectList(_context.ProductMechanism, "Id", "MechanismName", productMechanism.ProductId); productMechanism.loadLists(_context); return(View(productMechanism)); }
// GET: ProductMechanism/Edit/5 public async Task <IActionResult> Edit(int?id) { ProductMechanismViewModel vm; if (id == 0) { vm = new ProductMechanismViewModel(_context); } else { var productMechanism = await _context.ProductMechanism.FindAsync(id); if (productMechanism == null) { return(NotFound()); } vm = new ProductMechanismViewModel(_context, productMechanism); } return(View(vm)); }