Пример #1
0
        /// <summary>
        /// Update an entity into table
        /// </summary>
        /// <param name="table">Table name</param>
        /// <param name="entity">Entity object</param>
        /// <param name="noscript">NoScript flag</param>
        /// <returns>JSON string object result</returns>
        internal string Update(string table, IMobileServiceEntity entity, bool noscript = false)
        {
            // fill body
            this.body.Clear();
            this.body.Append(entity.ToJson());

            // build URI
            this.uri.Clear();
            this.uri.Append(this.applicationUri.AbsoluteUri)
            .Append("tables/")
            .Append(table)
            .Append("/")
            .Append(entity.Id);

            if (noscript)
            {
                if (this.masterKey == null)
                {
                    throw new ArgumentException("For noscript you must also supply the service master key");
                }
                this.uri.Append("?noscript=true");
            }

            this.httpRequest.Uri           = new Uri(this.uri.ToString());
            this.httpRequest.Method        = HttpMethod.Patch;
            this.httpRequest.Body          = Encoding.UTF8.GetBytes(body.ToString());
            this.httpRequest.ContentLength = this.httpRequest.Body.Length;

            HttpResponse httpResp = this.httpClient.Send(this.httpRequest);

            return(httpResp.GetBodyAsString());
        }
Пример #2
0
        /// <summary>
        /// Update an entity into table
        /// </summary>
        /// <param name="table">Table name</param>
        /// <param name="entity">Entity object</param>
        /// <param name="noscript">NoScript flag</param>
        /// <returns>JSON string object result</returns>
        internal string Update(string table, IMobileServiceEntity entity, bool noscript = false)
        {
            // fill body
            this.body.Clear();
            this.body.Append(entity.ToJson());

            // build URI
            this.uri.Clear();
            this.uri.Append(this.applicationUri.AbsoluteUri)
                .Append("tables/")
                .Append(table)
                .Append("/")
                .Append(entity.Id);

            if (noscript)
            {
                if (this.masterKey == null)
                    throw new ArgumentException("For noscript you must also supply the service master key");
                this.uri.Append("?noscript=true");
            }

            this.httpRequest.Uri = new Uri(this.uri.ToString());
            this.httpRequest.ContentLength = body.Length;
            this.httpRequest.Method = HttpMethod.Patch;

            HttpResponse httpResp = this.httpClient.Send(this.httpRequest);

            return body.ToString();
        }