Exemple #1
0
        public Purchase Create(string orderId, Offer.Offer offer)
        {
            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Offer.Offer));

            using (StringWriter sw = new StringWriter())
            {
                xmlSerializer.Serialize((TextWriter)sw, (object)offer);
                return(new Purchase(orderId, sw.GetStringBuilder().ToString()));
            }
        }
        private Policy(Guid policyId, Offer.Offer offer, DateTime purchaseDate, DateTime policyStartDate)
        {
            if (offer.Converted())
            {
                throw new ApplicationException("Offer already converted");
            }

            if (offer.Rejected())
            {
                throw new ApplicationException("Offer already rejected");
            }

            if (offer.Expired(purchaseDate))
            {
                throw new ApplicationException("Offer expired");
            }


            if (offer.Expired(policyStartDate))
            {
                throw new ApplicationException("Offer not valid at policy start date");
            }

            var policyNumber = Guid.NewGuid().ToString();
            var coverPeriod  = ValidityPeriod.Between
                               (
                policyStartDate,
                policyStartDate.Add(offer.CoverPeriod)
                               );
            var covers = offer.Covers
                         .Select(c => PolicyCover.ForPrice(c, coverPeriod))
                         .ToList();

            Id = policyId;
            ApplyChange(
                new InitialPolicyVersionCreated
                (
                    policyNumber,
                    offer.ProductCode,
                    coverPeriod,
                    purchaseDate,
                    offer.Customer,
                    offer.Car,
                    covers
                )
                );
        }
Exemple #3
0
        public Purchase Create(AggregateId orderId, Client.Client client, Offer.Offer offer)
        {
            if (!CanPurchse(client, offer.AvailableItems))
            {
                throw new DomainOperationException(client.AggregateId, "client can not purchase");
            }

            List <PurchaseItem> items = new List <PurchaseItem>(offer.AvailableItems.Count());
            Money purchaseTotlCost    = Money.ZERO;

            foreach (OfferItem item in offer.AvailableItems)
            {
                PurchaseItem purchaseItem = new PurchaseItem(item.ProductData, item.TotalCost);
                items.Add(purchaseItem);
                purchaseTotlCost = purchaseTotlCost.Add(purchaseItem.TotalCost);
            }

            Purchase purchase = new Purchase(orderId, client.AggregateId,
                                             items, Date.Today(), false, purchaseTotlCost);

            _dependencyInjector.InjectDependencies(purchase);

            return(purchase);
        }
Exemple #4
0
 public void NotifyOfRejectedOffer(Offer.Offer offer)
 {
     throw new NotImplementedException();
 }
 public static Policy BuyOffer(Offer.Offer offer, DateTime purchaseDate, DateTime policyStartDate)
 {
     return(new Policy(Guid.NewGuid(), offer, purchaseDate, policyStartDate));
 }