public async Task <IEnumerable <BlogPostModel> > FindPosts(BlogPostSearchModel options) { var filters = new List <FilterDefinition <BlogPostModel> >(); if (!string.IsNullOrEmpty(options.User)) { filters.Add(Builders <BlogPostModel> .Filter.Where(x => x.User == options.User)); } if (!string.IsNullOrEmpty(options.Tag)) { filters.Add(Builders <BlogPostModel> .Filter.Where(x => x.Tags.Contains(options.Tag))); } if (!string.IsNullOrEmpty(options.Text)) { filters.Add(Builders <BlogPostModel> .Filter.Text(options.Text)); } var filter = filters.Count > 0 ? Builders <BlogPostModel> .Filter.And(filters) : FilterDefinition <BlogPostModel> .Empty; return(await _context.Posts .Find(filter) .ToListAsync()); }
public virtual IActionResult List(BlogPostSearchModel searchModel) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog)) { return(AccessDeniedDataTablesJson()); } //prepare model var model = _blogModelFactory.PrepareBlogPostListModel(searchModel); return(Json(model)); }
/// <summary> /// Prepare blog post search model /// </summary> /// <param name="searchModel">Blog post search model</param> /// <returns>Blog post search model</returns> public virtual BlogPostSearchModel PrepareBlogPostSearchModel(BlogPostSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
public virtual async Task <IActionResult> List(BlogPostSearchModel searchModel) { if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageBlog)) { return(await AccessDeniedDataTablesJson()); } //prepare model var model = await _blogModelFactory.PrepareBlogPostListModelAsync(searchModel); return(Json(model)); }
/// <summary> /// Prepare blog post search model /// </summary> /// <param name="searchModel">Blog post search model</param> /// <returns>Blog post search model</returns> public virtual BlogPostSearchModel PrepareBlogPostSearchModel(BlogPostSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare available stores _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores); //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }
/// <summary> /// Prepare blog post search model /// </summary> /// <param name="searchModel">Blog post search model</param> /// <returns>Blog post search model</returns> public virtual BlogPostSearchModel PrepareBlogPostSearchModel(BlogPostSearchModel searchModel) { if (searchModel == null) throw new ArgumentNullException(nameof(searchModel)); //prepare available stores _baseAdminModelFactory.PrepareStores(searchModel.AvailableStores); searchModel.HideStoresList = _catalogSettings.IgnoreStoreLimitations || searchModel.AvailableStores.SelectionIsNotPossible(); //prepare page parameters searchModel.SetGridPageSize(); return searchModel; }
/// <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); }
/// <summary> /// Prepare paged blog post list model /// </summary> /// <param name="searchModel">Blog post search model</param> /// <returns> /// A task that represents the asynchronous operation /// The task result contains the blog post list model /// </returns> public virtual async Task <BlogPostListModel> PrepareBlogPostListModelAsync(BlogPostSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //get blog posts var blogPosts = await _blogService.GetAllBlogPostsAsync(storeId : searchModel.SearchStoreId, showHidden : true, pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize, title : searchModel.SearchTitle); //prepare list model var model = await new BlogPostListModel().PrepareToGridAsync(searchModel, blogPosts, () => { return(blogPosts.SelectAwait(async 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 = await _dateTimeHelper.ConvertToUserTimeAsync(blogPost.StartDateUtc.Value, DateTimeKind.Utc); } if (blogPost.EndDateUtc.HasValue) { blogPostModel.EndDateUtc = await _dateTimeHelper.ConvertToUserTimeAsync(blogPost.EndDateUtc.Value, DateTimeKind.Utc); } blogPostModel.CreatedOn = await _dateTimeHelper.ConvertToUserTimeAsync(blogPost.CreatedOnUtc, DateTimeKind.Utc); //fill in additional values (not existing in the entity) blogPostModel.LanguageName = (await _languageService.GetLanguageByIdAsync(blogPost.LanguageId))?.Name; blogPostModel.ApprovedComments = await _blogService.GetBlogCommentsCountAsync(blogPost, isApproved: true); blogPostModel.NotApprovedComments = await _blogService.GetBlogCommentsCountAsync(blogPost, isApproved: false); blogPostModel.SeName = await _urlRecordService.GetSeNameAsync(blogPost, blogPost.LanguageId, true, false); return blogPostModel; })); }); return(model); }
/// <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); }
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)); }
public Task <IEnumerable <BlogPostModel> > Find([FromBody] BlogPostSearchModel options) { return(_blogRepository.FindPosts(options)); }
public BlogContentModel() { BlogPosts = new BlogPostSearchModel(); BlogComments = new BlogCommentSearchModel(); }
/// <summary> /// Prepare blog post search model /// </summary> /// <param name="searchModel">Blog post search model</param> /// <returns>Blog post search model</returns> protected virtual async Task <BlogPostSearchModel> PrepareBlogPostSearchModelAsync(BlogPostSearchModel searchModel) { if (searchModel == null) { throw new ArgumentNullException(nameof(searchModel)); } //prepare available stores await _baseAdminModelFactory.PrepareStoresAsync(searchModel.AvailableStores); searchModel.HideStoresList = _catalogSettings.IgnoreStoreLimitations || searchModel.AvailableStores.SelectionIsNotPossible(); //prepare page parameters searchModel.SetGridPageSize(); return(searchModel); }