// Comparison Operators //public static bool operator ==(ParentProduct a, ParentProduct b) //{ // if (ReferenceEquals(a, b)) // return true; // return a.Equals(b); //} //public static bool operator !=(ParentProduct a, ParentProduct b) //{ // return !(a == b); //} //public static bool operator ==(ParentProduct a, string b) //{ // return a.Equals(b); //} //public static bool operator !=(ParentProduct a, string b) //{ // return !(a == b); //} //public static bool operator ==(string a, ParentProduct b) //{ // return (b == a); //} //public static bool operator !=(string a, ParentProduct b) //{ // return !(a == b); //} // ******************** // * Member Functions * // ******************** // Update Function public bool UpdateData(ParentProduct update) { if (this == update) { UpdateData(update); MetaTagKeywords = update.MetaTagKeywords; Description = update.Description; OnHomePage = update.OnHomePage; // Update Child Products with new data foreach (var child in update.ChildProducts) { var index = ChildProducts.FindIndex(x => x == child); if (index == -1) { ChildProducts.Add(child); } else { ChildProducts[index].UpdateData(child); } } return(true); } return(false); }
public double GetTotalPrice(DateTime?date) { if (!date.HasValue) { return(0); } double totalPriceSum = 0; var prices = Prices.Where(x => (x.Date <= date)).OrderByDescending(x => x.Date); if (prices.Any()) { totalPriceSum = prices.First().Sum; } totalPriceSum += ChildProducts.Sum(child => child.GetTotalPrice(date)); return(totalPriceSum); }
protected void AddProduct(Product product) { ChildProducts.Add(product); }