Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,PrecoUnitario,Nome")] Produto produto)
        {
            if (ModelState.IsValid)
            {
                _context.Add(produto);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(produto));
        }
        public async Task <IActionResult> Create([Bind("Id,Nome,Nascimento,Altura")] Cliente cliente)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cliente);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(cliente));
        }
Esempio n. 3
0
        public async Task <IActionResult> Create([Bind("Id,PedidoId,Quantidade,ProdutoId")] Itens itens)
        {
            if (ModelState.IsValid)
            {
                _context.Add(itens);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["PedidoId"]  = new SelectList(_context.Pedidos, "Id", "Id", itens.PedidoId);
            ViewData["ProdutoId"] = new SelectList(_context.Produtos, "Id", "Id", itens.ProdutoId);
            return(View(itens));
        }
Esempio n. 4
0
        public async Task <IActionResult> Create([Bind("Id,Nome,Cpf,Email")] Usuario usuario)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _context.Add(usuario);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }
            catch (DbUpdateException /* ex */)
            {
                ModelState.AddModelError("", "Unable to save changes. " +
                                         "Try again, and if the problem persists " +
                                         "see your system administrator.");
            }
            return(View(usuario));
        }
Esempio n. 5
0
 public void Inserir(Categoria categoria)
 {
     _context.Add(categoria);
     _context.SaveChanges();
 }
 public void Inserir(Produto produto)
 {
     _context.Add(produto);
     _context.SaveChanges();
 }