internal static async Task SetValueInternalAsync()

in src/WebJobs.Extensions.MobileApps/Bindings/MobileTableItemValueBinder.cs [77:116]


        internal static async Task SetValueInternalAsync(JObject originalItem, object newItem, MobileTableContext context)
        {
            JObject currentValue = null;
            bool isJObject = newItem.GetType() == typeof(JObject);

            if (isJObject)
            {
                currentValue = newItem as JObject;
            }
            else
            {
                currentValue = JObject.FromObject(newItem);
            }

            if (HasChanged(originalItem, currentValue))
            {
                // make sure it's not the Id that has changed
                if (!string.Equals(GetId(originalItem), GetId(currentValue), StringComparison.Ordinal))
                {
                    throw new InvalidOperationException("Cannot update the 'Id' property.");
                }

                if (isJObject)
                {
                    IMobileServiceTable table = context.Client.GetTable(context.ResolvedAttribute.TableName);
                    await table.UpdateAsync((JObject)newItem);
                }
                else
                {
                    // If TableName is specified, add it to the internal table cache. Now items of this type
                    // will operate on the specified TableName.
                    if (!string.IsNullOrEmpty(context.ResolvedAttribute.TableName))
                    {
                        context.Client.AddToTableNameCache(newItem.GetType(), context.ResolvedAttribute.TableName);
                    }
                    IMobileServiceTable<T> table = context.Client.GetTable<T>();
                    await table.UpdateAsync((T)newItem);
                }
            }
        }