コード例 #1
0
        public virtual async Task <IActionResult> BlogByCategory(BlogPagingFilteringModel command)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var model = await _mediator.Send(new GetBlogPostList()
            {
                Command = command
            });

            return(View("List", model));
        }
コード例 #2
0
        public ActionResult BlogByMonth(string month, BlogPagingFilteringModel command)
        {
            // INFO: param 'month' redunadant, because OutputCache does not include
            // complex type params in cache key computing

            if (!_blogSettings.Enabled)
            {
                return(HttpNotFound());
            }

            var model = PrepareBlogPostListModel(command);

            return(View("List", model));
        }
コード例 #3
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));
        }
コード例 #4
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);
        }
コード例 #5
0
        public ActionResult List(BlogPagingFilteringModel command)
        {
            if (!_blogSettings.Enabled)
            {
                return(HttpNotFound());
            }

            var model = PrepareBlogPostListModel(command);

            if (_seoSettings.CanonicalUrlsEnabled)
            {
                var url = Url.RouteUrl("Blog", null, Request.Url.Scheme);
                _pageAssetsBuilder.AddCanonicalUrlParts(url);
            }

            return(View("List", 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 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);
        }
コード例 #7
0
        public ActionResult BlogByMonth(string month, BlogPagingFilteringModel command)
        {
            // INFO: param 'month' redundant, because OutputCache does not include
            // complex type params in cache key computing

            if (!_blogSettings.Enabled)
            {
                return(HttpNotFound());
            }

            if (_seoSettings.CanonicalUrlsEnabled)
            {
                var blogUrl = Url.RouteUrl("BlogByMonth", new { month }, Request.Url.Scheme);
                _pageAssetsBuilder.AddCanonicalUrlParts(blogUrl);
            }

            var model = PrepareBlogPostListModel(command);

            return(View("List", model));
        }
コード例 #8
0
ファイル: CustomerBlogFactory.cs プロジェクト: agsyazilim/Ags
        /// <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);
        }
コード例 #9
0
 public GetBlogPostList()
 {
     Command = new BlogPagingFilteringModel();
 }
コード例 #10
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);
        }
コード例 #11
0
        public virtual IActionResult BlogByMonth(BlogPagingFilteringModel command, int customerId)
        {
            var model = _customerBlogFactory.PrepareBlogPostListModel(command, customerId);

            return(View("List", model));
        }
コード例 #12
0
        public virtual ActionResult BlogByMonth(BlogPagingFilteringModel command)
        {
            var model = _blogModelFactory.PrepareBlogPostListModel(command);

            return(View("List", model));
        }