Created
December 14, 2018 10:50
-
-
Save forki/80a6ea8b823ab7205f7d27788e266603 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec getNextInvoiceNo (table:CloudTable) operatorID = task { | |
let rowKey = "invoiceno" | |
let query = TableOperation.Retrieve(operatorID, rowKey) | |
let! r = table.ExecuteAsync(query) | |
if r.HttpStatusCode <> 200 || isNull r.Result then | |
let entity = DynamicTableEntity() | |
entity.PartitionKey <- operatorID | |
entity.RowKey <- rowKey | |
let no = 1 | |
let operation = TableOperation.Insert entity | |
entity.PartitionKey <- operatorID | |
entity.RowKey <- rowKey | |
entity.Properties.["InvoiceNo"] <- EntityProperty.GeneratePropertyForInt(System.Nullable(no + 1)) | |
let! _ = table.ExecuteAsync operation | |
return no | |
else | |
let entity = r.Result :?> DynamicTableEntity | |
let no = getIntProperty "InvoiceNo" entity | |
let operation = TableOperation.Replace entity | |
entity.Properties.["InvoiceNo"] <- EntityProperty.GeneratePropertyForInt(System.Nullable(no + 1)) | |
try | |
let! r = table.ExecuteAsync operation | |
return no | |
with | |
| _ -> return! getNextInvoiceNo table operatorID | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment