Ejemplo 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 scriptGeradoFounded = _scriptGeradoRepository.Find(id);

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

            ScriptGerado scriptGeradoNew = body.ToObject <ScriptGerado>();

            scriptGeradoNew.SetDataAlteracao();

            //Verifica se há inconsistência nos dados
            ScriptGeradoAssertion scriptGeradoAssertion = new ScriptGeradoAssertion(scriptGeradoNew);

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

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

            //Verifica se há inconsistência nos dados
            ScriptGeradoAssertion scriptGeradoAssertion = new ScriptGeradoAssertion(scriptGerado, true);

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

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