Exemplo n.º 1
0
        public static Result <PriceType> New(Title title, IPriceTypePolicy policy)
        {
            if (title == null)
            {
                throw new ArgumentNullException(nameof(title));
            }
            if (policy == null)
            {
                throw new ArgumentNullException(nameof(policy));
            }

            var priceType = new PriceType(title);

            if (!policy.IsUnique(priceType))
            {
                return(Fail <PriceType>("PriceType Title Should Be Unique"));
            }

            priceType.RaiseDomainEvent(new PriceTypeCreated(priceType));

            return(Ok(priceType));
        }
Exemplo n.º 2
0
        public Result <ProductPrice> AddPrice(PriceType priceType, Price price)
        {
            if (priceType == null)
            {
                throw new ArgumentNullException(nameof(priceType));
            }
            if (price == null)
            {
                throw new ArgumentNullException(nameof(price));
            }

            if (_prices.Exists(p => p.PriceType == priceType))
            {
                return(Fail <ProductPrice>($"A Price With PriceType:{priceType.Title} Already Exists"));
            }

            var productPrice = new ProductPrice(this, priceType, price);

            _prices.Add(productPrice);

            return(Ok(productPrice));
        }
Exemplo n.º 3
0
 internal ProductPrice(Product product, PriceType priceType, Price price) : this()
 {
     Product   = product;
     PriceType = priceType;
     Price     = price;
 }
Exemplo n.º 4
0
        public Price FindPrice(PriceType priceType)
        {
            var price = _prices.Find(p => p.PriceType == priceType);

            return(price?.Price ?? Price.Price);
        }