Example #1
0
        public void AddTransaction(CustomerTransaction customerTransaction)
        {
            using (var transaction = new TransactionScope())
            using (var connection = new ConnectionScope())
            {
                var customer = GetCustomer(customerTransaction.CustomerId);
                if (customer == null)
                    throw new Exception("Customer not found");

                customerTransaction.Insert();
                customer.Balance += customerTransaction.Amount;
                customer.Update();

                transaction.Complete();
            }
        }
Example #2
0
        public void AddAdjustment()
        {
            ICustomerService customerService = new CustomerService(new CustomerManager());

            var customer = customerService.GetCustomers().First();

            var transaction = new CustomerTransaction
            {
                Id = Guid.NewGuid(),
                CustomerId = customer.Id,
                DateTime = DateTimeOffset.Now,
                Type = CustomerTransactionType.Adjustment,
                Amount = -10.0m
            };

            customerService.AddTransaction(transaction);

            // Check customer balance.
            Assert.AreEqual<decimal>(customer.Balance - 10.0m, customerService.GetCustomer(customer.Id).Balance);
        }
        public void Save()
        {
            var payment = new CustomerTransaction
            {
                Id = Guid.NewGuid(),
                CustomerId = Customer.Id,
                DateTime = DateTimeOffset.Now,
                Type = CustomerTransactionType.Payment,
                Amount = Amount * -1
            };

            CustomerService.AddTransaction(payment);

            Close();
        }
Example #4
0
        public void CompletePayment()
        {
            var processvm = IoC.Get<ProcessViewModel>();
            processvm.Content = "Processing...";

            processvm.ProcessAction = () =>
            {
                var payment = new CustomerTransaction
                {
                    Id = Guid.NewGuid(),
                    CustomerId = Customer.Id,
                    DateTime = DateTimeOffset.Now,
                    Type = CustomerTransactionType.Payment,
                    Amount = Total * -1
                };

                CustomerService.AddTransaction(payment);

                Customer.Balance = CustomerService.GetCustomer(Customer.Id).Balance;
            };

            processvm.CompleteAction = () =>
            {
                var message = IoC.Get<MessageBoxViewModel>();
                message.Content = new CustomerTransactionInfo { NewBalance = Customer.Balance };
                message.DismissAction = () => ScreenCoordinator.NavigateToHome();
                message.DismissTimeout = 2500;

                ScreenCoordinator.NavigateToScreen(message);
            };

            ScreenCoordinator.NavigateToScreen(processvm);
        }
Example #5
0
 public void AddTransaction(CustomerTransaction transaction)
 {
     Manager.AddTransaction(transaction);
 }
Example #6
0
 public CustomerTransactionModel(CustomerTransaction customerTransaction, Customer customer)
 {
     CustomerTransaction = customerTransaction;
     Customer = customer;
 }