public async Task <IActionResult> AdicionarCategoria(CategoriaViewModel categoriaViewModel)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(await PopularCategorias(new CategoriaViewModel())));
                }

                var command = new AdicionarCategoriaCommand(categoriaViewModel.Nome, categoriaViewModel.Codigo);

                var resultado = await _mediatorHandler.EnviarCommand(command);

                if (resultado)
                {
                    return(RedirectToAction("Index"));
                }

                //TempData["Error"] = ObterMensagensDeErro();
                return(View());
            }
            catch (System.Exception ex)
            {
                TempData["Error"] = "System.Exception ex - Teste";
                return(View());
            }
        }
Пример #2
0
        public Task Handle(UsuarioNovoEvent message)
        {
            //Console.WriteLine(message.Serialize());
            var cmd = new UsuarioNovoCommand();

            cmd.Id    = new Guid(message.Id);
            cmd.Nome  = message.Nome;
            cmd.Email = message.Email;

            Bus.EnviarCommand(cmd);
            return(Task.CompletedTask);
        }
 public IActionResult Post([FromBody] UsuarioNovoCommand usuario)
 {
     Bus.EnviarCommand(usuario);
     return(Response(usuario));
 }