Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public async Task <int> CustomerCount()
        {
            var service = DemoProxy.CustomerService();
            var result  = await service.CustomerCount();

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <decimal> GetInvoicesTotal()
        {
            var aggregator = DemoProxy.InvoiceAggregator("AllInvoices");
            var totals     = await aggregator.GetInvoiceTotals();

            return(totals);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
0
        public async Task <int> AddInvoice(int customerId)
        {
            var service   = DemoProxy.InvoiceService();
            var invoiceId = await service.AddInvoice(customerId);

            return(invoiceId);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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
                });
            }
        }
Ejemplo n.º 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;
                }
            }
        }
Ejemplo n.º 12
0
 public async Task RemoveCustomer(int customerId)
 {
     var service = DemoProxy.CustomerService();
     await service.RemoveCustomer(customerId);
 }
Ejemplo n.º 13
0
 public async Task AddCustomer(Customer customer)
 {
     var service = DemoProxy.CustomerService();
     await service.AddCustomer(customer);
 }
Ejemplo n.º 14
0
        public async Task AddOrUpdate(string key, [FromBody] string value)
        {
            var service = DemoProxy.CacheService(key);

            await service.AddOrUpdate(key, value);
        }
Ejemplo n.º 15
0
 public async Task UpdateInvoice(Invoice invoice)
 {
     var service = DemoProxy.InvoiceService();
     await service.UpdateInvoice(invoice);
 }