Beispiel #1
0
        public StatementLRSResponse SaveStatement(Statement statement)
        {
            var r = new StatementLRSResponse();
            var req = new MyHTTPRequest();
            req.queryParams = new Dictionary<String, String>();
            req.resource = "statements";

            if (statement.id == null)
            {
                req.method = "POST";
            }
            else
            {
                req.method = "PUT";
                req.queryParams.Add("statementId", statement.id.ToString());
            }

            req.contentType = "application/json";
            req.content = Encoding.UTF8.GetBytes(statement.ToJSON(version));

            var res = MakeSyncRequest(req);
            if (statement.id == null)
            {
                if (res.status != HttpStatusCode.OK)
                {
                    r.success = false;
                    r.httpException = res.ex;
                    r.SetErrMsgFromBytes(res.content);
                    return r;
                }

                var ids = JArray.Parse(Encoding.UTF8.GetString(res.content));
                statement.id = new Guid((String)ids[0]);
            }
            else {
                if (res.status != HttpStatusCode.NoContent)
                {
                    r.success = false;
                    r.httpException = res.ex;
                    r.SetErrMsgFromBytes(res.content);
                    return r;
                }
            }

            r.success = true;
            r.content = statement;

            return r;
        }
Beispiel #2
0
        private StatementLRSResponse GetStatement(Dictionary<String, String> queryParams)
        {
            var r = new StatementLRSResponse();

            var req = new MyHTTPRequest();
            req.method = "GET";
            req.resource = "statements";
            req.queryParams = queryParams;

            var res = MakeSyncRequest(req);
            if (res.status != HttpStatusCode.OK)
            {
                r.success = false;
                r.httpException = res.ex;
                r.SetErrMsgFromBytes(res.content);
                return r;
            }

            r.success = true;
            r.content = new Statement(new Json.StringOfJSON(Encoding.UTF8.GetString(res.content)));

            return r;
        }