Пример #1
0
 public virtual void SetLegsAt(Leg __item, int __index)
 {
     if (__item == null)
     {
         legs[__index].Trip = null;
     }
     else
     {
         legs[__index] = __item;
         if (__item.Trip != this)
         {
             __item.Trip = this;
         }
     }
 }
Пример #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 [Leg] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual Leg Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, Leg copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((Leg)copiedObjects[this]);
            }
            copy = copy ?? new Leg();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.Id          = this.Id;
            }
            copy.LegOrder          = this.LegOrder;
            copy.TravelDate        = this.TravelDate;
            copy.NumberOfSolutions = this.NumberOfSolutions;
            copy.ArrivalDate       = this.ArrivalDate;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            if (deep && this.trip != null)
            {
                if (!copiedObjects.Contains(this.trip))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Trip = this.Trip;
                    }
                    else if (asNew)
                    {
                        copy.Trip = this.Trip.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.trip = this.trip.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Trip = (Trip)copiedObjects[this.Trip];
                    }
                    else
                    {
                        copy.trip = (Trip)copiedObjects[this.Trip];
                    }
                }
            }
            if (deep && this.fare != null)
            {
                if (!copiedObjects.Contains(this.fare))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Fare = this.Fare;
                    }
                    else if (asNew)
                    {
                        copy.Fare = this.Fare.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.fare = this.fare.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Fare = (Fare)copiedObjects[this.Fare];
                    }
                    else
                    {
                        copy.fare = (Fare)copiedObjects[this.Fare];
                    }
                }
            }
            copy.preferences = new List <Preference>();
            if (deep && this.preferences != null)
            {
                foreach (var __item in this.preferences)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddPreferences(__item);
                        }
                        else
                        {
                            copy.AddPreferences(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddPreferences((Preference)copiedObjects[__item]);
                    }
                }
            }
            copy.pointOfInterest = new List <PointOfInterest>();
            if (deep && this.pointOfInterest != null)
            {
                foreach (var __item in this.pointOfInterest)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddPointOfInterest(__item);
                        }
                        else
                        {
                            copy.AddPointOfInterest(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddPointOfInterest((PointOfInterest)copiedObjects[__item]);
                    }
                }
            }
            copy.solutions = new List <Solution>();
            if (deep && this.solutions != null)
            {
                foreach (var __item in this.solutions)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddSolutions(__item);
                        }
                        else
                        {
                            copy.AddSolutions(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddSolutions((Solution)copiedObjects[__item]);
                    }
                }
            }
            if (deep && this.originLocation != null)
            {
                if (!copiedObjects.Contains(this.originLocation))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.OriginLocation = this.OriginLocation;
                    }
                    else if (asNew)
                    {
                        copy.OriginLocation = this.OriginLocation.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.originLocation = this.originLocation.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.OriginLocation = (Location)copiedObjects[this.OriginLocation];
                    }
                    else
                    {
                        copy.originLocation = (Location)copiedObjects[this.OriginLocation];
                    }
                }
            }
            if (deep && this.destinationLocation != null)
            {
                if (!copiedObjects.Contains(this.destinationLocation))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.DestinationLocation = this.DestinationLocation;
                    }
                    else if (asNew)
                    {
                        copy.DestinationLocation = this.DestinationLocation.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.destinationLocation = this.destinationLocation.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.DestinationLocation = (Location)copiedObjects[this.DestinationLocation];
                    }
                    else
                    {
                        copy.destinationLocation = (Location)copiedObjects[this.DestinationLocation];
                    }
                }
            }
            if (deep && this.chosenSolution != null)
            {
                if (!copiedObjects.Contains(this.chosenSolution))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.ChosenSolution = this.ChosenSolution;
                    }
                    else if (asNew)
                    {
                        copy.ChosenSolution = this.ChosenSolution.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.chosenSolution = this.chosenSolution.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.ChosenSolution = (Solution)copiedObjects[this.ChosenSolution];
                    }
                    else
                    {
                        copy.chosenSolution = (Solution)copiedObjects[this.ChosenSolution];
                    }
                }
            }
            copy.notes = new List <Note>();
            if (deep && this.notes != null)
            {
                foreach (var __item in this.notes)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddNotes(__item);
                        }
                        else
                        {
                            copy.AddNotes(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddNotes((Note)copiedObjects[__item]);
                    }
                }
            }
            copy.photographs = new List <Photograph>();
            if (deep && this.photographs != null)
            {
                foreach (var __item in this.photographs)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddPhotographs(__item);
                        }
                        else
                        {
                            copy.AddPhotographs(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddPhotographs((Photograph)copiedObjects[__item]);
                    }
                }
            }
            return(copy);
        }
Пример #3
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(Leg compareTo)
        {
            return(!this.IsTransient() && !compareTo.IsTransient() && this.Id.Equals(compareTo.Id));
        }