Пример #1
0
 public Minutes MinutesWhichCanCover(PhoneCall phoneCall, IClock clock)
 {
     if (Allowance.IsGreaterOrEqualTo(phoneCall.Minutes))
     {
         return(phoneCall.Minutes);
     }
     else
     {
         return(Allowance);
     }
 }
Пример #2
0
 public Minutes MinutesWhichCanCover(PhoneCall phoneCall, IClock clock)
 {
     if (Allowance.IsGreaterOrEqualTo(phoneCall.Minutes))
     {
         return phoneCall.Minutes;
     }
     else
     {
         return Allowance;
     }
 }
Пример #3
0
        public void Record(PhoneCall phoneCall, PhoneCallCosting phoneCallCosting, IClock clock) 
        {
            var numberOfMinutesCoveredByAllowance = new Minutes();
      
            if (_freeCallAllowance != null)
                numberOfMinutesCoveredByAllowance = _freeCallAllowance.MinutesWhichCanCover(phoneCall, clock);

            var numberOfMinutesToChargeFor = phoneCall.Minutes.Subtract(numberOfMinutesCoveredByAllowance);

            var costOfCall = phoneCallCosting.DetermineCostOfCall(numberOfMinutesToChargeFor);

            Causes(new PhoneCallCharged(this.Id, phoneCall, costOfCall, numberOfMinutesCoveredByAllowance));
        }
        public void Record(PhoneCall phoneCall, PhoneCallCosting phoneCallCosting, IClock clock)
        {
            var numberOfMinutesCoveredByAllowance = new Minutes();

            if (_freeCallAllowance != null)
            {
                numberOfMinutesCoveredByAllowance = _freeCallAllowance.MinutesWhichCanCover(phoneCall, clock);
            }

            var numberOfMinutesToChargeFor = phoneCall.Minutes.Subtract(numberOfMinutesCoveredByAllowance);

            var costOfCall = phoneCallCosting.DetermineCostOfCall(numberOfMinutesToChargeFor);

            Causes(new PhoneCallCharged(this.Id, phoneCall, costOfCall, numberOfMinutesCoveredByAllowance));
        }
Пример #5
0
        public void Execute(Guid id, string phoneNumber, DateTime callStart, int callLengthInMinutes)
        {
            try{
                var payAsYouGoAccount = _payAsYouGoAccountRepository.FindBy(id);

                var numberDialled = new PhoneNumber(phoneNumber);
                var phoneCall = new PhoneCall(numberDialled, callStart, new Minutes(callLengthInMinutes));

                payAsYouGoAccount.Record(phoneCall, new PhoneCallCosting(), _clock);

                _payAsYouGoAccountRepository.Save(payAsYouGoAccount);

                _unitOfWork.SaveChanges();
            }
            catch (ConcurrencyException ex)
            {
                _unitOfWork.Advanced.Clear();

                // TODO: Add logic to retry X times then move to an error queue
                // Execute(id, phoneNumber, callStart, callLengthInMinutes);

                throw ex;
            }
        }
Пример #6
0
 public PhoneCallCharged(Guid aggregateId, PhoneCall phoneCall, Money costOfCall, Minutes coveredByAllowance) : base (aggregateId)
 {
     PhoneCall = phoneCall;
     CostOfCall = costOfCall;
     CoveredByAllowance = coveredByAllowance;
 }
 public PhoneCallCharged(Guid aggregateId, PhoneCall phoneCall, Money costOfCall, Minutes coveredByAllowance) : base(aggregateId)
 {
     PhoneCall          = phoneCall;
     CostOfCall         = costOfCall;
     CoveredByAllowance = coveredByAllowance;
 }