Beispiel #1
0
        /// <summary>
        /// Applies business rules to a partner offer.
        /// </summary>
        /// <param name="partnerOffer">The partner offer to normalize.</param>
        public void Normalize(PartnerOffer partnerOffer)
        {
            partnerOffer.AssertNotNull(nameof(partnerOffer));

            // ensure the Microsoft offer ID and other required properties are set
            Guid offerId;

            if (!Guid.TryParse(partnerOffer.Id, out offerId))
            {
                throw new PartnerDomainException(ErrorCode.InvalidInput, "Id must be a valid GUID").AddDetail("Field", "Id");
            }

            if (string.IsNullOrWhiteSpace(partnerOffer.MicrosoftOfferId))
            {
                throw new PartnerDomainException(ErrorCode.InvalidInput, "MicrosoftOfferId must be set").AddDetail("Field", "MicrosoftOfferId");
            }

            partnerOffer.Title.AssertNotEmpty("Offer title");

            if (partnerOffer.Price <= 0)
            {
                throw new PartnerDomainException(ErrorCode.InvalidInput, "Offer price should be more than zero").AddDetail("Field", "Price");
            }

            partnerOffer.Features = PartnerOfferNormalizer.CleanupEmptyEntries(partnerOffer.Features);
            partnerOffer.Summary  = PartnerOfferNormalizer.CleanupEmptyEntries(partnerOffer.Summary);
        }
Beispiel #2
0
        /// <summary>
        /// Applies business rules to a partner offer.
        /// </summary>
        /// <param name="partnerOffer">The partner offer to normalize.</param>
        public void Normalize(PartnerOffer partnerOffer)
        {
            partnerOffer.AssertNotNull(nameof(partnerOffer));

            // ensure the Microsoft offer ID and other required properties are set
            Guid offerId;

            if (!Guid.TryParse(partnerOffer.Id, out offerId))
            {
                throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.IdMustBeAValidGUID).AddDetail("Field", "Id");
            }

            if (string.IsNullOrWhiteSpace(partnerOffer.MicrosoftOfferId))
            {
                throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.MicrosoftOfferIdMustBeSet).AddDetail("Field", "MicrosoftOfferId");
            }

            partnerOffer.Title.AssertNotEmpty("Offer title");

            if (partnerOffer.Price <= 0)
            {
                throw new PartnerDomainException(ErrorCode.InvalidInput, Resources.OfferPriceShouldBeMoreThanZero).AddDetail("Field", "Price");
            }

            // flatten the offer price based on locale decimal settings.
            partnerOffer.Price = Math.Round(partnerOffer.Price, Resources.Culture.NumberFormat.CurrencyDecimalDigits, MidpointRounding.AwayFromZero);

            partnerOffer.Features = PartnerOfferNormalizer.CleanupEmptyEntries(partnerOffer.Features);
            partnerOffer.Summary  = PartnerOfferNormalizer.CleanupEmptyEntries(partnerOffer.Summary);
        }