private void UpdateThreadPartCounters(PostPart postPart) { var commonPart = postPart.As <CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { ThreadPart threadPart = postPart.ThreadPart ?? _threadService.Get(commonPart.Record.Container.Id, VersionOptions.Published); threadPart.PostCount = _postService.Count(threadPart, VersionOptions.Published); UpdateForumPartCounters(threadPart); } }
public async Task <ActionResult <ThreadResponseDTO> > Get(int id) { var thread = await _threadsService.Get(id); if (thread == null) { return(NotFound($"Thread with the id of {id} doesn't exist")); } var threadDto = _threadMapper.ToDto(thread); threadDto.CommentsCount = await _commentService.GetCommentsCount(id); return(threadDto); }
public ThreadPartHandler(IRepository<ThreadPartRecord> repository, IPostService postService, IThreadService threadService, IForumService forumService, IContentManager contentManager) { _postService = postService; _threadService = threadService; _forumService = forumService; _contentManager = contentManager; Filters.Add(StorageFilter.For(repository)); OnGetDisplayShape<ThreadPart>(SetModelProperties); OnGetEditorShape<ThreadPart>(SetModelProperties); OnUpdateEditorShape<ThreadPart>(SetModelProperties); OnActivated<ThreadPart>(PropertySetHandlers); OnLoading<ThreadPart>((context, part) => LazyLoadHandlers(part)); OnCreated<ThreadPart>((context, part) => UpdateForumPartCounters(part)); OnPublished<ThreadPart>((context, part) => UpdateForumPartCounters(part)); OnUnpublished<ThreadPart>((context, part) => UpdateForumPartCounters(part)); OnVersioning<ThreadPart>((context, part, newVersionPart) => LazyLoadHandlers(newVersionPart)); OnVersioned<ThreadPart>((context, part, newVersionPart) => UpdateForumPartCounters(newVersionPart)); OnRemoved<ThreadPart>((context, part) => UpdateForumPartCounters(part)); OnRemoved<ForumPart>((context, b) => _threadService .Get(context.ContentItem.As<ForumPart>()) .ToList() .ForEach(thread => context.ContentManager.Remove(thread.ContentItem))); }
public async Task Get_ThreadDoesntExist_ShouldReturnNull() { // Arrange var id = 1; _threadRepositoryMock .Setup(x => x.Get(id)) .ReturnsAsync(() => null); // Act var result = await _threadService.Get(id); // Assert Assert.Null(result); _threadRepositoryMock.Verify(x => x.Get(id), Times.Once); }
public ActionResult Item(int forumId, PagerParameters pagerParameters) { var forumPart = _forumService.Get(forumId, VersionOptions.Published); if (forumPart == null) { return(HttpNotFound()); } if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, forumPart, T("Not allowed to view forum"))) { return(new HttpUnauthorizedResult()); } Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); var threads = _threadService .Get(forumPart, pager.GetStartIndex(), pager.PageSize, VersionOptions.Published) .Select(b => _orchardServices.ContentManager.BuildDisplay(b, "Summary")); dynamic forum = _orchardServices.ContentManager.BuildDisplay(forumPart); var list = Shape.List(); list.AddRange(threads); forum.Content.Add(Shape.Parts_Forums_Thread_List(ContentPart: forumPart, ContentItems: list), "5"); var totalItemCount = forumPart.ThreadCount; forum.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after"); return(new ShapeResult(this, forum)); }
public ActionResult List() { var list = _orchardServices.New.List(); list.AddRange(_forumService.Get(VersionOptions.Latest) .Select(b => { var forum = _contentManager.BuildDisplay(b, "SummaryAdmin"); forum.TotalPostCount = _threadService.Get(b, VersionOptions.Latest).Count(); return(forum); })); dynamic viewModel = _orchardServices.New.ViewModel() .ContentItems(list); // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation. return(View((object)viewModel)); }
private void UpdateForumPartCounters(ThreadPart threadPart) { var commonPart = threadPart.As <CommonPart>(); if (commonPart != null && commonPart.Record.Container != null) { var forumPart = threadPart.ForumPart ?? _forumService.Get(commonPart.Record.Container.Id, VersionOptions.Published); // TODO: Refactor this to do the count in the DB and not make 3 DB calls. forumPart.ThreadCount = _threadService.Count(forumPart, VersionOptions.Published); forumPart.PostCount = _threadService .Get(forumPart, VersionOptions.Published) .Sum(publishedThreadPart => _postService .Count(publishedThreadPart, VersionOptions.Published)); } }
public ActionResult Item(int forumId, int threadId, PagerParameters pagerParameters) { var threadPart = _threadService.Get(forumId, threadId, VersionOptions.Published); if (threadPart == null) { return(HttpNotFound()); } if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, threadPart, T("Not allowed to view thread"))) { return(new HttpUnauthorizedResult()); } var pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); var posts = _postService.Get(threadPart, pager.GetStartIndex(), pager.PageSize, VersionOptions.Published) .Select(b => _orchardServices.ContentManager.BuildDisplay(b, "Detail")); dynamic thread = _orchardServices.ContentManager.BuildDisplay(threadPart); var pagerObject = Shape.Pager(pager).TotalItemCount(threadPart.PostCount); var list = Shape.List(); list.AddRange(posts); thread.Content.Add(Shape.Parts_Threads_Post_List(ContentPart: threadPart, ContentItems: list, Pager: pagerObject), "5"); var part = _orchardServices.ContentManager.New <PostPart>(threadPart.ForumPart.PostType); /* Get Edit Post*/ if (!threadPart.IsClosed && IsAllowedToCreatePost(part)) { dynamic model = _orchardServices.ContentManager.BuildEditor(part); var firstPostId = _postService.GetPositional(threadPart, ThreadPostPositional.First).Id; thread.Content.Add(Shape.Parts_Thread_Post_Create(ContentEditor: model, ContentId: firstPostId), "10"); } return(new ShapeResult(this, thread)); }
public ActionResult List(int forumId) { var forum = _forumService.Get(forumId, VersionOptions.Latest); if (forum == null) { return(HttpNotFound()); } if (!_orchardServices.Authorizer.Authorize(Orchard.Core.Contents.Permissions.ViewContent, forum, T("Not allowed to view forum"))) { return(new HttpUnauthorizedResult()); } var list = _orchardServices.New.List(); list.AddRange(_threadService.Get(forum) .Select(b => _orchardServices.ContentManager.BuildDisplay(b, "SummaryAdmin"))); dynamic viewModel = _orchardServices.New.ViewModel() .ContentItems(list); return(View((object)viewModel)); }
public IActionResult Get() { return(Ok(_threadService.Get())); }