Skip to content

Instantly share code, notes, and snippets.

@forki
Created December 14, 2018 10:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save forki/80a6ea8b823ab7205f7d27788e266603 to your computer and use it in GitHub Desktop.
Save forki/80a6ea8b823ab7205f7d27788e266603 to your computer and use it in GitHub Desktop.
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