Exemple #1
0
        public IActionResult Post(ClienteAddViewModel model)
        {
            try
            {
                clienteApplicationService.Add(model);

                return(Ok(
                           new
                {
                    Mensagem = "Cliente cadastrado com sucesso.",
                    Cliente = model
                }));
            }
            catch (EmailDeveSerUnicoException e)
            {
                return(StatusCode(403, e.Message));
            }
            catch (CpfDeveSerUnicoException e)
            {
                return(StatusCode(403, e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
Exemple #2
0
        public IActionResult Post(CreateClienteCommand command)
        {
            try
            {
                clienteApplicationService.Add(command);

                return(Ok(new { Message = "Cliente cadastrado com sucesso" }));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));;
            }
        }
        public ActionResult Post([FromBody] ClienteDTO clienteDTO)
        {
            try
            {
                if (clienteDTO == null)
                {
                    return(NotFound());
                }

                _clienteApp.Add(clienteDTO);
                return(Ok("Cliente cadastrado com sucesso"));
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #4
0
        public ActionResult Post([FromBody] ClienteDTO clienteDTO)
        {
            try
            {
                if (clienteDTO == null)
                {
                    return(NotFound());
                }

                _clienteApplicationService.Add(clienteDTO);

                return(Ok("Cliente Cadastrado com sucesso!"));
            }
            catch (Exception ex)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, $" {ex.Message}"));
            }
        }
Exemple #5
0
        public async Task <IActionResult> Create(ClienteViewModel cliente)
        {
            if (!ModelState.IsValid)
            {
                NotifyModelStateErrors();
                return(View(cliente));
            }

            var commandResult = await _clienteApplicationService.Add(cliente);

            if (commandResult.Success)
            {
                NotifyCommandResultSuccess();
                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                NotifyCommandResultErrors(commandResult.Errors);
            }

            return(View(cliente));
        }