Exemplo n.º 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 passoGeradoFounded = _passoGeradoRepository.Find(id);

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

            PassoGerado passoGeradoNew = body.ToObject <PassoGerado>();

            passoGeradoNew.SetDataAlteracao();

            //Verifica se há inconsistência nos dados
            PassoGeradoAssertion passoGeradoAssertion = new PassoGeradoAssertion(passoGeradoNew);

            if (passoGeradoAssertion.Notifications.HasNotifications())
            {
                Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError;
                return(new ObjectResult(passoGeradoAssertion.Notifications.Notify()));
            }
            _passoGeradoRepository.Update(passoGeradoNew);
            //return new NoContentResult();
            Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status200OK;
            return(new ObjectResult(passoGeradoNew));
        }
Exemplo n.º 2
0
        public IActionResult Create([FromBody] JObject body)
        {
            if (string.IsNullOrEmpty(body.ToString()))
            {
                return(BadRequest());
            }

            //PassoGerado passoGerado = new PassoGerado();
            //passoGerado.DeserializeJson(body); //Converte Json para o objeto
            PassoGerado passoGerado = body.ToObject <PassoGerado>();

            //Verifica se há inconsistência nos dados
            PassoGeradoAssertion passoGeradoAssertion = new PassoGeradoAssertion(passoGerado, true);

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

            _passoGeradoRepository.Add(passoGerado);
            Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status201Created;
            return(new ObjectResult(passoGerado));
        }