Beispiel #1
0
 public ActionResult Create(ClienteViewModel clienteViewModel)
 {
     if (!ModelState.IsValid)
     {
         return(View(clienteViewModel));
     }
     clienteViewModel = _clienteAppService.Adicionar(clienteViewModel);
     return(RedirectToAction("index"));
 }
Beispiel #2
0
        public ActionResult Create(ClienteEnderecoViewModel clienteEnderecoViewModel)
        {
            if (ModelState.IsValid)
            {
                clienteEnderecoViewModel = _clienteAppService.Adicionar(clienteEnderecoViewModel);

                if (!clienteEnderecoViewModel.ValidationResult.IsValid)
                {
                    foreach (var erro in clienteEnderecoViewModel.ValidationResult.Erros)
                    {
                        ModelState.AddModelError(string.Empty, erro.Message);
                    }
                    return(View(clienteEnderecoViewModel));
                }


                if (!clienteEnderecoViewModel.ValidationResult.Message.IsNullOrWhiteSpace())
                {
                    ViewBag.Sucesso = clienteEnderecoViewModel.ValidationResult.Message;
                    return(View(clienteEnderecoViewModel));
                }

                return(RedirectToAction("Index"));
            }

            return(View(clienteEnderecoViewModel));
        }
Beispiel #3
0
 public ActionResult Create(ClienteEnderecoViewModel clienteEnderecoViewModel)
 {
     if (ModelState.IsValid)
     {
         _clienteAppService.Adicionar(clienteEnderecoViewModel);
         return(RedirectToAction("Index"));
     }
     return(View(clienteEnderecoViewModel));
 }
 public IHttpActionResult Post([FromBody] ClienteEnderecoViewModel clienteEnderecoViewModel)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     _clienteAppService.Adicionar(clienteEnderecoViewModel);
     return(Ok());
 }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,Nome,Email,CPF,DataNascimento,DataCadastro,Ativo,Excluido")] ClienteEnderecoViewModel clienteEnderecoViewModel)
        {
            if (ModelState.IsValid)
            {
                _clienteAppService.Adicionar(clienteEnderecoViewModel);
                return(RedirectToAction("Index"));
            }

            return(View(clienteEnderecoViewModel));
        }
Beispiel #6
0
        public ActionResult Create(ClienteViewModel clienteViewModel)
        {
            if (ModelState.IsValid)
            {
                clienteViewModel = _clienteAppService.Adicionar(clienteViewModel);

                if (!clienteViewModel.ValidationResult.IsValid)
                {
                    foreach (var error in clienteViewModel.ValidationResult.Erros)
                    {
                        ModelState.AddModelError(string.Empty, error.Message);
                    }

                    return(View(clienteViewModel));
                }

                return(RedirectToAction("Index"));
            }

            return(View(clienteViewModel));
        }
Beispiel #7
0
        public IHttpActionResult Adicionar([FromBody] ClienteEnderecoViewModel clienteEndereco)
        {
            // 400 - Não é obrigatório, é só trocar o IHttpActionRequest por void
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _clienteAppService.Adicionar(clienteEndereco);

            // 200
            return(Ok());
        }
Beispiel #8
0
        public ActionResult Cadastrar(ClienteViewModel clienteViewModel)
        {
            if (ModelState.IsValid)
            {
                _clienteAppService.Adicionar(clienteViewModel);

                if (!ValidOperation("Cliente cadastrado com Sucesso!"))
                {
                    return(View(clienteViewModel));
                }

                return(RedirectToAction("Index"));
            }
            return(View(clienteViewModel));
        }
Beispiel #9
0
        public async Task CriarObterAtualizarExcluirCliente()
        {
            _mockClienteRepositorio = new Mock <IClienteRepositorio>();
            _appService             = new ClienteAppService(_mockClienteRepositorio.Object);
            /* Inserindo */
            var obj = "Ipppppp";

            /* Especificando retorno para o metodo em questão */
            _mockClienteRepositorio.Setup(x => x.Insert(It.IsAny <Cliente>()))
            .Returns(Task.CompletedTask);

            await _mockClienteRepositorio.Object.Insert(It.IsAny <Cliente>());

            await _appService.Adicionar(obj);
        }
Beispiel #10
0
        public ActionResult Create(ClienteViewModel ClienteViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(ClienteViewModel));
            }
            ClienteViewModel = _ClienteAppService.Adicionar(ClienteViewModel);

            if (ClienteViewModel.ValidationResult.IsValid)
            {
                TempData["Sucesso"] = ClienteViewModel.ValidationResult.Message;
                return(View(ClienteViewModel));
            }
            PopularModelComErros(ClienteViewModel.ValidationResult);
            return(View(ClienteViewModel));
        }
Beispiel #11
0
 public ActionResult Create(ClienteEnderecoVM cliente)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _clienteAppService.Adicionar(cliente);
             return(RedirectToAction("Index"));
         }
         return(View(cliente));
     }
     catch
     {
         return(View());
     }
 }
Beispiel #12
0
        public ActionResult Create(ClienteEnderecoViewModel clienteEndereco)
        {
            if (!ModelState.IsValid)
            {
                return(View(clienteEndereco));
            }

            clienteEndereco = _clienteAppService.Adicionar(clienteEndereco);
            if (clienteEndereco.Cliente.ValidationResult.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            PopularModelStateComErros(clienteEndereco.Cliente.ValidationResult);

            return(View(clienteEndereco));
        }
Beispiel #13
0
        public async Task <IActionResult> Create(ClienteViewModel cliente)
        {
            cliente.Cnpj = cliente.Cnpj.Replace(".", "").Replace("/", "").Replace("-", "");
            if (!ModelState.IsValid)
            {
                return(View(cliente));
            }

            var clienteResult = await _clienteAppService.Adicionar(cliente);

            if (OperacaoValida())
            {
                return(RedirectToAction(nameof(Index)));
            }

            return(View(cliente));
        }
        public async Task <string> Post([FromBody] ClienteModel model)
        {
            try
            {
                await _clienteAppService.Adicionar(model);
            }
            catch (DominioException ex)
            {
                return(ex.Message);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            return(null);
        }
Beispiel #15
0
        public ActionResult Create(ClienteEnderecoViewModel clienteEnderecoViewModel)
        {
            if (ModelState.IsValid)
            {
                clienteEnderecoViewModel = _clienteAppService.Adicionar(clienteEnderecoViewModel);

                if (!clienteEnderecoViewModel.ValidationResult.IsValid)
                {
                    foreach (var erro in clienteEnderecoViewModel.ValidationResult.Erros)
                    {
                        ModelState.AddModelError(string.Empty, erro.Message);
                    }
                    return(View(clienteEnderecoViewModel)); //CASO TENHA ALGUM ERRO RETORNA PARA A VIEW DE CADASTRO
                }
                return(RedirectToAction("Index"));
            }

            return(View(clienteEnderecoViewModel));
        }
        public ActionResult Create(ClienteEnderecoViewModel clienteEnderecoViewModel) // [Bind(Include = "ClienteId,Nome,Email,CPF,DataNascimento,DataCadastro,Ativo")]
        {
            if (ModelState.IsValid)
            {
                var clienteViewModel = _clienteAppService.Adicionar(clienteEnderecoViewModel);
                if (clienteViewModel.ValidationResult.IsValid)
                {
                    return(RedirectToAction("Index"));
                }

                foreach (var erro in clienteViewModel.ValidationResult.Erros)
                {
                    ModelState.AddModelError(string.Empty, erro.Message);
                }
                return(View(clienteEnderecoViewModel));
            }

            return(View(clienteEnderecoViewModel));
        }
Beispiel #17
0
        public ActionResult Create(ClienteEnderecoViewModel clienteEnderecoViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(clienteEnderecoViewModel));
            }

            clienteEnderecoViewModel = _clienteAppService.Adicionar(clienteEnderecoViewModel);
            var result = clienteEnderecoViewModel.Cliente.ValidationResult;

            if (result.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            foreach (var erro in result.Erros)
            {
                ModelState.AddModelError(string.Empty, erro.Message);
            }

            return(View(clienteEnderecoViewModel));
        }
        public ActionResult Create(ClienteEnderecoViewModel clienteEnderecoViewModel)
        {
            if (ModelState.IsValid)
            {
                clienteEnderecoViewModel = _clienteAppService.Adicionar(clienteEnderecoViewModel);

                if (Notifications.HasNotifications())
                {
                    foreach (var item in Notifications.Notify())
                    {
                        ModelState.AddModelError(string.Empty, item.Value);
                    }

                    return(View(clienteEnderecoViewModel));
                }

                ViewBag.Sucesso = "Cliente cadastrado com sucesso :)";
                return(View(clienteEnderecoViewModel));
            }

            return(View(clienteEnderecoViewModel));
        }
        public HttpResponseMessage Post(ClienteViewModel clienteViewModel)
        {
            if (ModelState.IsValid)
            {
                clienteViewModel = _clienteAppService.Adicionar(clienteViewModel);

                if (!clienteViewModel.ValidationResult.IsValid)
                {
                    foreach (var erro in clienteViewModel.ValidationResult.Erros)
                    {
                        ModelState.AddModelError(string.Empty, erro.Message);
                    }

                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
                }

                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, clienteViewModel);
                return(response);
            }
            else
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }
        }
Beispiel #20
0
        public ActionResult Create(ClienteEnderecoViewModel clienteEnderecoViewModel)
        {
            if (ModelState.IsValid)
            {
                clienteEnderecoViewModel = _clienteAppService.Adicionar(clienteEnderecoViewModel);

                if (!clienteEnderecoViewModel.ValidationResult.IsValid)
                {
                    foreach (var erro in clienteEnderecoViewModel.ValidationResult.Erros)
                    {
                        ModelState.AddModelError(string.Empty, erro.Message); //estou adicionando um erro na lista de erros da viewmodel
                    }
                    return(View(clienteEnderecoViewModel));
                }
                if (clienteEnderecoViewModel.ValidationResult.Message != null)
                {
                    ViewBag.Sucesso = clienteEnderecoViewModel.ValidationResult.Message;
                    return(View(clienteEnderecoViewModel));
                }
                return(RedirectToAction("Index"));
            }

            return(View(clienteEnderecoViewModel));
        }
        public IHttpActionResult Adicionar([FromBody] ClienteEnderecoViewModel clienteEnderecoViewModel)
        {
            var @return = _clienteAppService.Adicionar(clienteEnderecoViewModel);

            return([email protected] ? TratarErros(@return.Cliente.ValidationResult) : Created <ClienteEnderecoViewModel>(string.Empty, @return));
        }
 // POST: api/Clientes
 public void Post([FromBody] ClienteEnderecoViewModel clienteEnderecoViewModel)
 {
     _clienteAppService.Adicionar(clienteEnderecoViewModel);
 }
Beispiel #23
0
        public IActionResult adicionarCliente([FromBody] NewClienteViewModel cliente)
        {
            cliente = _clienteAppService.Adicionar(cliente);

            return(cliente.ValidationResult.IsValid ? ApiResponse(cliente) : ApiResponse(cliente.ValidationResult));
        }
Beispiel #24
0
 public void Incluir([FromBody] ClienteViewModel Cliente)
 {
     _ClienteAppService.Adicionar(Cliente);
 }
Beispiel #25
0
 // POST: api/Clientes
 public IHttpActionResult Post([FromBody] ClienteEnderecoViewModel clienteEnderecoViewModel)
 {
     clienteEnderecoViewModel = _clienteAppService.Adicionar(clienteEnderecoViewModel);
     return(Response(clienteEnderecoViewModel));
 }