Example #1
0
/// <summary>
///     Returns true if self and the provided entity have the same Id values
///     and the Ids are not of the default Id value
/// </summary>
        protected bool HasSameNonDefaultIdAs(Fare compareTo)
        {
            return(!this.IsTransient() && !compareTo.IsTransient() && this.Id.Equals(compareTo.Id));
        }
Example #2
0
/// <summary>
/// Copies the current object to a new instance
/// </summary>
/// <param name="deep">Copy members that refer to objects external to this class (not dependent)</param>
/// <param name="copiedObjects">Objects that should be reused</param>
/// <param name="asNew">Copy the current object as a new one, ready to be persisted, along all its members.</param>
/// <param name="reuseNestedObjects">If asNew is true, this flag if set, forces the reuse of all external objects.</param>
/// <param name="copy">Optional - An existing [Fare] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual Fare Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, Fare copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((Fare)copiedObjects[this]);
            }
            copy = copy ?? new Fare();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.Id          = this.Id;
            }
            copy.TotalPrice  = this.TotalPrice;
            copy.Description = this.Description;
            copy.TaxAmount   = this.TaxAmount;
            copy.BasePrice   = this.BasePrice;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            if (deep && this.leg != null)
            {
                if (!copiedObjects.Contains(this.leg))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Leg = this.Leg;
                    }
                    else if (asNew)
                    {
                        copy.Leg = this.Leg.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.leg = this.leg.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Leg = (Leg)copiedObjects[this.Leg];
                    }
                    else
                    {
                        copy.leg = (Leg)copiedObjects[this.Leg];
                    }
                }
            }
            copy.charges = new List <Charge>();
            if (deep && this.charges != null)
            {
                foreach (var __item in this.charges)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddCharges(__item);
                        }
                        else
                        {
                            copy.AddCharges(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddCharges((Charge)copiedObjects[__item]);
                    }
                }
            }
            if (deep && this.fareType != null)
            {
                if (!copiedObjects.Contains(this.fareType))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.FareType = this.FareType;
                    }
                    else if (asNew)
                    {
                        copy.FareType = this.FareType.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.fareType = this.fareType.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.FareType = (FareType)copiedObjects[this.FareType];
                    }
                    else
                    {
                        copy.fareType = (FareType)copiedObjects[this.FareType];
                    }
                }
            }
            copy.datasource = new List <Datasource>();
            if (deep && this.datasource != null)
            {
                foreach (var __item in this.datasource)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddDatasource(__item);
                        }
                        else
                        {
                            copy.AddDatasource(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddDatasource((Datasource)copiedObjects[__item]);
                    }
                }
            }
            if (deep && this.currency != null)
            {
                if (!copiedObjects.Contains(this.currency))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Currency = this.Currency;
                    }
                    else if (asNew)
                    {
                        copy.Currency = this.Currency.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.currency = this.currency.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Currency = (Currency)copiedObjects[this.Currency];
                    }
                    else
                    {
                        copy.currency = (Currency)copiedObjects[this.Currency];
                    }
                }
            }
            return(copy);
        }