Exemple #1
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 [CreditNote] instance to use as the destination.</param>
/// <returns>A copy of the object</returns>
        public virtual CreditNote Copy(bool deep = false, Hashtable copiedObjects = null, bool asNew = false, bool reuseNestedObjects = false, CreditNote copy = null)
        {
            if (copiedObjects == null)
            {
                copiedObjects = new Hashtable();
            }
            if (copy == null && copiedObjects.Contains(this))
            {
                return((CreditNote)copiedObjects[this]);
            }
            copy = copy ?? new CreditNote();
            if (!asNew)
            {
                copy.TransientId = this.TransientId;
                copy.Id          = this.Id;
            }
            copy.CreditNoteNumber   = this.CreditNoteNumber;
            copy.Description        = this.Description;
            copy.DateIssued         = this.DateIssued;
            copy.Amount             = this.Amount;
            copy.TotalPrice         = this.TotalPrice;
            copy.CreditNoteDocument = this.CreditNoteDocument;
            copy.CNoteAttachment    = this.CNoteAttachment;
            copy.Status             = this.Status;
            if (!copiedObjects.Contains(this))
            {
                copiedObjects.Add(this, copy);
            }
            copy.orders = new List <Order>();
            if (deep && this.orders != null)
            {
                foreach (var __item in this.orders)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddOrders(__item);
                        }
                        else
                        {
                            copy.AddOrders(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddOrders((Order)copiedObjects[__item]);
                    }
                }
            }
            copy.creditNoteProducts = new List <CreditNoteProduct>();
            if (deep && this.creditNoteProducts != null)
            {
                foreach (var __item in this.creditNoteProducts)
                {
                    if (!copiedObjects.Contains(__item))
                    {
                        if (asNew && reuseNestedObjects)
                        {
                            copy.AddCreditNoteProducts(__item);
                        }
                        else
                        {
                            copy.AddCreditNoteProducts(__item.Copy(deep, copiedObjects, asNew));
                        }
                    }
                    else
                    {
                        copy.AddCreditNoteProducts((CreditNoteProduct)copiedObjects[__item]);
                    }
                }
            }
            if (deep && this.transaction != null)
            {
                if (!copiedObjects.Contains(this.transaction))
                {
                    if (asNew && reuseNestedObjects)
                    {
                        copy.Transaction = this.Transaction;
                    }
                    else if (asNew)
                    {
                        copy.Transaction = this.Transaction.Copy(deep, copiedObjects, true);
                    }
                    else
                    {
                        copy.transaction = this.transaction.Copy(deep, copiedObjects, false);
                    }
                }
                else
                {
                    if (asNew)
                    {
                        copy.Transaction = (Transaction)copiedObjects[this.Transaction];
                    }
                    else
                    {
                        copy.transaction = (Transaction)copiedObjects[this.Transaction];
                    }
                }
            }
            return(copy);
        }