예제 #1
0
        public IActionResult Alterar([FromBody] ContatoDTO contatoDTO)
        {
            ContatoValidation validation       = new ContatoValidation();
            ValidationResult  validationResult = validation.Validate(contatoDTO);

            if (!validationResult.IsValid)
            {
                return(ResponseValidationResult(validationResult));
            }

            try
            {
                _contatoService.Alterar(contatoDTO);

                var data = new
                {
                    result = new
                    {
                        id      = contatoDTO.Id,
                        nome    = contatoDTO.Nome,
                        celular = contatoDTO.Celular,
                        email   = contatoDTO.Email
                    }
                };

                return(Ok(new { success = true, data = data }));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { success = false, errors = new KeyValuePair <string, string>("BadRequest", $"Erro ao executar o método Alterar: {ex.Message}") }));
            }
        }
예제 #2
0
        public async Task <IActionResult> OnPostUpdateAsync(CancellationToken cancellationToken)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var result = await _contatoService.Alterar(Contato, cancellationToken).ConfigureAwait(false);

            if (!result)
            {
                return(RedirectToPage("/Error"));
            }

            return(RedirectToPage("Index"));
        }