public virtual async Task <IPagedList <PostView> > GetPostsFromMultiCategoriesAsync( MaterialsShowOptions options) { var rez = await db.MaterialsVisible.GetPagedListAsync( x => new PostView { Id = x.Id, Title = x.Title, Preview = x.Text, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, AuthorLink = x.Author.Link, AuthorAvatar = x.Author.Avatar, PublishDate = x.PublishDate, CategoryName = x.Category.Name, CategoryTitle = x.Category.Title, IsCommentsBlocked = x.IsCommentsBlocked }, x => options.CategoriesIds.Contains(x.CategoryId), x => x.OrderByDescending(y => y.PublishDate), options.Page, options.PageSize); foreach (var postView in rez.Items) { var textLength = postView.Preview.Length; postView.Preview = MakePreview.HtmlFirstImage(new HtmlParser().ParseDocument(postView.Preview), options.PreviewSize); postView.HasMoreText = postView.Preview.Length != textLength; } return(rez); }
public async Task <IList <object> > GetMaterialsFromMultiCategoryAsync(MaterialsShowOptions options) { Func <IQueryable <Material>, IOrderedQueryable <Material> > orderBy; if (options.Sort != null) { orderBy = options.Sort; } else { orderBy = MaterialsDefaultSortService.DefaultSortOptions.GetValueOrDefault(nameof(BlogPresenter)); } var result = await db.MaterialsVisible.GetPagedListAsync(x => new PostView { Id = x.Id, Title = x.Title, Preview = x.Text, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, AuthorLink = x.Author.Link, AuthorAvatar = x.Author.Avatar, PublishDate = x.PublishDate, CategoryName = x.Category.Name, CategoryTitle = x.Category.Title, IsCommentsBlocked = x.IsCommentsBlocked }, x => options.CategoriesIds.Contains(x.CategoryId), orderBy, options.Page, options.PageSize ); return(result.Items as IList <Object>); }
public virtual async Task <IActionResult> GetNewTopics(string categoryName, int page = 1) { var categoryParent = categoriesCache.GetCategory(categoryName); if (categoryParent == null) { return(BadRequest()); } var allCategories = categoryParent.AllSubCategories.Where(x => x.IsMaterialsContainer); var categories = authorizationService.GetAllowedCategories(User.Roles, allCategories, OperationKeys.MaterialAndCommentsRead); var categoriesIds = categories.Select(x => x.Id); var options = new MaterialsShowOptions { CategoriesIds = categoriesIds, Page = page, PageSize = forumOptions.CurrentValue.NewTopicsPageSize }; async Task <IPagedList <TopicInfoView> > LoadDataAsync() { return(await forumPresenter.GetNewTopicsAsync(options, forumOptions.CurrentValue.NewTopicsMaxPages)); } return(await CacheContentAsync(categoryParent, categoriesIds, LoadDataAsync, page)); }
public virtual Task <IPagedList <TopicInfoView> > GetNewTopicsAsync(MaterialsShowOptions options, int maxPages) { return(db.MaterialsVisible.GetPagedListMaxAsync( x => new TopicInfoView { Id = x.Id, Title = x.Title, SubTitle = x.SubTitle, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, AuthorAvatar = x.Author.Avatar, PublishDate = x.PublishDate, LastCommentId = x.LastCommentId, LastCommentPublishDate = x.LastCommentId.HasValue ? (DateTime?)x.LastComment.PublishDate : null, CategoryName = x.Category.Name, CategoryTitle = x.Category.Title, LastCommentAuthorName = x.LastComment.Author.UserName, LastCommentAuthorAvatar = x.LastComment.Author.Avatar, IsCommentsBlocked = x.IsCommentsBlocked }, x => options.CategoriesIds.Contains(x.CategoryId), x => x.OrderByDescending(y => y.LastActivity), options.Page, options.PageSize, maxPages)); }
public async Task <IList <object> > GetMaterialsFromMultiCategoryAsync(MaterialsShowOptions options) { Func <IQueryable <Material>, IOrderedQueryable <Material> > order; if (options.Sort != null) { order = options.Sort; } else { order = MaterialsDefaultSortService.DefaultSortOptions.GetValueOrDefault(nameof(ArticlesPresenter)); } var result = await db.MaterialsVisible.GetPagedListAsync(x => new ArticleInfoView { Id = x.Id, Name = x.Name, Title = x.Title, Description = x.SubTitle, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, PublishDate = x.PublishDate, CategoryName = x.Category.Name, CategoryTitle = x.Category.Title, IsCommentsBlocked = x.IsCommentsBlocked }, x => options.CategoriesIds.Contains(x.CategoryId), order, options.Page, options.PageSize); return(result as IList <object>); }
public virtual Task <IPagedList <ArticleInfoView> > GetArticlesAsync(MaterialsShowOptions options) { Func <IQueryable <Material>, IOrderedQueryable <Material> > orderBy; if (options.Sort != null) { orderBy = options.Sort; } else { orderBy = x => x.OrderByDescending(y => y.PublishDate); } IQueryable <Material> query = db.Materials; if (!options.ShowHidden) { query = query.Where(x => !x.IsHidden); } if (!options.ShowDeleted) { query = query.Where(x => x.DeletedDate == null); } return(query.GetPagedListAsync( x => new ArticleInfoView { Id = x.Id, Name = x.Name, Title = x.Title, Description = x.SubTitle, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, PublishDate = x.PublishDate, CategoryName = x.Category.Name, SortNumber = x.SortNumber, IsHidden = x.IsHidden, DeletedDate = x.DeletedDate, IsCommentsBlocked = x.IsCommentsBlocked }, x => x.CategoryId == options.CategoryId, orderBy, options.Page, options.PageSize)); }
public virtual async Task <IActionResult> GetArticles( string categoryName, OrderType sort = OrderType.PublishDate, int page = 1, bool showDeleted = false) { CategoryCached category = categoriesCache.GetCategory(categoryName); if (category == null) { return(BadRequest()); } if (!authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialAndCommentsRead)) { return(Unauthorized()); } var options = new MaterialsShowOptions { CategoryId = category.Id, orderType = sort, Page = page, PageSize = articlesOptions.CurrentValue.CategoryPageSize }; if (authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialHide)) { options.ShowHidden = true; } if (showDeleted && authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialDeleteAny)) { options.ShowDeleted = true; } async Task <IPagedList <ArticleInfoView> > LoadDataAsync() { return(await articlesPresenter.GetArticlesAsync(options)); } if (showDeleted) { return(Ok(await LoadDataAsync())); } return(await CacheContentAsync(category, category.Id, LoadDataAsync, page)); }
public virtual async Task <IPagedList <PostView> > GetPostsAsync(MaterialsShowOptions options) { IQueryable <Material> query = db.Materials; if (!options.ShowHidden) { query = query.Where(x => !x.IsHidden); } if (!options.ShowDeleted) { query = query.Where(x => x.DeletedDate == null); } var rez = await query.GetPagedListAsync( x => new PostView { Id = x.Id, Title = x.Title, Preview = x.Text, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, AuthorLink = x.Author.Link, AuthorAvatar = x.Author.Avatar, PublishDate = x.PublishDate, CategoryName = x.Category.Name, IsCommentsBlocked = x.IsCommentsBlocked, IsHidden = x.IsHidden, DeletedDate = x.DeletedDate }, x => x.CategoryId == options.CategoryId, x => x.OrderByDescending(y => y.PublishDate), options.Page, options.PageSize); foreach (var postView in rez.Items) { var textLength = postView.Preview.Length; postView.Preview = MakePreview.HtmlFirstImage(new HtmlParser().ParseDocument(postView.Preview), blogOptions.CurrentValue.PreviewLength); postView.HasMoreText = postView.Preview.Length != textLength; } return(rez); }
public async Task <IList <object> > GetMaterialsFromMultiCategoryAsync(MaterialsShowOptions options) { Func <IQueryable <Material>, IOrderedQueryable <Material> > orderBy; if (options.Sort != null) { orderBy = options.Sort; } else { orderBy = MaterialsDefaultSortService.DefaultSortOptions.GetValueOrDefault(nameof(MaterialsPresenter)); } IQueryable <Material> materials = db.Materials; var res = await(from material in materials join category in db.GetTable <Category>() on material.CategoryId equals category.Id orderby orderBy where options.CategoriesIds.Contains(material.CategoryId) select new MaterialView() { Id = material.Id, Name = material.Name, Title = material.Title, SubTitle = material.SubTitle, AuthorLink = material.Author.Link, AuthorName = material.Author.UserName, AuthorAvatar = material.Author.Avatar, AuthorId = material.Author.Id, PublishDate = material.PublishDate, EditDate = material.EditDate, CommentsCount = material.CommentsCount, Text = material.Text, CategoryName = material.Category.Name, IsHidden = material.IsHidden, IsCommentsBlocked = material.IsCommentsBlocked, DeletedDate = material.DeletedDate, Tags = material.TagMaterials.OrderBy(y => y.Tag.Name).Select(y => y.Tag.Name).ToArray(), VisitsCount = material.VisitsCount, SettingsJson = material.SettingsJson }).ToListAsync(); return(res as IList <object>); }
public virtual async Task <IActionResult> GetMaterials(GetMaterialsRequest materialsRequest) { SectionServerCached section = sectionsCache.GetSectionServerCached(materialsRequest.SectionName, User.Roles); if (section == null) { return(BadRequest($"No component {materialsRequest.SectionName} found in cache")); } MaterialsServerSection sectionData = section.GetData <MaterialsServerSection>(); if (!("," + sectionData.CategoriesNames + ",").Contains("," + materialsRequest.CategoryName + ",")) { return(BadRequest( $"Can not show {materialsRequest.CategoryName} in {materialsRequest.SectionName} section")); } CategoryCached category = categoriesCache.GetCategory(materialsRequest.CategoryName); if (category == null) { return(BadRequest($"Can not find {materialsRequest.CategoryName} category")); } MaterialsShowOptions options = new MaterialsShowOptions { ShowDeleted = materialsRequest.ShowDeleted, CategoryId = category.Id, Page = materialsRequest.Page, Sort = MaterialsSortOptionsService.MaterialsSortOptions[materialsRequest.Sort] }; using var scope = serviceProvider.CreateScope(); IMaterialsQueryPresenter materialsQueryPresenter = (IMaterialsQueryPresenter)scope.ServiceProvider.GetRequiredService(MaterialsPresenterTypes.GetBySection(section)); return(await CacheContentAsync(category, category.Id, () => materialsQueryPresenter.GetMaterialsByCategoryAsync(options), new RequestOptions() { Sort = materialsRequest.Sort, PageNumber = materialsRequest.Page })); }
public virtual async Task <IActionResult> GetThread(string categoryName, int page = 1, bool showDeleted = false) { var category = categoriesCache.GetCategory(categoryName); if (category == null) { return(BadRequest()); } if (!authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialAndCommentsRead)) { return(Unauthorized()); } var options = new MaterialsShowOptions { CategoryId = category.Id, Page = page, PageSize = forumOptions.CurrentValue.ThreadMaterialsPageSize }; if (authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialHide)) { options.ShowHidden = true; } if (showDeleted && authorizationService.HasAccess(User.Roles, category, OperationKeys.MaterialDeleteAny)) { options.ShowDeleted = true; } async Task <IPagedList <TopicInfoView> > LoadDataAsync() { return(await forumPresenter.GetThreadAsync(options)); } if (showDeleted) { return(Ok(await LoadDataAsync())); } return(await CacheContentAsync(category, category.Id, LoadDataAsync, page)); }
public virtual async Task <IActionResult> GetMaterialsFromMultiCategories(GetMaterialsRequest materialsRequest) { SectionServerCached section = sectionsCache.GetSectionServerCached(materialsRequest.SectionName, User.Roles); if (section == null) { return(BadRequest($"No component {materialsRequest.SectionName} found in cache")); } MaterialsServerSection sectionData = section.GetData <MaterialsServerSection>(); var сategories = categoriesCache.GetAllCategoriesWithChildren(sectionData.CategoriesNames); IList <CategoryCached> categories = authorizationService.GetAllowedCategories(User.Roles, сategories.Values, operationKeysContainer.MaterialAndCommentsRead); if (categories.Count == 0) { return(BadRequest("No categories to show")); } IEnumerable <int> categoriesIds = categories.Select(x => x.Id).ToArray(); MaterialsSortOptionsService.MaterialsSortOptions.TryGetValue(materialsRequest.Sort, out Func <IQueryable <Material>, IOrderedQueryable <Material> > sort); var options = new MaterialsShowOptions { CategoriesIds = categoriesIds, Page = materialsRequest.Page, PageSize = sectionData.PageSize, Sort = sort }; using var scope = serviceProvider.CreateScope(); IMaterialsQueryPresenter materialsQueryPresenter = (IMaterialsQueryPresenter)scope.ServiceProvider.GetRequiredService(MaterialsPresenterTypes.GetBySection(section)); return(await CacheContentAsync(section, categoriesIds, () => materialsQueryPresenter.GetMaterialsFromMultiCategoryAsync(options), materialsRequest.Page)); }
public virtual async Task <IActionResult> GetPostsFromMultiCategories(string sectionName, int page = 1) { var section = sectionsCache.GetSectionServerCached(sectionName, User.Roles); if (section == null) { return(BadRequest($"No component {sectionName} found in cache")); } PostsServerSection sectionData = section.GetData <PostsServerSection>(); var materialsCategoriesDic = categoriesCache.GetAllCategoriesWithChildren(sectionData.Categories); var materialsCategoriesExcludeDic = categoriesCache.GetAllCategoriesWithChildren(sectionData.CategoriesExclude); foreach (var(key, _) in materialsCategoriesExcludeDic) { materialsCategoriesDic.Remove(key); } var categoriesList = authorizationService.GetAllowedCategories(User.Roles, materialsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead); if (categoriesList.Count == 0) { return(BadRequest("No categories to show")); } var categoriesIds = categoriesList.Select(x => x.Id); var options = new MaterialsShowOptions { CategoriesIds = categoriesList.Select(x => x.Id), Page = page, PageSize = sectionData.PageSize, PreviewSize = sectionData.PreviewSize }; return(await CacheContentAsync(section, categoriesIds, () => blogPresenter.GetPostsFromMultiCategoriesAsync(options), page)); }
public virtual Task <IPagedList <ArticleInfoView> > GetArticlesFromMultiCategoriesAsync( MaterialsShowOptions options) { return(db.Materials.Where(x => x.DeletedDate == null && !x.IsHidden).GetPagedListAsync( x => new ArticleInfoView { Id = x.Id, Name = x.Name, Title = x.Title, Description = x.SubTitle, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, PublishDate = x.PublishDate, CategoryName = x.Category.Name, CategoryTitle = x.Category.Title, IsCommentsBlocked = x.IsCommentsBlocked }, x => options.CategoriesIds.Contains(x.CategoryId), x => x.OrderByDescending(y => y.PublishDate), options.Page, options.PageSize)); }
public virtual Task <IPagedList <TopicInfoView> > GetThreadAsync(MaterialsShowOptions options) { IQueryable <Material> query = db.Materials; if (!options.ShowHidden) { query = query.Where(x => !x.IsHidden); } if (!options.ShowDeleted) { query = query.Where(x => x.DeletedDate == null); } return(query.GetPagedListAsync( x => new TopicInfoView { Id = x.Id, Title = x.Title, SubTitle = x.SubTitle, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, AuthorAvatar = x.Author.Avatar, PublishDate = x.PublishDate, LastCommentId = x.LastCommentId, LastCommentPublishDate = x.LastCommentId.HasValue ? (DateTime?)x.LastComment.PublishDate : null, CategoryName = x.Category.Name, LastCommentAuthorName = x.LastComment.Author.UserName, LastCommentAuthorAvatar = x.LastComment.Author.Avatar, IsCommentsBlocked = x.IsCommentsBlocked, IsHidden = x.IsHidden, DeletedDate = x.DeletedDate }, x => x.CategoryId == options.CategoryId, x => x.OrderByDescending(y => y.LastActivity), options.Page, options.PageSize)); }
public virtual async Task <IActionResult> GetArticlesFromMultiCategories(string categoriesNames, int page = 1) { var materialsCategoriesDic = categoriesCache.GetAllCategoriesWithChildren(categoriesNames); IList <CategoryCached> categoriesList = authorizationService.GetAllowedCategories(User.Roles, materialsCategoriesDic.Values, OperationKeys.MaterialAndCommentsRead); if (categoriesList.Count == 0) { return(BadRequest("No categories to show")); } var options = new MaterialsShowOptions { CategoriesIds = categoriesList.Select(x => x.Id), Page = page, PageSize = articlesOptions.CurrentValue.CategoryPageSize }; IPagedList <ArticleInfoView> articles = await articlesPresenter.GetArticlesFromMultiCategoriesAsync(options); return(Json(articles)); }
public async Task <IList <object> > GetMaterialsByCategoryAsync(MaterialsShowOptions options) { Func <IQueryable <Material>, IOrderedQueryable <Material> > orderBy; if (options.Sort != null) { orderBy = options.Sort; } else { orderBy = MaterialsDefaultSortService.DefaultSortOptions.GetValueOrDefault(nameof(ForumPresenter)); } var result = await db.MaterialsVisible.GetPagedListMaxAsync(x => new TopicInfoView() { Id = x.Id, Title = x.Title, SubTitle = x.SubTitle, CommentsCount = x.CommentsCount, AuthorName = x.Author.UserName, AuthorAvatar = x.Author.Avatar, PublishDate = x.PublishDate, LastCommentId = x.LastCommentId, LastCommentPublishDate = x.LastCommentId.HasValue ? (DateTime?)x.LastComment.PublishDate : null, CategoryName = x.Category.Name, CategoryTitle = x.Category.Title, LastCommentAuthorName = x.LastComment.Author.UserName, LastCommentAuthorAvatar = x.LastComment.Author.Avatar, IsCommentsBlocked = x.IsCommentsBlocked }, x => x.CategoryId == options.CategoryId, orderBy, options.Page, options.PageSize); return(result.Items as IList <object>); }