Exemple #1
0
        public async Task <IActionResult> Cadastrar(IngredienteViewModel ingredienteViewModel)
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <IngredienteViewModel, IngredienteDTO>();
            });
            IMapper mapper = configuration.CreateMapper();

            IngredienteDTO dto = mapper.Map <IngredienteDTO>(ingredienteViewModel);

            try
            {
                Response response = await _ingredienteService.Insert(dto);

                if (response.Sucesso)
                {
                    return(RedirectToAction("Index", "Ingrediente"));
                }

                ViewBag.ErrorMessage = response.GetErrorMessage();
                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
                return(View());
            }
        }
        public ActionResult Create(Ingrediente ingrdnt)
        {
            ViewBag.tipoingrediente = tpingredienteService.FindAll();
            bool rpta = ingredienteService.Insert(ingrdnt);

            if (rpta)
            {
                return(RedirectToAction("Index"));
            }
            return(View());
        }