예제 #1
0
        public async Task <decimal> GetInvoicesTotal()
        {
            var aggregator = DemoProxy.InvoiceAggregator("AllInvoices");
            var totals     = await aggregator.GetInvoiceTotals();

            return(totals);
        }
예제 #2
0
        public async Task UpdateInvoice(Invoice invoice)
        {
            var myDictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <int, List <Invoice> > >("InvoiceData");

            var     aggregator = DemoProxy.InvoiceAggregator("AllInvoices");
            decimal oldTotal   = 0;
            var     newTotal   = invoice.InvoiceTotal;


            using (var tx = this.StateManager.CreateTransaction())
            {
                var result = await myDictionary.TryGetValueAsync(tx, 0);

                var invoices = result.Value;

                var selectedInvoice = result.Value
                                      .FirstOrDefault(_invoice => _invoice.Id == invoice.Id);

                oldTotal = selectedInvoice.InvoiceTotal;

                selectedInvoice.Items = invoice.Items;

                await myDictionary.TryUpdateAsync(tx, 0, invoices, invoices);

                await tx.CommitAsync();

                try
                {
                    decimal updatedTotal = newTotal - oldTotal;
                    await aggregator.AddToInvoiceTotal(updatedTotal);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);

                    throw;
                }
            }
        }