public void RejectOffer(Offer offer) { if (offer == null) throw new ArgumentNullException("offer"); offer.CompleteOffer(success: false); DomainEvents.Raise(new OfferLostEvent { Offer = offer }); }
public void AcceptOffer(Offer offer) { if (offer == null) throw new ArgumentNullException("offer"); offer.CompleteOffer(success: true); DomainEvents.Raise(new OfferWonEvent { Offer = offer }); }
/// <summary> /// Initializes a new instance of the <see cref="OfferDraft"/> class. /// </summary> /// <param name="sourceOffer">Source offer from which to create a new draft</param> private OfferDraft(Offer sourceOffer) { if (sourceOffer == null) throw new ArgumentNullException("sourceOffer"); _sourceOffer = sourceOffer; _owner = sourceOffer.Owner; _title = sourceOffer.Title; _customer = sourceOffer.Customer; _discount = sourceOffer.Discount; _createdOn = DateTime.Now; }
/// <summary> /// Creates a new <see cref="Offer"/> based on current draft state. /// </summary> /// <param name="expiresOn"><see cref="DateTime"/> until which the offer is valid.</param> /// <returns>A new <see cref="Offer"/> instance.</returns> public virtual Offer CreateOffer(DateTime expiresOn) { if (expiresOn < DateTime.Now) throw new ArgumentOutOfRangeException("expiresOn"); if (Owner == null) throw new InvalidOperationException("Owner should be defined before creating an offer."); if (Customer == null) throw new InvalidOperationException("Customer should be defined before creating an offer."); var offer = new Offer(this, expiresOn); foreach (var draftItem in Items) offer.AddItem(new OfferItem(draftItem)); return offer; }
/// <summary> /// Creates a new draft from given offer. /// </summary> /// <returns>A new <see cref="OfferDraft"/> instance.</returns> public static OfferDraft CreateFromOffer(Offer sourceOffer) { if (sourceOffer == null) throw new ArgumentNullException("sourceOffer"); var draft = new OfferDraft(sourceOffer); foreach (var item in sourceOffer.Items) { var draftItem = new OfferDraftItem(item.Product, item.Quantity); draft.AddItem(draftItem); draft.ChangeItemDiscount(draftItem, item.Discount); } return draft; }