Example #1
0
        public async Task <IActionResult> Create(Venda venda)
        {
            if (!ModelState.IsValid)
            {
                return(View(new VendaViewModel()
                {
                    Venda = venda, Livros = (await _livroServico.GetAllAsync()).OrderBy(x => x.Titulo).ToList(), Clientes = (await _clienteServico.GetAllAsync()).OrderBy(x => x.Nome).ToList()
                }));
            }

            var livro = await _livroServico.FindFirstAsync(x => x.ID == venda.LivroID);

            venda.ValorUnitario = livro.Preco;
            await _vendaServico.AddAsync(venda);

            return(RedirectToAction(nameof(Index)));
        }