Exemplo n.º 1
0
 public IActionResult Create([FromBody] UsuarioCreateIn value)
 {
     try
     {
         var handler = new UsuarioHandler();
         var command = new UsuarioCreateCommand()
         {
             Email = value.Email, Nome = value.Nome, Senha = value.Senha
         };
         var result = (CommandResult <bool>)handler.Handle(command, Service);
         return(Ok(result));
     }
     catch (ArgumentNullException e)
     {
         return(NotFound(new CommandResult <bool>()
         {
             Message = e.Message
         }));
     }
     catch (Exception e)
     {
         return(NotFound(new CommandResult <bool>()
         {
             Message = e.Message
         }));
     }
 }
 public void Create(UsuarioCreateCommand command)
 {
     if (command.Nome == "UsuarioExistente" || command.Email == "*****@*****.**")
     {
         throw new Exception("Nome ou email já existe.");
     }
 }
        public void Create(UsuarioCreateCommand command)
        {
            var usuario = new Usuario()
            {
                Nome = command.Nome, Email = command.Email, Senha = command.Senha
            };

            ContextAccess.context.Usuario.Add(usuario);
            ContextAccess.context.SaveChanges();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create(UsuarioCreateCommand command)
        {
            if (ModelState.IsValid)
            {
                await _identityProxy.CreateAsync(command);

                return(Ok());
            }

            return(BadRequest());
        }
Exemplo n.º 5
0
        public void CreateSucesso()
        {
            var handler = new UsuarioHandler();
            var command = new UsuarioCreateCommand()
            {
                Email = "*****@*****.**", Nome = "UsuarioExistente", Senha = "123"
            };

            handler.Handle(command, Service);
            Assert.AreEqual(true, handler.Valid); //nao precisa acoplar o result do command
        }
Exemplo n.º 6
0
        public void CreateJaExisteErro()
        {
            var handler = new UsuarioHandler();
            var command = new UsuarioCreateCommand()
            {
                Email = "wil.com", Nome = "Fake", Senha = "123"
            };

            handler.Handle(command, Service);
            Assert.AreEqual(false, handler.Valid);
        }
Exemplo n.º 7
0
        public void CreateTamanhoNomeMinimoErro()
        {
            var handler = new UsuarioHandler();
            var command = new UsuarioCreateCommand()
            {
                Email = "*****@*****.**", Nome = "W", Senha = "123"
            };

            handler.Handle(command, Service);
            Assert.AreEqual(false, handler.Valid); //nao precisa acoplar o result do command
        }
Exemplo n.º 8
0
        public async Task CreateAsync(UsuarioCreateCommand command)
        {
            var content = new StringContent(
                JsonSerializer.Serialize(command),
                Encoding.UTF8,
                "application/json"
                );

            var request = await _httpClient.PostAsync($"{_apiUrls.IdentityUrl}identity", content);

            request.EnsureSuccessStatusCode();
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Create(UsuarioCreateCommand command)
        {
            if (ModelState.IsValid)
            {
                var result = await _mediator.Send(command);

                if (!result.Succeeded)
                {
                    return(BadRequest(result.Errors));
                }

                return(Ok());
            }

            return(BadRequest());
        }
Exemplo n.º 10
0
        [ProducesResponseType(500)] //erro interno de servidor
        public async Task <IActionResult> Post(UsuarioCreateCommand command)
        {
            try
            {
                await usuarioApplicationService.Create(command);

                return(StatusCode(201, new
                {
                    message = "Usuário cadastrado com sucesso."
                }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, new
                {
                    e.Message
                }));
            }
        }
 public async Task Create(UsuarioCreateCommand command)
 {
     await mediator.Send(command);
 }
 public async Task <object> Create([FromBody] UsuarioCreateCommand usuarioCreateCommand)
 {
     return(await mediator.Send(usuarioCreateCommand));
 }