Beispiel #1
0
        /**
         * Update single entity but only the changed fields
         */
        public async Task <JToken> PatchItemAsync(string entityTypeName, Dto item)
        {
            var entitySetName = this.metadataCli.EntityTypes[entityTypeName].EntitySetName;
            var keyNames      = this.metadataCli.EntityTypes[entityTypeName].Key;
            var url           = this.apiUrl + "/crud/" + entitySetName + "?" + QueryUtils.RenderQueryString(new QueryObject()
            {
                Keys = (new List <Dto> {
                    DataAdapterUtils.GetKeyFromData(keyNames, (Dto)item["partialEntity"])
                }).ToArray()
            });

            // Info credit: http://benfoster.io/blog/adding-patch-support-to-httpclient
            HttpRequestMessage request;
            var jsonPatchItem = JsonConvert.SerializeObject(item["patchItem"]);

            using (var content = new StringContent(jsonPatchItem, Encoding.UTF8, "application/json"))
            {
                request = new HttpRequestMessage(new HttpMethod("PATCH"), url)
                {
                    Content = content
                };
            }
            var response = await this.client.SendAsync(request);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultSingleSerialDataToken = JToken.Parse(json);
                return(resultSingleSerialDataToken);
            }
            return(null);
        }
Beispiel #2
0
        /**
         * Entity Action call (a service operation that returns entities and may produce side effects)
         */
        public async Task <JToken> CallEntityActionAsync(string actionName, Dictionary <string, object> paramsObject, string returnTypeName)
        {
            var paramsQueryString = DataAdapterUtils.CreateParamsQueryString(paramsObject);

            var url = this.apiUrl + "/operations/" + actionName + "?" + paramsQueryString;

            var response = await this.client.PostAsync(url, null);;

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultToken = JToken.Parse(json);
                return(resultToken);
            }
            return(null);
        }
Beispiel #3
0
        /**
         * Entity Function call (a service operation that returns entities and has no side effects)
         */
        public async Task <JToken> CallEntityFunctionAsync(string functionName, Dictionary <string, object> paramsObject, QueryObject queryObject, string returnTypeName, bool returnCollection)
        {
            queryObject.Count = returnCollection;
            var paramsQueryString = DataAdapterUtils.CreateParamsQueryString(paramsObject);

            var url = this.apiUrl + "/operations/" + functionName + "?" + paramsQueryString + "&" + QueryUtils.RenderQueryString(queryObject);

            var response = await this.client.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultToken = JToken.Parse(json);
                return(resultToken);
            }
            return(null);
        }
Beispiel #4
0
        /**
         * Delete multiple entities
         */
        public async Task <JToken> DeleteItemsAsync(string entityTypeName, Dto[] items)
        {
            var entitySetName = this.metadataCli.EntityTypes[entityTypeName].EntitySetName;
            var keyNames      = this.metadataCli.EntityTypes[entityTypeName].Key;
            var url           = this.apiUrl + "/crud/" + "batch/" + entitySetName + "?" + QueryUtils.RenderQueryString(new QueryObject()
            {
                Keys = DataAdapterUtils.GetKeyFromMultipleData(keyNames, items).ToArray()
            });

            var response = await this.client.DeleteAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultSerialDataToken = JToken.Parse(json);
                return(resultSerialDataToken);
            }
            return(null);
        }
Beispiel #5
0
        /**
         * Update single entity
         */
        public async Task <JToken> PutItemAsync(string entityTypeName, Dto entity)
        {
            var entitySetName = this.metadataCli.EntityTypes[entityTypeName].EntitySetName;
            var keyNames      = this.metadataCli.EntityTypes[entityTypeName].Key;
            var url           = this.apiUrl + "/crud/" + entitySetName + "?" + QueryUtils.RenderQueryString(new QueryObject()
            {
                Keys = (new List <Dto>()
                {
                    DataAdapterUtils.GetKeyFromData(keyNames, entity)
                }).ToArray()
            });

            var jsonPatchItem = JsonConvert.SerializeObject(entity);
            var response      = await this.client.PutAsync(url, new StringContent(jsonPatchItem, Encoding.UTF8, "application/json"));

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultSingleSerialDataToken = JToken.Parse(json);
                return(resultSingleSerialDataToken);
            }
            return(null);
        }
Beispiel #6
0
        /**
         * Retrive a single entity
         */
        public async Task <JToken> LoadOneAsync(string entityTypeName, Dto partialDto, string[] expand)
        {
            var entitySetName = this.metadataCli.EntityTypes[entityTypeName].EntitySetName;
            var keyNames      = this.metadataCli.EntityTypes[entityTypeName].Key;
            var queryObject   = new QueryObject()
            {
                Keys   = (new List <Dto> {
                    DataAdapterUtils.GetKeyFromData(keyNames, partialDto)
                }).ToArray(),
                Expand = expand
            };
            var url = this.apiUrl + "/crud/" + "single/" + entitySetName + "?" + QueryUtils.RenderQueryString(queryObject);

            var response = await this.client.GetAsync(url);

            if (response.IsSuccessStatusCode)
            {
                var json = await response.Content.ReadAsStringAsync();

                var resultSingleSerialDataToken = JToken.Parse(json);
                return(resultSingleSerialDataToken);
            }
            return(null);
        }