コード例 #1
0
        public IActionResult Cadastrar([FromBody] Usuario usuario)
        {
            JsonResult rs = null;

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                rs             = new JsonResult(dao.Cadastrar(usuario));
                rs.ContentType = "application/json";
                if (!Convert.ToBoolean(rs.Value))
                {
                    rs.StatusCode = 404;
                    rs.Value      = "Ocorreu um erro.";
                }
                else
                {
                    rs.StatusCode = 200;
                }
            }
            catch (SystemException ex)
            {
                rs            = new JsonResult("");
                rs.StatusCode = 204;
                rs.Value      = ex.Message;
            }

            return(Json(rs));
        }