Пример #1
0
        /// <summary>
        /// Gets list of customer roles
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="showHidden">A value indicating whether to load hidden records</param>
        /// <returns>Result</returns>
        public virtual IList <CustomerRole> GetCustomerRoles(Core.Domain.Customers.Customer customer, bool showHidden = false)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            var query = GetCustomerRolesBase(customer.Id, showHidden);

            var key = _cacheKeyService.PrepareKeyForShortTermCache(NopCustomerServicesDefaults.CustomerRolesCacheKey, customer, showHidden);

            return(_staticCacheManager.Get(key, () => query.ToList()));
        }
Пример #2
0
        /// <summary>
        /// Get the render widget models
        /// </summary>
        /// <param name="widgetZone">Name of widget zone</param>
        /// <param name="additionalData">Additional data object</param>
        /// <returns>List of the render widget models</returns>
        public virtual List <RenderWidgetModel> PrepareRenderWidgetModel(string widgetZone, object additionalData = null)
        {
            var roles = _customerService.GetCustomerRoleIds(_workContext.CurrentCustomer);

            var cacheKey = _cacheKeyService.PrepareKeyForShortTermCache(NopModelCacheDefaults.WidgetModelKey,
                                                                        roles, _storeContext.CurrentStore, widgetZone, _themeContext.WorkingThemeName);

            var cachedModels = _staticCacheManager.Get(cacheKey, () =>
                                                       _widgetPluginManager.LoadActivePlugins(_workContext.CurrentCustomer, _storeContext.CurrentStore.Id, widgetZone)
                                                       .Select(widget => new RenderWidgetModel
            {
                WidgetViewComponentName      = widget.GetWidgetViewComponentName(widgetZone),
                WidgetViewComponentArguments = new RouteValueDictionary {
                    ["widgetZone"] = widgetZone
                }
            }));

            //"WidgetViewComponentArguments" property of widget models depends on "additionalData".
            //We need to clone the cached model before modifications (the updated one should not be cached)
            var models = cachedModels.Select(renderModel => new RenderWidgetModel
            {
                WidgetViewComponentName      = renderModel.WidgetViewComponentName,
                WidgetViewComponentArguments = new RouteValueDictionary {
                    ["widgetZone"] = widgetZone, ["additionalData"] = additionalData
                }
            }).ToList();

            return(models);
        }
Пример #3
0
        /// <summary>
        /// Get customer role identifiers
        /// </summary>
        /// <param name="customer">Customer</param>
        /// <param name="showHidden">A value indicating whether to load hidden records</param>
        /// <returns>Customer role identifiers</returns>
        public virtual int[] GetCustomerRoleIds(Customer customer, bool showHidden = false)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            var query = from cr in _customerRoleRepository.Table
                        join crm in _customerCustomerRoleMappingRepository.Table on cr.Id equals crm.CustomerRoleId
                        where crm.CustomerId == customer.Id &&
                        (showHidden || cr.Active)
                        select cr.Id;

            var key = _cacheKeyService.PrepareKeyForShortTermCache(BopCustomerServicesDefaults.CustomerRoleIdsCacheKey, customer, showHidden);

            return(_staticCacheManager.Get(key, () => query.ToArray()));
        }
Пример #4
0
        public IList <Auth_Roles> GetUserRoles(Auth_User user, bool showHidden = false)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            try
            {
                var key = _cacheKeyService.PrepareKeyForShortTermCache(MotelUserServicesDefaults.UserRolesByObjectCacheKey, user);

                var query = from urm in  _userRolesMappingRepository.Table join ur in _rolesRepository.Table
                            on urm.RoleID equals ur.Id
                            where urm.UserID == user.Id
                            orderby ur.Id
                            select ur;
                return(_staticCacheManager.Get(key, () => query.ToList()));
            }
            catch (Exception ex)
            {
                _logger.Error("GetCustomerRoles error", ex);
                return(null);
            }
        }
        /// <summary>
        /// Gets all the ShippingByTotalRecords
        /// </summary>
        /// <param name="pageIndex">page index</param>
        /// <param name="pageSize">page size</param>
        /// <returns>ShippingByTotalRecord collection</returns>
        public virtual IPagedList <ShippingByTotalRecord> GetAllShippingByTotalRecords(int pageIndex = 0, int pageSize = int.MaxValue)
        {
            var key = _cacheKeyService.PrepareKeyForShortTermCache(SHIPPINGBYTOTAL_ALL_KEY, pageIndex, pageSize);

            return(_staticCacheManager.Get(key, () =>
            {
                var query = from sbt in _sbtRepository.Table
                            orderby sbt.StoreId, sbt.CountryId, sbt.StateProvinceId, sbt.DisplayOrder, sbt.ShippingMethodId, sbt.From, sbt.Id
                select sbt;

                var records = new PagedList <ShippingByTotalRecord>(query, pageIndex, pageSize);

                return records;
            }));
        }
Пример #6
0
        /// <summary>
        /// Get all shipping by weight records
        /// </summary>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <returns>List of the shipping by weight record</returns>
        public virtual IPagedList <ShippingByWeightByTotalRecord> GetAll(int pageIndex = 0, int pageSize = int.MaxValue)
        {
            var key = _cacheKeyService.PrepareKeyForShortTermCache(_shippingByWeightByTotalAllKey);
            var rez = _staticCacheManager.Get(key, () =>
            {
                var query = from sbw in _sbwtRepository.Table
                            orderby sbw.StoreId, sbw.CountryId, sbw.StateProvinceId, sbw.Zip, sbw.ShippingMethodId, sbw.WeightFrom, sbw.OrderSubtotalFrom
                select sbw;

                return(query.ToList());
            });

            var records = new PagedList <ShippingByWeightByTotalRecord>(rez, pageIndex, pageSize);

            return(records);
        }
        /// <summary>
        /// Gets all tax rates
        /// </summary>
        /// <returns>Tax rates</returns>
        public virtual IPagedList <TaxRate> GetAllTaxRates(int pageIndex = 0, int pageSize = int.MaxValue)
        {
            var key = _cacheKeyService.PrepareKeyForShortTermCache(ModelCacheEventConsumer.TAXRATE_ALL_KEY);
            var rez = _staticCacheManager.Get(key, () =>
            {
                var query = from tr in _taxRateRepository.Table
                            orderby tr.StoreId, tr.CountryId, tr.StateProvinceId, tr.Zip, tr.TaxCategoryId
                select tr;

                return(query.ToList());
            });

            var records = new PagedList <TaxRate>(rez, pageIndex, pageSize);

            return(records);
        }
Пример #8
0
        /// <summary>
        /// Gets all pickup points
        /// </summary>
        /// <param name="storeId">The store identifier; pass 0 to load all records</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <returns>Pickup points</returns>
        public virtual IPagedList <StorePickupPoint> GetAllStorePickupPoints(int storeId = 0, int pageIndex = 0, int pageSize = int.MaxValue)
        {
            var key = _cacheKeyService.PrepareKeyForShortTermCache(_pickupPointAllKey, storeId);
            var rez = _staticCacheManager.Get(key, () =>
            {
                var query = _storePickupPointRepository.Table;
                if (storeId > 0)
                {
                    query = query.Where(point => point.StoreId == storeId || point.StoreId == 0);
                }
                query = query.OrderBy(point => point.DisplayOrder).ThenBy(point => point.Name);

                return(query.ToList());
            });

            return(new PagedList <StorePickupPoint>(rez, pageIndex, pageSize));
        }
        public virtual IList <ShoppingCartItem> GetShoppingCart(Customer customer, ShoppingCartType?shoppingCartType = null,
                                                                int storeId = 0, int?productId = null, DateTime?createdFromUtc = null, DateTime?createdToUtc = null)
        {
            if (customer == null)
            {
                throw new ArgumentNullException(nameof(customer));
            }

            var items = _sciRepository.Table.Where(sci => sci.CustomerId == customer.Id);

            //filter by type
            if (shoppingCartType.HasValue)
            {
                items = items.Where(item => item.ShoppingCartTypeId == (int)shoppingCartType.Value);
            }

            //filter shopping cart items by store
            if (storeId > 0 && !_shoppingCartSettings.CartsSharedBetweenStores)
            {
                items = items.Where(item => item.StoreId == storeId);
            }

            //filter shopping cart items by product
            if (productId > 0)
            {
                items = items.Where(item => item.ProductId == productId);
            }

            //filter shopping cart items by date
            if (createdFromUtc.HasValue)
            {
                items = items.Where(item => createdFromUtc.Value <= item.CreatedOnUtc);
            }
            if (createdToUtc.HasValue)
            {
                items = items.Where(item => createdToUtc.Value >= item.CreatedOnUtc);
            }

            var key = _cacheKeyService.PrepareKeyForShortTermCache(NopOrderDefaults.ShoppingCartCacheKey, customer, shoppingCartType, storeId, productId, createdFromUtc, createdToUtc);

            return(_staticCacheManager.Get(key, () => items.ToList()));
        }