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)); }
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); }
/// <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); }
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); }
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)); }
/// <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 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); }
/// <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); }
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); }