Exemplo n.º 1
0
        public async Task <IActionResult> Create(CompraViewComponent compraViewComponent)
        {
            if (!ModelState.IsValid)
            {
                return(View(compraViewComponent));
            }

            var compra = _mapper.Map <Compra>(compraViewComponent);

            await _compraRepository.Adicionar(compra);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Edit(Guid id, CompraViewComponent compraViewComponent)
        {
            if (id != compraViewComponent.Id)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(View(compraViewComponent));
            }

            var compraAtualizada = _mapper.Map <Compra>(await _compraRepository.ObterPorId(id));

            compraAtualizada.Nome = compraViewComponent.Nome;
            await _compraRepository.Atualizar(compraAtualizada);

            return(RedirectToAction("Index"));
        }