コード例 #1
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());
        }
コード例 #2
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());
        }