public async Task <IActionResult> Registro(SaladaViewModel saladaViewModel) { try { await _cardapioRepository.AddCardapio(_mapper.Map <Salada>(saladaViewModel)); await _cardapioRepository.Save(); //_cardapioRepository.AddCardapio<Salada>(_mapper.Map<Salada>(saladaViewModel)); ModelState.Clear(); await _cardapioRepository.RemoveProdutoAntigo <Salada>(); return(View(await GetSaladas())); } catch (System.Exception e) { ModelState.AddModelError(string.Empty, e.Message); return(View(await GetSaladas())); } }
public async Task <IActionResult> Registro(AcompanhamentoViewModel acompanhamentoViewModel) { try { await _cardapioRepository.AddCardapio(_mapper.Map <Acompanhamento>(acompanhamentoViewModel)); await _cardapioRepository.Save(); var AcompanhamentoMapper = _mapper.Map <List <AcompanhamentoViewModel> >(await _cardapioRepository.Ativos <Acompanhamento>()); acompanhamentoViewModel = new AcompanhamentoViewModel { Acompanhamentos = AcompanhamentoMapper }; ModelState.Clear(); return(View(acompanhamentoViewModel)); } catch (System.Exception e) { ModelState.AddModelError(string.Empty, e.Message); return(View(new AcompanhamentoViewModel { Acompanhamentos = _mapper.Map <List <AcompanhamentoViewModel> >(await _cardapioRepository.Ativos <Acompanhamento>()) })); } }