public async Task <BalanceBook> UpsertBalanceBook(BalanceBook balanceBook) { var entity = CreateBalanceBookEntity(balanceBook); await Store(entity); var updatedBook = await GetBalanceBook(); return(updatedBook); }
private TableEntity <BalanceBook> CreateBalanceBookEntity(BalanceBook book) { var entity = new TableEntity <BalanceBook>(book) { PartitionKey = PartitionBalanceKey, RowKey = BalanceBookRowKey, Timestamp = DateTimeOffset.UtcNow, ETag = "*" }; return(entity); }
public static IList <Block> BuildBalanceMessage(BalanceBook balanceBook) { var blocks = new List <Block>(); var balanceBlock = new SectionBlock() { BlockId = "balance_summary", Text = new Markdown("") }; foreach (var pair in balanceBook.Balances.Values .Where(x => x.Balance != 0) .OrderBy(x => x.Key)) { var balanceStr = Math.Abs(pair.Balance).ToString("0.00", CultureInfo.InvariantCulture); balanceStr = pair.Balance > 0 ? $" :arrow_left: {balanceStr} :arrow_left: " : $" :arrow_right: {balanceStr} :arrow_right: "; balanceBlock.Text.Text += $"> {pair.PartyA.ToSlackMention()}{balanceStr}{pair.PartyB.ToSlackMention()}\n"; } var(biggestDebtor, biggestDebt) = balanceBook.FindBiggestDebtor(); if (biggestDebtor != null) { balanceBlock.Text.Text += $"{biggestDebtor.ToSlackMention()} should host the next order (total: *{biggestDebt:F2}*)"; } if (string.IsNullOrWhiteSpace(balanceBlock.Text.Text)) { balanceBlock.Text = new PlainText("Everyone is even."); } blocks.Add(balanceBlock); return(blocks); }