/// <summary> /// Determines whether the specified Historic Price is equal the this Historic Price. /// </summary> /// <param name="other">The other price to compare.</param> /// <returns> /// True, when the other historic price refers to the same Stock ID and Date as this one. /// </returns> public virtual bool Equals(HistoricPrice other) { if (ReferenceEquals(null, other)) { return false; } if (ReferenceEquals(this, other)) { return true; } return (GetStockIdForComparison(other.Stock) == GetStockIdForComparison(this.Stock)) && other.Date.Equals(this.Date); }
/// <summary> /// Adds an historic price to the stock's price history. /// </summary> /// <param name="price">The price to add to the history.</param> /// <returns>True, when the price was successfully added.</returns> public virtual bool AddHistoricPrice(HistoricPrice price) { // Store the price's current Stock reference so the operation can be reverted on failure. var priorStockReference = price.Stock; // Try to add the price to this stock's history. price.Stock = this; var success = this.priceHistory.Add(price); // Revert on failure. if (!success) { price.Stock = priorStockReference; } return success; }