Пример #1
0
        /// <summary>
        /// Gets the customers.
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <Customer> > GetAllCustomers()
        {
            var service = DemoProxy.CustomerService();
            var result  = await service.GetAllCustomers();

            return(result);
        }
Пример #2
0
        public async Task <int> CustomerCount()
        {
            var service = DemoProxy.CustomerService();
            var result  = await service.CustomerCount();

            return(result);
        }
Пример #3
0
        public async Task <decimal> GetInvoicesTotal()
        {
            var aggregator = DemoProxy.InvoiceAggregator("AllInvoices");
            var totals     = await aggregator.GetInvoiceTotals();

            return(totals);
        }
Пример #4
0
        /// <summary>
        /// Gets the customer.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <Customer> GetCustomer(int id)
        {
            var service = DemoProxy.CustomerService();
            var result  = await service.GetCustomer(id);

            return(result);
        }
Пример #5
0
        /// <summary>
        /// Gets the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public async Task <string> Get(string key)
        {
            var service = DemoProxy.CacheService(key);
            var value   = await service.Get(key);

            return(value);
        }
Пример #6
0
        /// <summary>
        /// Gets the customers.
        /// </summary>
        /// <returns></returns>
        public async Task <IEnumerable <Invoice> > GetAllInvoicesForCustomer(int customerId)
        {
            var service = DemoProxy.InvoiceService();
            var result  = await service.GetAllInvoicesForCustomer(customerId);

            return(result);
        }
Пример #7
0
        public async Task <int> AddInvoice(int customerId)
        {
            var service   = DemoProxy.InvoiceService();
            var invoiceId = await service.AddInvoice(customerId);

            return(invoiceId);
        }
Пример #8
0
        /// <summary>
        /// Gets the customer.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public async Task <Invoice> GetInvoice(int id)
        {
            var service = DemoProxy.InvoiceService();
            var result  = await service.GetInvoice(id);

            return(result);
        }
Пример #9
0
        public void Test_demo()
        {
            // Test iwth real subject
            DemoClient  client      = new DemoClient();
            RealSubject realSubject = new RealSubject();

            client.ClientCode(realSubject);

            // Test with proxy
            DemoProxy proxy = new DemoProxy(realSubject);

            client.ClientCode(proxy);
        }
Пример #10
0
        public async Task <CounterStats> IncrementClickCount()
        {
            try
            {
                var counter = DemoProxy.CounterService();

                var result = await counter.IncrementClickCount();

                return(result);
            }
            catch (Exception ex)
            {
                return(new CounterStats()
                {
                    ClickCount = 0,
                    ServedBy = ex.Message
                });
            }
        }
Пример #11
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;
                }
            }
        }
Пример #12
0
 public async Task RemoveCustomer(int customerId)
 {
     var service = DemoProxy.CustomerService();
     await service.RemoveCustomer(customerId);
 }
Пример #13
0
 public async Task AddCustomer(Customer customer)
 {
     var service = DemoProxy.CustomerService();
     await service.AddCustomer(customer);
 }
Пример #14
0
        public async Task AddOrUpdate(string key, [FromBody] string value)
        {
            var service = DemoProxy.CacheService(key);

            await service.AddOrUpdate(key, value);
        }
Пример #15
0
 public async Task UpdateInvoice(Invoice invoice)
 {
     var service = DemoProxy.InvoiceService();
     await service.UpdateInvoice(invoice);
 }