Beispiel #1
0
        public void AssignOffer(Guid memberId, Guid offerTypeId)
        {
            var member    = _memberRepository.GetById(memberId);
            var offerType = _offerTypeRepository.GetById(offerTypeId);

            var offer = member.AssignOffer(offerType, _offerValueCalculator);

            _offerRepository.Save(offer);
        }
Beispiel #2
0
        public void AssignOffer(Guid memberId, Guid offerTypeId)
        {
            // Retreive
            var member    = _memberRepository.GetById(memberId);
            var offerType = _offerTypeRepository.GetById(offerTypeId);

            // Delegate to business objects
            var offer = member.AssignOffer(offerType, _offerValueCalculator);

            // Save
            _offerRepository.Save(offer);
        }
        public void AssignOffer(Guid memberId, Guid offerTypeId)
        {
            var member    = _memberRepository.GetById(memberId);
            var offerType = _offerTypeRepository.GetById(offerTypeId);

            var value = _offerValueCalculator
                        .CalculateValue(member, offerType);

            DateTime dateExpiring;

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

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

            default:
                throw new ArgumentOutOfRangeException();
            }

            var offer = new Offer
            {
                MemberAssigned = member,
                Type           = offerType,
                Value          = value,
                DateExpiring   = dateExpiring
            };

            member.AssignedOffers.Add(offer);
            member.NumberOfActiveOffers++;

            _offerRepository.Save(offer);
        }