public virtual ActionResult Chat(int productId)
        {
            var storeId = storeMappingService
                          .GetStoreIdByEntityId(productId, "Product")
                          .FirstOrDefault();

            if (storeId == 0)
            {
                customerActivityService.InsertActivity("GetCustomerChat",
                                                       localizationService.GetResource("Moveleiros.ActivityLog.ChatNotFound"), productId);

                return(RedirectToAction("ChatContact", new { productId = productId }));
            }

            var chatSnippet = storeService.GetChatByStoreId(storeId);

            if (string.IsNullOrEmpty(chatSnippet))
            {
                customerActivityService.InsertActivity("GetCustomerChat",
                                                       localizationService.GetResource("Moveleiros.ActivityLog.ChatNotFound"), productId);

                return(RedirectToAction("ChatContact", new { productId = productId }));
            }

            customerActivityService.InsertActivity("GetCustomerChat",
                                                   localizationService.GetResource("Moveleiros.ActivityLog.GetCustomerChat"), productId);

#if DEBUG
            System.Threading.Thread.Sleep(2000);
#endif

            return(View("Chat", model: chatSnippet));
        }
Ejemplo n.º 2
0
        protected virtual void PrepareStoresMappingModel(LanguageModel model, Language language, bool excludeProperties)
        {
            #region Extensions by QuanNH
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var _workContext = Nop.Core.Infrastructure.EngineContext.Current.Resolve <Nop.Core.IWorkContext>();

            List <int> storeId   = _storeMappingService.GetStoreIdByEntityId(_workContext.CurrentCustomer.Id, "Stores");
            var        allStores = _storeService.GetAllStores();

            if (storeId.Count > 0)
            {
                allStores = _storeService.GetAllStoresByEntityName(_workContext.CurrentCustomer.Id, "Stores");
            }

            if (!excludeProperties)
            {
                if (language != null)
                {
                    model.SelectedStoreIds = _storeMappingService.GetStoresIdsWithAccess(language).ToList();
                    if (storeId.Count <= 0)
                    {
                        model.LimitedToStores = false;
                    }
                }
                else
                {
                    if (storeId.Count > 0)
                    {
                        model.SelectedStoreIds = storeId;
                        model.LimitedToStores  = true;
                    }
                }
            }

            foreach (var store in allStores)
            {
                model.AvailableStores.Add(new SelectListItem
                {
                    Text     = store.Name,
                    Value    = store.Id.ToString(),
                    Selected = model.SelectedStoreIds.Contains(store.Id)
                });
            }

            #endregion
        }
        /// <summary>
        /// Gets all categories
        /// </summary>
        /// <param name="categoryName">Category name</param>
        /// <param name="storeId">Store identifier; 0 if you want to get all records</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="showHidden">A value indicating whether to show hidden records</param>
        /// <returns>Categories</returns>
        public virtual IPagedList <Category> GetAllCategories(string categoryName = "", int storeId = 0,
                                                              int pageIndex       = 0, int pageSize = int.MaxValue, bool showHidden = false, bool onlySubCategory = false,
                                                              bool onlyCategory   = false)
        {
            if (_commonSettings.UseStoredProcedureForLoadingCategories &&
                _commonSettings.UseStoredProceduresIfSupported && _dataProvider.StoredProceduredSupported)
            {
                //stored procedures are enabled for loading categories and supported by the database.
                //It's much faster with a large number of categories than the LINQ implementation below

                //prepare parameters
                var showHiddenParameter = _dataProvider.GetParameter();
                showHiddenParameter.ParameterName = "ShowHidden";
                showHiddenParameter.Value         = showHidden;
                showHiddenParameter.DbType        = DbType.Boolean;

                var nameParameter = _dataProvider.GetParameter();
                nameParameter.ParameterName = "Name";
                nameParameter.Value         = categoryName ?? string.Empty;
                nameParameter.DbType        = DbType.String;

                var storeIdParameter = _dataProvider.GetParameter();
                storeIdParameter.ParameterName = "StoreId";
                storeIdParameter.Value         = !_catalogSettings.IgnoreStoreLimitations ? storeId : 0;
                storeIdParameter.DbType        = DbType.Int32;

                //pass allowed customer role identifiers as comma-delimited string
                var customerRoleIdsParameter = _dataProvider.GetParameter();
                customerRoleIdsParameter.ParameterName = "CustomerRoleIds";
                customerRoleIdsParameter.Value         = !_catalogSettings.IgnoreAcl
                    ? string.Join(",", _workContext.CurrentCustomer.GetCustomerRoleIds()) : string.Empty;
                customerRoleIdsParameter.DbType = DbType.String;

                var pageIndexParameter = _dataProvider.GetParameter();
                pageIndexParameter.ParameterName = "PageIndex";
                pageIndexParameter.Value         = pageIndex;
                pageIndexParameter.DbType        = DbType.Int32;

                var pageSizeParameter = _dataProvider.GetParameter();
                pageSizeParameter.ParameterName = "PageSize";
                pageSizeParameter.Value         = pageSize;
                pageSizeParameter.DbType        = DbType.Int32;

                var totalRecordsParameter = _dataProvider.GetParameter();
                totalRecordsParameter.ParameterName = "TotalRecords";
                totalRecordsParameter.Direction     = ParameterDirection.Output;
                totalRecordsParameter.DbType        = DbType.Int32;

                //invoke stored procedure
                var categories = _dbContext.ExecuteStoredProcedureList <Category>("CategoryLoadAllPaged",
                                                                                  showHiddenParameter, nameParameter, storeIdParameter, customerRoleIdsParameter,
                                                                                  pageIndexParameter, pageSizeParameter, totalRecordsParameter);
                var totalRecords = (totalRecordsParameter.Value != DBNull.Value) ? Convert.ToInt32(totalRecordsParameter.Value) : 0;

                //paging
                return(new PagedList <Category>(categories, pageIndex, pageSize, totalRecords));
            }
            else
            {
                //stored procedures aren't supported. Use LINQ
                var query = _categoryRepository.Table;
                if (!showHidden)
                {
                    query = query.Where(c => c.Published);
                }
                if (!String.IsNullOrWhiteSpace(categoryName))
                {
                    query = query.Where(c => c.Name.Contains(categoryName));
                }
                query = query.Where(c => !c.Deleted);
                query = query.OrderBy(c => c.ParentCategoryId).ThenBy(c => c.DisplayOrder).ThenBy(c => c.Id);

                if ((storeId > 0 && !_catalogSettings.IgnoreStoreLimitations) || (!showHidden && !_catalogSettings.IgnoreAcl))
                {
                    if (!showHidden && !_catalogSettings.IgnoreAcl)
                    {
                        //ACL (access control list)
                        var allowedCustomerRolesIds = _workContext.CurrentCustomer.GetCustomerRoleIds();
                        query = from c in query
                                join acl in _aclRepository.Table
                                on new { c1 = c.Id, c2 = "Category" } equals new { c1 = acl.EntityId, c2 = acl.EntityName } into c_acl
                        from acl in c_acl.DefaultIfEmpty()
                        where !c.SubjectToAcl || allowedCustomerRolesIds.Contains(acl.CustomerRoleId)
                        select c;
                    }
                    if (storeId > 0 && !_catalogSettings.IgnoreStoreLimitations)
                    {
                        //Store mapping
                        query = from c in query
                                join sm in _storeMappingRepository.Table
                                on new { c1 = c.Id, c2 = "Category" } equals new { c1 = sm.EntityId, c2 = sm.EntityName } into c_sm
                        from sm in c_sm.DefaultIfEmpty()
                        where !c.LimitedToStores || storeId == sm.StoreId
                        select c;
                    }

                    //only distinct categories (group by ID)
                    query = from c in query
                            group c by c.Id
                            into cGroup
                            orderby cGroup.Key
                            select cGroup.FirstOrDefault();

                    query = query.OrderBy(c => c.ParentCategoryId).ThenBy(c => c.DisplayOrder).ThenBy(c => c.Id);
                }

                #region Extensions by QuanNH
                else
                {
                    //Store mapping
                    var currentStoreId = _storeMappingService.GetStoreIdByEntityId(_workContext.CurrentCustomer.Id, "Stores").FirstOrDefault();
                    int adminId        = _storeMappingService.GetStoreIdByEntityId(_workContext.CurrentCustomer.Id, "Admin").FirstOrDefault();
                    if (adminId <= 0 && currentStoreId > 0)
                    {
                        query = from c in query
                                join sm in _storeMappingRepository.Table
                                on new { c1 = c.Id, c2 = "Category" }
                    }
                    equals new { c1 = sm.EntityId, c2 = sm.EntityName } into c_sm
                    from sm in c_sm.DefaultIfEmpty()
                    where !c.LimitedToStores || currentStoreId == sm.StoreId
                    select c;

                    //only distinct categories (group by ID)
                    query = from c in query
                            group c by c.Id
                            into cGroup
                            orderby cGroup.Key
                            select cGroup.FirstOrDefault();

                    query = query.OrderBy(c => c.ParentCategoryId).ThenBy(c => c.DisplayOrder);
                }
                #endregion


                if (onlySubCategory)
                {
                    query = query.Where(t => t.ParentCategoryId > 0);
                }

                if (onlyCategory)
                {
                    query = query.Where(t => t.ParentCategoryId == 0);
                }

                var unsortedCategories = query.ToList();

                //sort categories
                var sortedCategories = unsortedCategories.SortCategoriesForTree();

                //paging
                return(new PagedList <Category>(sortedCategories, pageIndex, pageSize));
            }
        }