Ejemplo n.º 1
0
        // GET: api/DocumentDB
        public IEnumerable <dynamic> Get(string collection, string fields = "value c", string where = "", string join = "")
        {
            var query = new SqlQuerySpec(
                "SELECT " + fields + " FROM c " + (string.IsNullOrEmpty(join) ? "" : " JOIN " + join + " ") + (string.IsNullOrEmpty(where) ? "" : " where " + where),
                new SqlParameterCollection());

            return(DocumentDBHelper.GetDocuments(collection, query, null).documents);
        }
 // GETByQuery: api/DocumentDB
 public IHttpActionResult GetByQuery(string collection, string query = "Select * from collection", int?maxitemcount = null, string continuationToken = null)
 {
     if (query.StartsWith("select", System.StringComparison.CurrentCultureIgnoreCase))
     {
         var queryObject = new SqlQuerySpec(
             query,
             new SqlParameterCollection());
         var result = DocumentDBHelper.GetDocuments(collection, queryObject, maxitemcount, continuationToken);
         if (!string.IsNullOrEmpty(result.ContinuationToken))
         {
             System.Web.HttpContext.Current.Response.AddHeader("ContinuationToken", result.ContinuationToken);
         }
         return(Ok(result.documents));
     }
     return(BadRequest("Expression must start with SELECT"));
 }