Esempio n. 1
0
        /// <summary>
        /// Updates multiple items
        /// </summary>
        /// <typeparam name="T">The type of the item to be updated</typeparam>
        /// <param name="items">A dictionary of id => item where item can be encoded
        /// with encoder</param>
        /// <param name="encoder">The encoder that can handle T</param>
        /// <param name="parms">Additional params for the platform</param>
        /// <returns>A dictionary of id => item</returns>
        public async Task <Dictionary <string, T> > UpdateMany <T>(Dictionary <string, T> items,
                                                                   IJsonEncoder <T> encoder, Dictionary <string, string> parms = null)
        {
            if (!this.canUpdate)
            {
                throw new FlowThingsNotImplementedException();
            }

            JObject jo = new JObject();

            foreach (KeyValuePair <string, T> kvp in items)
            {
                jo.Add(new JProperty(kvp.Key, encoder.Encode(kvp.Value)));
            }

            JToken jt = await this.RequestAsync("MPUT", "", jo, parms);

            Dictionary <string, T> d = new Dictionary <string, T>();

            foreach (KeyValuePair <string, JToken> kvp in (JObject)jt["body"])
            {
                string id   = kvp.Key;
                T      item = encoder.Decode(kvp.Value);

                d.Add(id, item);
            }

            return(d);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates the item with the passed ID on the platform.
        /// </summary>
        /// <typeparam name="T">The type of the item to be updated</typeparam>
        /// <param name="id">The ID of the item to be updated</param>
        /// <param name="item">The contents of the item -- all fields produced by Encode(item) will
        /// be updated on the platform; to update only certain fields use Update with dynamics
        /// below</param>
        /// <param name="encoder">The encoder that can encode/decode T to a JToken</param>
        /// <param name="parms">Additional parameters passed to the platform</param>
        /// <returns>The updated item as an object of type T</returns>
        public async Task <T> Update <T>(string id, T item, IJsonEncoder <T> encoder,
                                         Dictionary <string, string> parms = null)
        {
            if (!this.canUpdate)
            {
                throw new FlowThingsNotImplementedException();
            }

            JToken jt = await this.RequestAsync("PUT", "/" + id, encoder.Encode(item), parms);

            return(encoder.Decode(jt["body"]));
        }