コード例 #1
0
        public static VolumeDiscount Load(Int32 volumeDiscountId, bool useCache)
        {
            if (volumeDiscountId == 0)
            {
                return(null);
            }
            VolumeDiscount volumeDiscount = null;
            string         key            = "VolumeDiscount_" + volumeDiscountId.ToString();

            if (useCache)
            {
                volumeDiscount = ContextCache.GetObject(key) as VolumeDiscount;
                if (volumeDiscount != null)
                {
                    return(volumeDiscount);
                }
            }
            volumeDiscount = new VolumeDiscount();
            if (volumeDiscount.Load(volumeDiscountId))
            {
                if (useCache)
                {
                    ContextCache.SetObject(key, volumeDiscount);
                }
                return(volumeDiscount);
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Creates a copy of a volume discount
        /// </summary>
        /// <param name="volumeDiscountId">Id of the volume discount of which to create a copy</param>
        /// <param name="deepCopy">If <b>true</b> all child references are also copied</param>
        /// <returns>Copy of the given volume discount</returns>
        public static VolumeDiscount Copy(int volumeDiscountId, bool deepCopy)
        {
            //LOAD COPY (NO CACHE)
            VolumeDiscount source = new VolumeDiscount();

            if (source.Load(volumeDiscountId))
            {
                //IF DEEP COPY, RESET ALL CHILD REFERENCES
                if (deepCopy)
                {
                    foreach (VolumeDiscountLevel child in source.Levels)
                    {
                        child.VolumeDiscountLevelId = 0;
                        child.VolumeDiscountId      = 0;
                    }
                    foreach (VolumeDiscountGroup child in source.VolumeDiscountGroups)
                    {
                        child.VolumeDiscountId = 0;
                    }
                    foreach (CategoryVolumeDiscount child in source.CategoryVolumeDiscounts)
                    {
                        child.VolumeDiscountId = 0;
                    }
                    foreach (ProductVolumeDiscount child in source.ProductVolumeDiscounts)
                    {
                        child.VolumeDiscountId = 0;
                    }
                }
                source.VolumeDiscountId = 0;
                source.Save();
                return(source);
            }
            return(null);
        }
コード例 #3
0
        public static bool Delete(Int32 volumeDiscountId)
        {
            VolumeDiscount volumeDiscount = new VolumeDiscount();

            if (volumeDiscount.Load(volumeDiscountId))
            {
                return(volumeDiscount.Delete());
            }
            return(false);
        }