コード例 #1
0
        private List <Discount> GetActiveDiscounts()
        {
            List <Discount> userDiscounts = DiscountCollection.GetActiveDiscountsForCurrentUser(this.StoreId.Value);

            List <Discount> discounts = new List <Discount>();

            foreach (Discount d in userDiscounts)
            {
                if (d.DiscountTypeName == DiscountDiscountType.AllProducts)
                {
                    discounts.Add(d);
                }
                else if (d.DiscountTypeName == DiscountDiscountType.Product)
                {
                    var productIdInts = d.GetProductIds().Select(WA.Parser.ToInt).ToList();
                    if (productIdInts.Contains(this.Id.Value))
                    {
                        discounts.Add(d);
                    }
                }
                else if (d.DiscountTypeName == DiscountDiscountType.Category)
                {
                    var categoryIdInts     = d.GetCategoryIds().Select(WA.Parser.ToInt);
                    var productCategoryIds = this.GetCategories(true).Select(c => c.Id);
                    if (categoryIdInts.Intersect(productCategoryIds).Count() > 0)
                    {
                        discounts.Add(d);
                    }
                }
            }
            return(discounts);
        }
コード例 #2
0
        public static List <Discount> GetAll(int storeId)
        {
            DiscountQuery q = new DiscountQuery();

            q.Where(q.StoreId == storeId);
            q.OrderBy(q.DnnRoleId.Ascending);

            DiscountCollection collection = new DiscountCollection();

            collection.Load(q);

            return(collection.ToList());
        }
コード例 #3
0
        internal static List <Discount> GetActiveDiscountsForCurrentUser(int storeId)
        {
            UserInfo userInfo = UserController.GetCurrentUserInfo();

            RoleController  roleController = new RoleController();
            List <RoleInfo> userRoles      = roleController.GetUserRoles(userInfo.PortalID, userInfo.UserID).ToList <RoleInfo>();

            List <int> roleIds = userRoles.ConvertAll(r => r.RoleID);

            DiscountQuery q = new DiscountQuery();

            q.Where(q.StoreId == storeId);
            q.Where(q.IsActive == true);
            if (roleIds.Count > 0)
            {
                q.Where(q.Or(
                            q.DnnRoleId.IsNull(), q.DnnRoleId.In(roleIds.ToArray())
                            ));
            }
            else
            {
                q.Where(q.Or(q.DnnRoleId.IsNull()));
            }

            DateTime now = DateTime.Now;

            q.Where(q.Or(
                        q.ValidFromDate.IsNull(), now >= q.ValidFromDate
                        ));
            q.Where(q.Or(
                        q.ValidToDate.IsNull(), now <= q.ValidToDate
                        ));

            DiscountCollection discounts = new DiscountCollection();

            discounts.Load(q);

            return(discounts.ToList());
        }