示例#1
0
        public IActionResult Update(Guid id, [FromBody] dynamic body)
        {
            if (string.IsNullOrEmpty(body.ToString()))
            {
                return(BadRequest());
            }

            //Verifica se o registro existe na base
            var contatoFounded = _contatoRepository.Find(id);

            if (contatoFounded == null)
            {
                return(NotFound());
            }

            Contato contatoNew = new Contato();

            contatoNew = contatoFounded;
            contatoNew.DeserializeJson(body); //Converte Json para o objeto Apoiado
            contatoNew.SetDataAlteracao();

            //Verifica se há inconsistência nos dados
            ContatoAssertion contatoAssertion = new ContatoAssertion(contatoNew);

            if (contatoAssertion.Notifications.HasNotifications())
            {
                Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError;
                return(new ObjectResult(contatoAssertion.Notifications.Notify()));
            }
            _contatoRepository.Update(contatoNew);
            //return new NoContentResult();
            Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status200OK;
            return(new ObjectResult(contatoNew));
        }
示例#2
0
        public IActionResult Create([FromBody] dynamic body)
        {
            if (string.IsNullOrEmpty(body.ToString()))
            {
                return(BadRequest());
            }
            Contato contato = new Contato(); //(((JValue)body.SelectToken("nome")).Value.ToString());

            contato.DeserializeJson(body);   //Converte Json para o objeto Apoiado

            //Verifica se há inconsistência nos dados
            ContatoAssertion contatoAssertion = new ContatoAssertion(contato, true);

            if (contatoAssertion.Notifications.HasNotifications())
            {
                Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError;
                return(new ObjectResult(contatoAssertion.Notifications.Notify()));
            }

            _contatoRepository.Add(contato);
            //return CreatedAtRoute("GetApoio", new { id = apoiado.Id }, apoiado);
            Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status201Created;
            return(new ObjectResult(contato));
        }