public void AssignIncentiveToTrader(Guid traderId, Guid incentiveDefinitionId)
        {
            var trader = _traderRepository.GetById(traderId);
            var incentiveDefinition = _incentiveDefinitionRepository.GetById(incentiveDefinitionId);

            var incentive = trader.AssignIncentive(incentiveDefinition, _incentiveValueCalculator, _systemClock);

            _incentiveRepository.Save(incentive);
        }
Esempio n. 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);
        }