public async Task UpdateAsync(string tableName, MobileServiceTableKind tableKind, string id, JObject item) { var operation = new UpdateOperation(tableName, tableKind, id) { Table = await this.GetTable(tableName) }; await this.ExecuteOperationAsync(operation, item); }
internal static MobileServiceTableOperation Deserialize(JObject obj) { if (obj == null) { return(null); } var kind = (MobileServiceTableOperationKind)obj.Value <int>("kind"); string tableName = obj.Value <string>("tableName"); var tableKind = (MobileServiceTableKind)obj.Value <int?>("tableKind").GetValueOrDefault(); string itemId = obj.Value <string>("itemId"); MobileServiceTableOperation operation = null; switch (kind) { case MobileServiceTableOperationKind.Insert: operation = new InsertOperation(tableName, tableKind, itemId); break; case MobileServiceTableOperationKind.Update: operation = new UpdateOperation(tableName, tableKind, itemId); break; case MobileServiceTableOperationKind.Delete: operation = new DeleteOperation(tableName, tableKind, itemId); break; } if (operation != null) { operation.Id = obj.Value <string>(MobileServiceSystemColumns.Id); operation.Sequence = obj.Value <long?>("sequence").GetValueOrDefault(); operation.Version = obj.Value <long?>("version").GetValueOrDefault(); string itemJson = obj.Value <string>("item"); operation.Item = !String.IsNullOrEmpty(itemJson) ? JObject.Parse(itemJson) : null; operation.State = (MobileServiceTableOperationState)obj.Value <int?>("state").GetValueOrDefault(); } return(operation); }
public void Collapse_CancelsNewOperation_WithUpdateOperation() { var newOperation = new UpdateOperation("test", MobileServiceTableKind.Table, "abc"); this.operation.Collapse(newOperation); // new operation should be cancelled Assert.IsTrue(newOperation.IsCancelled); // existing operation should be updated and not cancelled Assert.IsFalse(this.operation.IsCancelled); Assert.IsTrue(this.operation.IsUpdated); Assert.AreEqual(this.operation.Version, 2); }
public void Validate_Succeeds_WithUpdateOperation() { var newOperation = new UpdateOperation("test", MobileServiceTableKind.Table, "abc"); this.operation.Validate(newOperation); }
public void Initialize() { this.operation = new UpdateOperation("test", MobileServiceTableKind.Table, "abc"); }
public void Validate_Throws_WithUpdateOperation() { var tableOperation = new UpdateOperation("test", MobileServiceTableKind.Table, "abc"); TestDeleteValidateThrows(tableOperation); }
internal static MobileServiceTableOperation Deserialize(JObject obj) { if (obj == null) { return null; } var kind = (MobileServiceTableOperationKind)obj.Value<int>("kind"); string tableName = obj.Value<string>("tableName"); var tableKind = (MobileServiceTableKind)obj.Value<int?>("tableKind").GetValueOrDefault(); string itemId = obj.Value<string>("itemId"); MobileServiceTableOperation operation = null; switch (kind) { case MobileServiceTableOperationKind.Insert: operation = new InsertOperation(tableName, tableKind, itemId); break; case MobileServiceTableOperationKind.Update: operation = new UpdateOperation(tableName, tableKind, itemId); break; case MobileServiceTableOperationKind.Delete: operation = new DeleteOperation(tableName, tableKind, itemId); break; } if (operation != null) { operation.Id = obj.Value<string>(MobileServiceSystemColumns.Id); operation.Sequence = obj.Value<long?>("sequence").GetValueOrDefault(); operation.Version = obj.Value<long?>("version").GetValueOrDefault(); string itemJson = obj.Value<string>("item"); operation.Item = !String.IsNullOrEmpty(itemJson) ? JObject.Parse(itemJson) : null; operation.State = (MobileServiceTableOperationState)obj.Value<int?>("state").GetValueOrDefault(); } return operation; }