예제 #1
0
        public Incentive AssignIncentive(IncentiveDefinition incentiveDefinition, IIncentiveValueCalculator incentiveValueCalculator, ISystemClock systemClock)
        {
            var incentiveValue = incentiveValueCalculator.CalculateValue(this, incentiveDefinition);
            var expirationDate = incentiveDefinition.CalculateExpirationDate(systemClock);

            var incentive = new Incentive(this, incentiveDefinition, expirationDate, incentiveValue);

            _assignedIncentives.Add(incentive);
            return(incentive);
        }
예제 #2
0
        public void AssignIncentive(Guid traderId, Guid incentiveDefinitionId)
        {
            var trader = _traderRepository.GetById(traderId);
            var incentiveDefinition = _incentiveDefinitionRepository.GetById(incentiveDefinitionId);
            var incentiveValue      = _incentiveValueCalculator.CalculateValue(trader, incentiveDefinition);

            DateTime dateExpiring;

            switch (incentiveDefinition.ExpirationType)
            {
            case ExpirationType.Assignment:
                dateExpiring = DateTime.Now.AddDays(incentiveDefinition.DaysValid);
                break;

            case ExpirationType.Fixed:
                if (incentiveDefinition.BeginDate != null)
                {
                    dateExpiring = incentiveDefinition.BeginDate.Value.AddDays(incentiveDefinition.DaysValid);
                }
                else
                {
                    throw new InvalidOperationException();
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var incentive = new Incentive
            {
                TraderAssigned      = trader,
                IncentiveDefinition = incentiveDefinition,
                Value        = incentiveValue,
                DateExpiring = dateExpiring
            };

            trader.AssignedIncentives.Add(incentive);
            trader.NumberOfAssignedIncentives++;

            _incentiveRepository.Save(incentive);
        }