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)); }
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)); }
internal ProductPrice(Product product, PriceType priceType, Price price) : this() { Product = product; PriceType = priceType; Price = price; }
public Price FindPrice(PriceType priceType) { var price = _prices.Find(p => p.PriceType == priceType); return(price?.Price ?? Price.Price); }