/// <summary> /// Delete an instance from the table. /// </summary> /// <param name="instance">The instance to delete.</param> /// <param name="parameters">A dictionary of user-defined parameters and values to include in the request URI query string.</param> /// <returns> /// A task that will complete when the delete has finished. /// </returns> public Task DeleteAsync(T instance, IDictionary <string, string> parameters) { if (instance == null) { throw new ArgumentNullException("instance"); } // Serialize the instance JsonObject value = MobileServiceTableSerializer.Serialize(instance).AsObject(); // Send the request return(DeleteAsync(value, parameters) .ContinueWith(t => { if (t.IsFaulted) { throw t.Exception.InnerException; } // Clear the instance ID since it's no longer associated with that // ID on the server (note that reflection is goodly enough to turn // null into the correct value for us). SerializableType type = SerializableType.Get(typeof(T)); type.IdMember.SetValue(instance, null); })); }
/// <summary> /// Insert a new instance into the table. /// </summary> /// <param name="instance">The instance to insert.</param> /// <param name="parameters">A dictionary of user-defined parameters and values to include in the request URI query string.</param> /// <returns> /// A task that will complete when the insertion has finished. /// </returns> public Task InsertAsync(T instance, IDictionary <string, string> parameters) { if (instance == null) { throw new ArgumentNullException("instance"); } // Serialize the instance JsonObject value = MobileServiceTableSerializer.Serialize(instance).AsObject(); return(InsertAsync(value, parameters) .ContinueWith(t => MobileServiceTableSerializer.Deserialize(t.Result, instance))); }
/// <summary> /// Updates an instance in the table. /// </summary> /// <param name="instance">The instance to update.</param> /// <returns> /// A task that will complete when the update has finished. /// </returns> public Task UpdateAsync(T instance) { if (instance == null) { throw new ArgumentNullException("instance"); } // Serialize the instance JsonObject value = MobileServiceTableSerializer.Serialize(instance).AsObject(); // Send the request return(UpdateAsync(value) .ContinueWith(t => MobileServiceTableSerializer.Deserialize(t.Result, instance))); }
/// <summary> /// Updates an instance in the table. /// </summary> /// <param name="instance">The instance to update.</param> /// <returns> /// A task that will complete when the update has finished. /// </returns> public async Task UpdateAsync(T instance) { if (instance == null) { throw new ArgumentNullException("instance"); } // Serialize the instance JObject value = MobileServiceTableSerializer.Serialize(instance).AsObject(); // Send the request JToken response = await this.UpdateAsync(value); // Deserialize the response back into the instance in case any // server scripts changed values of the instance. MobileServiceTableSerializer.Deserialize(response, instance); }
/// <summary> /// Updates an instance in the table. /// </summary> /// <param name="instance">The instance to update.</param> /// <param name="parameters"> /// A dictionary of user-defined parameters and values to include in the request URI query string. /// </param> /// <returns> /// A task that will complete when the update has finished. /// </returns> public async Task UpdateAsync(T instance, IDictionary <string, string> parameters) { if (instance == null) { throw new ArgumentNullException("instance"); } // Serialize the instance JsonObject value = MobileServiceTableSerializer.Serialize(instance).AsObject(); // Send the request IJsonValue response = await this.UpdateAsync(value, parameters); // Deserialize the response back into the instance in case any // server scripts changed values of the instance. MobileServiceTableSerializer.Deserialize(response, instance); }
/// <summary> /// Delete an instance from the table. /// </summary> /// <param name="instance">The instance to delete.</param> /// <returns> /// A task that will complete when the delete has finished. /// </returns> public async Task DeleteAsync(T instance) { if (instance == null) { throw new ArgumentNullException("instance"); } // Serialize the instance JObject value = MobileServiceTableSerializer.Serialize(instance).AsObject(); // Send the request await this.DeleteAsync(value); // Clear the instance ID since it's no longer associated with that // ID on the server (note that reflection is goodly enough to turn // null into the correct value for us). SerializableType type = SerializableType.Get(typeof(T)); type.IdMember.SetValue(instance, null); }