Пример #1
0
        public void Rdeem(Invoice invoice, int numberOfDays)
        {
            // 防御性编程
            if (invoice == null)
            {
                throw new Exception("invoice为null!");
            }
            if (numberOfDays <= 0)
            {
                throw new Exception("numberOfDays不能为小于1!");
            }
            // logging
            Console.WriteLine("Redem:{0}", DateTime.Now);
            Console.WriteLine("Invoice:{0}", invoice.Id);

            _exceptionHandler.Wrapper(() =>
            {
                _transactionManager.Wrapper(() =>
                {
                    var pointsPerDay = 10;
                    if (invoice.Vehicle.Size >= Size.Luxury)
                    {
                        pointsPerDay = 15;
                    }
                    var totalPoints  = pointsPerDay * numberOfDays;
                    invoice.Discount = numberOfDays * invoice.CostPerDay;
                    _loyaltyDataService.SubstractPoints(invoice.Customer.Id, totalPoints);

                    // logging
                    Console.WriteLine("Redem completed:{0}", DateTime.Now);
                });
            });
        }
Пример #2
0
 public void Redeem(Invoice invoice, int numberOfDays)
 {
     //防御性编程
     if (invoice == null)
     {
         throw new Exception("invoice为null!");
     }
     if (numberOfDays <= 0)
     {
         throw new Exception("numberOfDays不能小于1!");
     }
     //logging
     Console.WriteLine("Redeem:{0}", DateTime.Now);
     Console.WriteLine("Invoice:{0}", invoice.Id);
     using (var ts = new TransactionScope())
     {
         try
         {
             var pointsPerDay = 10;
             if (invoice.Vehicle.Size >= Size.Luxury)
             {
                 pointsPerDay = 15;
             }
             var totalPoints = pointsPerDay * numberOfDays;
             invoice.Discount = numberOfDays * invoice.CostPerDay;
             _loyaltyDataService.SubstractPoints(invoice.Customer.Id, totalPoints);
             ts.Complete();
         }
         catch (Exception)
         {
             throw;
         }
     }
     Console.WriteLine("Redeem Complete:{0}", DateTime.Now);
 }
Пример #3
0
        public void Redeem(Invoice invoice, int numberOfDays)
        {
            var pointsPerday = 10;

            if (invoice.Vehicle.Size >= Size.Luxury)
            {
                pointsPerday = 15;
            }
            var totalPoints = numberOfDays * pointsPerday;

            _loyaltyDataService.SubstractPoints(invoice.Customer.Id, totalPoints);
            invoice.Discount = numberOfDays * invoice.CostPerDay;
        }