示例#1
0
        public ActionResult HomePageBlogLeft(BlogPagingFilteringModel command)
        {
            var model = new BlogPostListModel();

            model.WorkingLanguageId = _workContext.WorkingLanguage.Id;

            if (command.PageSize <= 0)
            {
                command.PageSize = _blogSettings.PostsPageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            DateTime?dateFrom = command.GetFromMonth();
            DateTime?dateTo   = command.GetToMonth();

            var blogPosts = _blogService.GetAllBlogPosts(_storeContext.CurrentStore.Id, command.PageIndex);

            model.PagingFilteringContext.LoadPagedList(blogPosts);

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                _blogModelFactory.PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();
            return(PartialView(model));
        }
示例#2
0
        public virtual ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlogposts))
            {
                return(AccessDeniedView());
            }

            var model = new BlogPostListModel();

            /*可用类目搜索项*/
            model.AvailableCategories.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            var categories = SelectListHelper.GetBlogCategoryList(_categoryService, _cacheManager, true);

            foreach (var c in categories)
            {
                model.AvailableCategories.Add(c);
            }

            /*可用发布状态搜索项*/
            model.AvailablePublishedOptions.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.All"), Value = "0"
            });
            model.AvailablePublishedOptions.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.PublishedOnly"), Value = "1"
            });
            model.AvailablePublishedOptions.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Catalog.Products.List.SearchPublished.UnpublishedOnly"), Value = "2"
            });

            return(View(model));
        }
        public async Task <BlogPostListModel> PrepareBlogPostListModel(BlogPagingFilteringModel command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var model = new BlogPostListModel();

            model.PagingFilteringContext.Tag        = command.Tag;
            model.PagingFilteringContext.Month      = command.Month;
            model.PagingFilteringContext.CategoryId = command.CategoryId;
            model.WorkingLanguageId = _workContext.WorkingLanguage.Id;
            model.SearchKeyword     = command.SearchKeyword;

            if (command.PageSize <= 0)
            {
                command.PageSize = _blogSettings.PostsPageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            DateTime?dateFrom = command.GetFromMonth();
            DateTime?dateTo   = command.GetToMonth();

            IPagedList <BlogPost> blogPosts;

            if (string.IsNullOrEmpty(command.CategoryId))
            {
                if (String.IsNullOrEmpty(command.Tag))
                {
                    blogPosts = await _blogService.GetAllBlogPosts(_storeContext.CurrentStore.Id,
                                                                   dateFrom, dateTo, command.PageNumber - 1, command.PageSize, blogPostName : model.SearchKeyword);
                }
                else
                {
                    blogPosts = await _blogService.GetAllBlogPostsByTag(_storeContext.CurrentStore.Id,
                                                                        command.Tag, command.PageNumber - 1, command.PageSize);
                }
            }
            else
            {
                blogPosts = await _blogService.GetAllBlogPosts(_storeContext.CurrentStore.Id,
                                                               dateFrom, dateTo, command.PageNumber - 1, command.PageSize, categoryId : command.CategoryId, blogPostName : model.SearchKeyword);
            }
            model.PagingFilteringContext.LoadPagedList(blogPosts);

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false).Wait();
                return(blogPostModel);
            })
                              .ToList();

            return(model);
        }
示例#4
0
        public virtual IActionResult List(DataSourceRequest command, BlogPostListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedKendoGridJson());
            }

            var blogPosts = _blogService.GetAllBlogPosts(model.SearchStoreId, 0, null, null, command.Page - 1, command.PageSize, true);
            var gridModel = new DataSourceResult
            {
                Data = blogPosts.Select(x =>
                {
                    var m = x.ToModel();
                    //little performance optimization: ensure that "Body" is not returned
                    m.Body = "";
                    if (x.StartDateUtc.HasValue)
                    {
                        m.StartDate = _dateTimeHelper.ConvertToUserTime(x.StartDateUtc.Value, DateTimeKind.Utc);
                    }
                    if (x.EndDateUtc.HasValue)
                    {
                        m.EndDate = _dateTimeHelper.ConvertToUserTime(x.EndDateUtc.Value, DateTimeKind.Utc);
                    }
                    m.CreatedOn           = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    m.LanguageName        = _languageService.GetLanguageById(x.LanguageId)?.Name;
                    m.ApprovedComments    = _blogService.GetBlogCommentsCount(x, isApproved: true);
                    m.NotApprovedComments = _blogService.GetBlogCommentsCount(x, isApproved: false);

                    return(m);
                }),
                Total = blogPosts.TotalCount
            };

            return(Json(gridModel));
        }
示例#5
0
        public virtual ActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            var model = new BlogPostListModel();

            #region Extensions by QuanNH
            //stores
            var _workContext = Nop.Core.Infrastructure.EngineContext.Current.Resolve <Nop.Core.IWorkContext>();
            var AllStores    = _storeService.GetAllStoresByEntityName(_workContext.CurrentCustomer.Id, "Stores");
            if (AllStores.Count <= 0)
            {
                AllStores = _storeService.GetAllStores();
                model.AvailableStores.Add(new SelectListItem {
                    Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
                });
            }

            foreach (var s in AllStores)
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }

            #endregion

            return(View(model));
        }
示例#6
0
        /// <summary>
        /// Prepare blog post list model
        /// </summary>
        /// <param name="command">Blog paging filtering model</param>
        /// <returns>Blog post list model</returns>
        public virtual BlogPostListModel PrepareBlogPostListModel(BlogPagingFilteringModel command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var model = new BlogPostListModel
            {
                PagingFilteringContext =
                {
                    Tag   = command.Tag,
                    Month = command.Month
                },
                WorkingLanguageId = _workContext.WorkingLanguage.Id
            };

            if (command.PageSize <= 0)
            {
                command.PageSize = _blogSettings.PostsPageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            var dateFrom = command.GetFromMonth();
            var dateTo   = command.GetToMonth();

            IPagedList <BlogPost> blogPosts;

            if (string.IsNullOrEmpty(command.Tag))
            {
                blogPosts = _blogService.GetAllBlogPosts(_storeContext.CurrentStore.Id,
                                                         _workContext.WorkingLanguage.Id,
                                                         dateFrom, dateTo, command.PageNumber - 1, command.PageSize);
            }
            else
            {
                blogPosts = _blogService.GetAllBlogPostsByTag(_storeContext.CurrentStore.Id,
                                                              _workContext.WorkingLanguage.Id,
                                                              command.Tag, command.PageNumber - 1, command.PageSize);
            }
            model.PagingFilteringContext.LoadPagedList(blogPosts);

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();

            return(model);
        }
示例#7
0
        protected BlogPostListModel PrepareBlogPostListModel(BlogPagingFilteringModel command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var storeId           = _services.StoreContext.CurrentStore.Id;
            var workingLanguageId = _services.WorkContext.WorkingLanguage.Id;
            var model             = new BlogPostListModel();

            model.PagingFilteringContext.Tag   = command.Tag;
            model.PagingFilteringContext.Month = command.Month;
            model.WorkingLanguageId            = workingLanguageId;

            if (command.PageSize <= 0)
            {
                command.PageSize = _blogSettings.PostsPageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            DateTime?dateFrom = command.GetFromMonth();
            DateTime?dateTo   = command.GetToMonth();

            IPagedList <BlogPost> blogPosts;

            if (!command.Tag.HasValue())
            {
                blogPosts = _blogService.GetAllBlogPosts(storeId, workingLanguageId, dateFrom, dateTo, command.PageNumber - 1, command.PageSize);
            }
            else
            {
                blogPosts = _blogService.GetAllBlogPostsByTag(storeId, workingLanguageId, command.Tag, command.PageNumber - 1, command.PageSize);
            }

            model.PagingFilteringContext.LoadPagedList(blogPosts);

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();

            return(model);
        }
示例#8
0
        public virtual ActionResult List(DataSourceRequest command, BlogPostListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlogposts))
            {
                return(AccessDeniedKendoGridJson());
            }

            var categoryIds = new List <int> {
                model.SearchCategoryId
            };

            if (model.SearchIncludeSubCategories && model.SearchCategoryId > 0)
            {
                categoryIds.AddRange(GetChildCategoryIds(model.SearchCategoryId));
            }

            bool?overridePublished = null;

            if (model.SearchPublishedId == 1)
            {
                overridePublished = true;
            }
            else if (model.SearchPublishedId == 2)
            {
                overridePublished = false;
            }

            var blogPosts = _blogService.GetAllBlogPosts(command.Page - 1, command.PageSize, categoryIds: categoryIds,
                                                         keywords: model.SearchTitle, overridePublished: overridePublished, showDeleted: model.ShowDeleted, orderBy: BlogSortingEnum.CreatedOnDesc);

            var utcNow    = DateTime.UtcNow;
            var gridModel = new DataSourceResult();

            gridModel.Data = blogPosts.Select(x =>
            {
                var m          = x.ToModel();
                m.Body         = "";
                m.BodyOverview = "";
                m.AuthorEmail  = x.Author != null ? x.Author.Email : null;
                m.CreatedOn    = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                m.UpdatedOn    = _dateTimeHelper.ConvertToUserTime(x.UpdatedOnUtc, DateTimeKind.Utc);
                m.Published    = (x.AvailableStartDateUtc == null || x.AvailableStartDateUtc < utcNow) &&
                                 (x.AvailableEndDateUtc == null || x.AvailableEndDateUtc > utcNow);
                return(m);
            });
            gridModel.Total = blogPosts.TotalCount;

            return(Json(gridModel));
        }
示例#9
0
        public ActionResult List(BlogPagingFilteringModel command)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var model = new BlogPostListModel();

            model.PagingFilteringContext.Tag   = command.Tag;
            model.PagingFilteringContext.Month = command.Month;
            model.WorkingLanguageId            = _workContext.WorkingLanguage.Id;

            if (command.PageSize <= 0)
            {
                command.PageSize = _blogSettings.PostsPageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            DateTime?dateFrom = command.GetFromMonth();
            DateTime?dateTo   = command.GetToMonth();

            IList <BlogPost> blogPosts;

            if (String.IsNullOrEmpty(command.Tag))
            {
                blogPosts = _blogService.GetAllBlogPosts(_workContext.WorkingLanguage.Id,
                                                         dateFrom, dateTo, command.PageNumber - 1, command.PageSize);
                model.PagingFilteringContext.LoadPagedList(blogPosts as IPagedList <BlogPost>);
            }
            else
            {
                blogPosts = _blogService.GetAllBlogPostsByTag(_workContext.WorkingLanguage.Id, command.Tag);
            }

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();

            return(View(model));
        }
示例#10
0
        /// <summary>
        /// Prepare blog post list model
        /// </summary>
        /// <param name="command">Blog paging filtering model</param>
        /// <returns>Blog post list model</returns>
        public virtual BlogPostListModel PrepareBlogPostListModel(BlogPagingFilteringModel command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var model = new BlogPostListModel();

            model.PagingFilteringContext.Tag   = command.Tag;
            model.PagingFilteringContext.Month = command.Month;

            if (command.PageSize <= 0)
            {
                command.PageSize = 10;                        // post size
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            DateTime?dateFrom = command.GetFromMonth();
            DateTime?dateTo   = command.GetToMonth();

            IPagedList <BlogPost> blogPosts;

            if (String.IsNullOrEmpty(command.Tag))
            {
                blogPosts = _blogService.GetAllBlogPosts(dateFrom, dateTo, command.PageNumber - 1, command.PageSize);
            }
            else
            {
                blogPosts = _blogService.GetAllBlogPostsByTag(command.Tag, command.PageNumber - 1, command.PageSize);
            }
            model.PagingFilteringContext.LoadPagedList(blogPosts);

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();

            return(model);
        }
        /// <summary>
        /// Prepare paged blog post list model
        /// </summary>
        /// <param name="searchModel">Blog post search model</param>
        /// <returns>Blog post list model</returns>
        public virtual BlogPostListModel PrepareBlogPostListModel(BlogPostSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get blog posts
            var blogPosts = _blogService.GetAllBlogPosts(searchModel.SearchStoreId, showHidden: true,
                                                         pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new BlogPostListModel
            {
                Data = blogPosts.Select(blogPost =>
                {
                    //fill in model values from the entity
                    var blogPostModel = blogPost.ToModel <BlogPostModel>();

                    //little performance optimization: ensure that "Body" is not returned
                    blogPostModel.Body = string.Empty;

                    //convert dates to the user time
                    if (blogPost.StartDateUtc.HasValue)
                    {
                        blogPostModel.StartDateUtc = _dateTimeHelper.ConvertToUserTime(blogPost.StartDateUtc.Value, DateTimeKind.Utc);
                    }
                    if (blogPost.EndDateUtc.HasValue)
                    {
                        blogPostModel.EndDateUtc = _dateTimeHelper.ConvertToUserTime(blogPost.EndDateUtc.Value, DateTimeKind.Utc);
                    }
                    blogPostModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    blogPostModel.LanguageName        = _languageService.GetLanguageById(blogPost.LanguageId)?.Name;
                    blogPostModel.ApprovedComments    = _blogService.GetBlogCommentsCount(blogPost, isApproved: true);
                    blogPostModel.NotApprovedComments = _blogService.GetBlogCommentsCount(blogPost, isApproved: false);
                    blogPostModel.SeName = _urlRecordService.GetSeName(blogPost, blogPost.LanguageId, true, false);

                    return(blogPostModel);
                }),
                Total = blogPosts.TotalCount
            };

            return(model);
        }
        public ActionResult BlogsHome()
        {
            var model = new BlogPostListModel();

            model.WorkingLanguageId = _workContext.WorkingLanguage.Id;
            var blogPosts = _blogService.GetNewBlogPosts();

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();
            return(PartialView(model));
        }
示例#13
0
        protected BlogPostListModel PrepareBlogPostListModel(int?maxPostAmount, int?maxAgeInDays, bool renderHeading, string blogHeading, bool disableCommentCount, string postsWithTag)
        {
            var storeId    = _services.StoreContext.CurrentStore.Id;
            var languageId = _services.WorkContext.WorkingLanguage.Id;
            var isAdmin    = _services.WorkContext.CurrentCustomer.IsAdmin();

            var model = new BlogPostListModel
            {
                BlogHeading         = blogHeading,
                RenderHeading       = renderHeading,
                RssToLinkButton     = renderHeading,
                DisableCommentCount = disableCommentCount
            };

            DateTime?maxAge = null;

            if (maxAgeInDays.HasValue)
            {
                maxAge = DateTime.UtcNow.AddDays(-maxAgeInDays.Value);
            }

            IPagedList <BlogPost> blogPosts;

            if (!postsWithTag.IsEmpty())
            {
                blogPosts = _blogService.GetAllBlogPostsByTag(storeId, postsWithTag, 0, maxPostAmount ?? 100, languageId, isAdmin, maxAge);
            }
            else
            {
                blogPosts = _blogService.GetAllBlogPosts(storeId, null, null, 0, maxPostAmount ?? 100, languageId, isAdmin, maxAge);
            }

            Services.DisplayControl.AnnounceRange(blogPosts);

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();

            return(model);
        }
示例#14
0
        /// <summary>
        /// Prepare paged blog post list model
        /// </summary>
        /// <param name="searchModel">Blog post search model</param>
        /// <param name="customerId"></param>
        /// <returns>Blog post list model</returns>
        public virtual BlogPostListModel PrepareBlogPostListModel(BlogPostSearchModel searchModel, int customerId = 0)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get blog posts
            var blogPosts = _blogService.GetAllBlogPosts(customerId: customerId, showHidden: true,
                                                         pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            BlogPostListModel model = new BlogPostListModel
            {
                Data = blogPosts.Select(blogPost =>
                {
                    //fill in model values from the entity
                    BlogPostModel blogPostModel = blogPost.ToModel <BlogPostModel>();

                    //little performance optimization: ensure that "Body" is not returned
                    blogPostModel.Body = string.Empty;

                    //convert dates to the user time
                    if (blogPost.StartDateUtc.HasValue)
                    {
                        blogPostModel.StartDate = blogPost.StartDateUtc.Value;
                    }
                    if (blogPost.EndDateUtc.HasValue)
                    {
                        blogPostModel.EndDate = blogPost.EndDateUtc.Value;
                    }
                    blogPostModel.CreatedOn = blogPost.CreatedOnUtc;

                    //fill in additional values (not existing in the entity)
                    blogPostModel.ApprovedComments    = _blogService.GetBlogCommentsCount(blogPost, isApproved: true);
                    blogPostModel.NotApprovedComments = _blogService.GetBlogCommentsCount(blogPost, isApproved: false);

                    return(blogPostModel);
                }),
                Total = blogPosts.TotalCount
            };

            return(model);
        }
示例#15
0
        /// <summary>
        /// Prepare blog post list model
        /// </summary>
        /// <param name="command">Blog paging filtering model</param>
        /// <returns>Blog post list model</returns>
        public virtual async Task <BlogPostListModel> PrepareBlogPostListModelAsync(BlogPagingFilteringModel command)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (command.PageSize <= 0)
            {
                command.PageSize = _blogSettings.PostsPageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            var dateFrom = command.GetFromMonth();
            var dateTo   = command.GetToMonth();

            var language = await _workContext.GetWorkingLanguageAsync();

            var store = await _storeContext.GetCurrentStoreAsync();

            var blogPosts = string.IsNullOrEmpty(command.Tag)
                ? await _blogService.GetAllBlogPostsAsync(store.Id, language.Id, dateFrom, dateTo, command.PageNumber - 1, command.PageSize)
                : await _blogService.GetAllBlogPostsByTagAsync(store.Id, language.Id, command.Tag, command.PageNumber - 1, command.PageSize);

            var model = new BlogPostListModel
            {
                PagingFilteringContext = { Tag = command.Tag, Month = command.Month },
                WorkingLanguageId      = language.Id,
                BlogPosts = await blogPosts.SelectAwait(async blogPost =>
                {
                    var blogPostModel = new BlogPostModel();
                    await PrepareBlogPostModelAsync(blogPostModel, blogPost, false);
                    return(blogPostModel);
                }).ToListAsync()
            };

            model.PagingFilteringContext.LoadPagedList(blogPosts);

            return(model);
        }
示例#16
0
        public virtual ActionResult List(DataSourceRequest command, BlogPostListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedKendoGridJson());
            }

            #region Extensions by QuanNH

            var _storeMappingService = Nop.Core.Infrastructure.EngineContext.Current.Resolve <IStoreMappingService>();
            int currentStoredId      = _storeMappingService.CurrentStore();
            var blogPosts            = _blogService.GetAllBlogPosts(currentStoredId, 0, null, null, command.Page - 1, command.PageSize, true);

            #endregion

            var gridModel = new DataSourceResult
            {
                Data = blogPosts.Select(x =>
                {
                    var m = x.ToModel();
                    //little performance optimization: ensure that "Body" is not returned
                    m.Body = "";
                    if (x.StartDateUtc.HasValue)
                    {
                        m.StartDate = _dateTimeHelper.ConvertToUserTime(x.StartDateUtc.Value, DateTimeKind.Utc);
                    }
                    if (x.EndDateUtc.HasValue)
                    {
                        m.EndDate = _dateTimeHelper.ConvertToUserTime(x.EndDateUtc.Value, DateTimeKind.Utc);
                    }
                    m.CreatedOn           = _dateTimeHelper.ConvertToUserTime(x.CreatedOnUtc, DateTimeKind.Utc);
                    m.LanguageName        = x.Language.Name;
                    m.ApprovedComments    = _blogService.GetBlogCommentsCount(x, isApproved: true);
                    m.NotApprovedComments = _blogService.GetBlogCommentsCount(x, isApproved: false);

                    return(m);
                }),
                Total = blogPosts.TotalCount
            };

            return(Json(gridModel));
        }
示例#17
0
        public virtual IActionResult List()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            var model = new BlogPostListModel();

            //stores
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var store in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = store.Name, Value = store.Id.ToString()
                });
            }

            return(View(model));
        }
示例#18
0
        public virtual IActionResult List(BlogPostSearchModel searchModel)
        {
            bool isAuthorized = _authorizationService.AuthorizeAsync(User, GetCurrentUserAsync(), CustomerOperations.Read).Result.Succeeded;

            if (!isAuthorized)
            {
                return(AccessDeniedView());
            }
            var customer            = User.GetCustomer(_userManager, _customerService);
            BlogPostListModel model = null;

            if (customer.IsInCustomerRole(CustomerRole.Constants.CustomerManagersRole) && !customer.IsInCustomerRole(CustomerRole
                                                                                                                     .Constants.CustomerAdministratorsRole))
            {
                model = _blogModelFactory.PrepareBlogPostListModel(searchModel, customer.Id);
                return(Json(model));
            }
            //prepare model
            model = _blogModelFactory.PrepareBlogPostListModel(searchModel);

            return(Json(model));
        }
示例#19
0
 public CustomerBlogModel()
 {
     BlogPostModel           = new BlogPostModel();
     AvailableBlogPostModels = new BlogPostListModel();
     BlogPostModels          = new List <BlogPostModel>();
 }
示例#20
0
        /// <summary>
        /// Prepare blog post list model
        /// </summary>
        /// <param name="command">Blog paging filtering model</param>

        /// <param name="editorId"></param>
        /// <returns>Blog post list model</returns>
        public virtual BlogPostListModel PrepareBlogPostListModel(BlogPagingFilteringModel command, int editorId)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            var model = new BlogPostListModel();

            model.PagingFilteringContext.Tag   = command.Tag;
            model.PagingFilteringContext.Month = command.Month;

            if (command.PageSize <= 0)
            {
                command.PageSize = _blogSettings.PostsPageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            var dateFrom = command.GetFromMonth();
            var dateTo   = command.GetToMonth();

            IPagedList <BlogPost> blogPosts;

            if (string.IsNullOrEmpty(command.Tag))
            {
                blogPosts = _blogservice.GetAllBlogPosts(customerId: editorId, dateFrom: dateFrom, dateTo: dateTo, pageIndex: command.PageNumber - 1, pageSize: command.PageSize);
            }
            else
            {
                blogPosts = _blogservice.GetAllBlogPostsByTag(editorId, command.Tag, command.PageNumber - 1, command.PageSize);
            }
            model.PagingFilteringContext.LoadPagedList(blogPosts);
            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();

            var customer = _customerService.GetCustomerById(editorId);
            var appUser  = _customerService.GetApplicationUserById(customer.OwnerId);

            model.EditorModel.AvatarUrl = _pictureService.GetPictureUrl(
                Convert.ToInt32(_customerService.GetCustomerById(customer.Id).Zip), 120, defaultPictureType: PictureType.Avatar);
            model.EditorModel.Email     = appUser.Email;
            model.EditorModel.FirstName = appUser.FirstName;
            model.EditorModel.LastName  = appUser.LastName;
            model.EditorModel.EditorId  = customer.Id;
            var claimsAsync = _customerService.GetUserClaim(customer.OwnerId);

            foreach (var item in claimsAsync)
            {
                if (item.ClaimType == "FacebookLink")
                {
                    model.EditorModel.FaceBookLink = item.ClaimValue ?? "";
                }
                else if (item.ClaimType == "InstagramLink")
                {
                    model.EditorModel.InstagramLink = item.ClaimValue ?? "";
                }
                else if (item.ClaimType == "TwitterLink")
                {
                    model.EditorModel.TwitterLink = item.ClaimValue ?? "";
                }
            }


            return(model);
        }
示例#21
0
        protected BlogPostListModel PrepareBlogPostListModel(BlogPagingFilteringModel command)
        {
            Guard.NotNull(command, nameof(command));

            var storeId    = _services.StoreContext.CurrentStore.Id;
            var languageId = _services.WorkContext.WorkingLanguage.Id;
            var isAdmin    = _services.WorkContext.CurrentCustomer.IsAdmin();

            var model = new BlogPostListModel();

            model.PagingFilteringContext.Tag   = command.Tag;
            model.PagingFilteringContext.Month = command.Month;

            if (command.PageSize <= 0)
            {
                command.PageSize = _blogSettings.PostsPageSize;
            }
            if (command.PageNumber <= 0)
            {
                command.PageNumber = 1;
            }

            DateTime?dateFrom = command.GetFromMonth();
            DateTime?dateTo   = command.GetToMonth();

            IPagedList <BlogPost> blogPosts;

            if (!command.Tag.HasValue())
            {
                blogPosts = _blogService.GetAllBlogPosts(storeId, dateFrom, dateTo, command.PageNumber - 1, command.PageSize, languageId, isAdmin);
            }
            else
            {
                blogPosts = _blogService.GetAllBlogPostsByTag(storeId, command.Tag, command.PageNumber - 1, command.PageSize, languageId, isAdmin);
            }

            model.PagingFilteringContext.LoadPagedList(blogPosts);

            // Prepare SEO model
            var parsedMonth = model.PagingFilteringContext.GetParsedMonth();
            var tag         = model.PagingFilteringContext.Tag;

            if (parsedMonth == null && tag == null)
            {
                model.MetaTitle       = _blogSettings.GetLocalizedSetting(x => x.MetaTitle, storeId);
                model.MetaDescription = _blogSettings.GetLocalizedSetting(x => x.MetaDescription, storeId);
                model.MetaKeywords    = _blogSettings.GetLocalizedSetting(x => x.MetaKeywords, storeId);
            }
            else
            {
                model.MetaTitle = parsedMonth != null?
                                  T("PageTitle.Blog.Month").Text.FormatWith(parsedMonth.Value.ToNativeString("MMMM", CultureInfo.InvariantCulture) + " " + parsedMonth.Value.Year) :
                                      T("PageTitle.Blog.Tag").Text.FormatWith(tag);

                model.MetaDescription = parsedMonth != null?
                                        T("Metadesc.Blog.Month").Text.FormatWith(parsedMonth.Value.ToNativeString("MMMM", CultureInfo.InvariantCulture) + " " + parsedMonth.Value.Year) :
                                            T("Metadesc.Blog.Tag").Text.FormatWith(tag);

                model.MetaKeywords = parsedMonth != null?parsedMonth.Value.ToNativeString("MMMM", CultureInfo.InvariantCulture) + " " + parsedMonth.Value.Year : tag;
            }

            Services.DisplayControl.AnnounceRange(blogPosts);

            model.BlogPosts = blogPosts
                              .Select(x =>
            {
                var blogPostModel = new BlogPostModel();
                PrepareBlogPostModel(blogPostModel, x, false);
                return(blogPostModel);
            })
                              .ToList();

            return(model);
        }