Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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));
        }