public IActionResult Update(Guid id, [FromBody] dynamic body)//[FromBody]Apoiado conexaoNew) { if (string.IsNullOrEmpty(body.ToString())) { return(BadRequest()); } //Verifica se o registro existe na base var conexaoFounded = _conexaoRepository.Find(id); if (conexaoFounded == null) { return(NotFound()); } Conexao conexaoNew = new Conexao(); conexaoNew = conexaoFounded; conexaoNew.DeserializeJson(body); //Converte Json para o objeto Apoiado conexaoNew.SetDataAlteracao(); //Verifica se há inconsistência nos dados ConexaoAssertion conexaoAssertion = new ConexaoAssertion(conexaoNew); if (conexaoAssertion.Notifications.HasNotifications()) { Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError; return(new ObjectResult(conexaoAssertion.Notifications.Notify())); } _conexaoRepository.Update(conexaoNew); //return new NoContentResult(); Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status200OK; return(new ObjectResult(conexaoNew)); }
public IActionResult Create([FromBody] JObject body)//[FromBody] Apoiado conexao) { if (string.IsNullOrEmpty(body.ToString())) { return(BadRequest()); } Conexao conexao = new Conexao(); //(((JValue)body.SelectToken("nome")).Value.ToString()); conexao.DeserializeJson(body); //Converte Json para o objeto Apoiado //Verifica se há inconsistência nos dados ConexaoAssertion conexaoAssertion = new ConexaoAssertion(conexao, true); if (conexaoAssertion.Notifications.HasNotifications()) { Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status500InternalServerError; return(new ObjectResult(conexaoAssertion.Notifications.Notify())); } _conexaoRepository.Add(conexao); //return CreatedAtRoute("GetApoio", new { id = conexao.Id }, conexao); Response.StatusCode = Microsoft.AspNetCore.Http.StatusCodes.Status201Created; return(new ObjectResult(conexao)); }