public async Task <IActionResult> Create([Bind("ID,Descricao,ValorIndividual")] 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,ClienteID,ValorTotal,DataPedido")] Pedido pedido) { if (ModelState.IsValid) { _context.Add(pedido); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(pedido)); }
public virtual async Task <T> Insert(T obj) { try { _context.Add(obj); await _context.SaveChangesAsync(); return(obj); } catch (System.Exception) { throw; } }
public async Task <IActionResult> Create([Bind("Nome,CPF")] Cliente cliente) { try { if (ModelState.IsValid) { _context.Add(cliente); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } catch (DbUpdateException /* ex */) { //Log the error (uncomment ex variable name and write a log. ModelState.AddModelError("", "Unable to save changes. " + "Try again, and if the problem persists " + "see your system administrator."); } return(View(cliente)); }