Example #1
0
        public async Task <IActionResult> Edit(int id, 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()
                }));
            }

            if (id != venda.ID)
            {
                return(RedirectToAction(nameof(Error), new { message = "O ID Informado não corresponde ao ID  da uma Venda!" }));
            }

            try
            {
                await _vendaServico.UpdateAsync(venda);

                return(RedirectToAction(nameof(Index)));
            }
            catch (ApplicationException erro)
            {
                return(RedirectToAction(nameof(Error), new { message = erro.Message }));
            }
        }