Example #1
0
        public ActionResult Forum()
        {
            ForumRepository          repository = new ForumRepository();
            ICollection <ForumModel> posts      = repository.GetForumBy(User.Identity.Name);

            return(View(posts));
        }
        public static ForumRepository GetForumRepository(IUnitOfWork unitOfWork)
        {
            var repository = new ForumRepository();

            repository.UnitOfWork = unitOfWork;
            return(repository);
        }
		private void GetPostService(UnitOfWork uow, out ICategoryService categoryService, out IForumService forumService, out ITopicService topicService, out IPostService postService) {
			ICategoryRepository cateRepo = new CategoryRepository(uow);
			IForumRepository forumRepo = new ForumRepository(uow);
			ITopicRepository topicRepo = new TopicRepository(uow);
			IPostRepository postRepo = new PostRepository(uow);
			IForumConfigurationRepository configRepo = new ForumConfigurationRepository(uow);

			IState request = new DummyRequest();

			ILogger logger = new ConsoleLogger();

			IUserRepository userRepo = new UserRepository(uow);
			User user = userRepo.Create(new User {
				Name = "D. Ummy",
				ProviderId = "12345678",
				FullName = "Mr. Doh Ummy",
				EmailAddress = "[email protected]",
				Culture = "th-TH",
				TimeZone = "GMT Standard Time"
			});

			List<IEventSubscriber> subscribers = new List<IEventSubscriber>();

			IEventPublisher eventPublisher = new EventPublisher(subscribers, logger, request);
			IUserProvider userProvider = new DummyUserProvider(user);
			IPermissionService permService = new PermissionService();
			IForumConfigurationService confService = new ForumConfigurationService(configRepo);

			categoryService = new CategoryService(userProvider, cateRepo, eventPublisher, logger, permService);
			forumService = new ForumService(userProvider, cateRepo, forumRepo, topicRepo, postRepo, eventPublisher, logger, permService);
			topicService = new TopicService(userProvider, forumRepo, topicRepo, postRepo, eventPublisher, logger, permService, confService);
			postService = new PostService(userProvider, forumRepo, topicRepo, postRepo, eventPublisher, logger, permService, confService);
		}
        public static ForumRepository GetForumRepository()
        {
            var repository = new ForumRepository();

            repository.UnitOfWork = GetUnitOfWork();
            return(repository);
        }
Example #5
0
        private void GetForumService(UnitOfWork uow, out ICategoryService categoryService, out IForumService forumService)
        {
            ICategoryRepository cateRepo  = new CategoryRepository(uow);
            IForumRepository    forumRepo = new ForumRepository(uow);
            ITopicRepository    topicRepo = new TopicRepository(uow);
            IPostRepository     postRepo  = new PostRepository(uow);

            IState request = new DummyRequest();

            ILogger logger = new ConsoleLogger();

            IUserRepository userRepo = new UserRepository(uow);
            User            user     = userRepo.Create(new User {
                Name         = "D. Ummy",
                ProviderId   = "12345678",
                FullName     = "Mr. Doh Ummy",
                EmailAddress = "[email protected]",
                Culture      = "th-TH",
                TimeZone     = "GMT Standard Time"
            });

            List <IEventSubscriber> subscribers = new List <IEventSubscriber>();

            IEventPublisher    eventPublisher = new EventPublisher(subscribers, logger, request);
            IUserProvider      userProvider   = new DummyUserProvider(user);
            IPermissionService permService    = new PermissionService();

            categoryService = new CategoryService(userProvider, cateRepo, eventPublisher, logger, permService);
            forumService    = new ForumService(userProvider, cateRepo, forumRepo, topicRepo, postRepo, eventPublisher, logger, permService);
        }
Example #6
0
        public async Task ConcealComment(int projectId,
                                         int commentId,
                                         int commentDiscussionId,
                                         int currentUserId)
        {
            var discussion = await ForumRepository.GetDiscussionByComment(projectId, commentId);

            var childComments = discussion.Comments.Where(c => c.ParentCommentId == commentId);
            var comment       = discussion.Comments.FirstOrDefault(coment => coment.CommentId == commentId);

            if (comment == null)
            {
                throw new JoinRpgEntityNotFoundException(commentId, nameof(Comment));
            }

            if (comment.HasMasterAccess(currentUserId) && !childComments.Any() &&
                comment.IsVisibleToPlayer && !comment.IsCommentByPlayer)
            {
                comment.IsVisibleToPlayer = false;
                await UnitOfWork.SaveChangesAsync();
            }
            else
            {
                throw new JoinRpgConcealCommentException();
            }
        }
        public async Task <ActionResult> ListThreads(int projectid)
        {
            var project = await ProjectRepository.GetProjectAsync(projectid);

            if (project == null)
            {
                return(NotFound());
            }
            var isMaster = project.HasMasterAccess(CurrentUserIdOrDefault);
            IEnumerable <int>?groupIds;

            if (isMaster)
            {
                groupIds = null;
            }
            else
            {
                var claims = await ClaimsRepository.GetClaimsForPlayer(projectid, ClaimStatusSpec.Approved, CurrentUserId);

                groupIds = claims.SelectMany(claim => claim.Character.GetGroupsPartOf().Select(g => g.CharacterGroupId));
            }
            var threads = await ForumRepository.GetThreads(projectid, isMaster, groupIds);

            var viewModel = new ForumThreadListViewModel(project, threads, CurrentUserId);

            return(View(viewModel));
        }
Example #8
0
        public async Task <ActionResult> RedirectToDiscussion(int projectid,
                                                              int?commentid,
                                                              int?commentDiscussionId)
        {
            CommentDiscussion discussion;

            if (commentid != null)
            {
                discussion = await ForumRepository.GetDiscussionByComment(projectid, (int)commentid);
            }
            else if (commentDiscussionId != null)
            {
                discussion =
                    await ForumRepository.GetDiscussion(projectid, (int)commentDiscussionId);
            }
            else
            {
                return(HttpNotFound());
            }

            if (!discussion.HasAnyAccess(CurrentUserId))
            {
                return(NoAccesToProjectView(discussion.Project));
            }

            return(ReturnToParent(discussion, commentid != null ? $"comment{commentid}" : null));
        }
Example #9
0
 public UpdateSubForumWork(ForumRepository forumRepository, CategoryRepository categoryRepository, CategoryContract updatedCategory,
                           CategoryContract oldCategory) : base(forumRepository)
 {
     m_forumRepository    = forumRepository;
     m_categoryRepository = categoryRepository;
     m_updatedCategory    = updatedCategory;
     m_oldCategory        = oldCategory;
 }
Example #10
0
        public async Task DeleteForum_ForumDoesNotExist_DoesNotCallDelete()
        {
            A.CallTo(() => ForumRepository.Read(1)).Returns(null as Forum);

            await ForumService.Delete(1);

            A.CallTo(() => ForumRepository.Delete(A <Forum> .Ignored)).MustNotHaveHappened();
        }
Example #11
0
 public SubForumManager(ForumRepository forumRepository, CategoryRepository categoryRepository,
                        ForumAccessSubwork forumAccessSubwork, ForumSiteUrlHelper forumSiteUrlHelper)
 {
     m_forumRepository    = forumRepository;
     m_categoryRepository = categoryRepository;
     m_forumAccessSubwork = forumAccessSubwork;
     m_forumSiteUrlHelper = forumSiteUrlHelper;
 }
Example #12
0
        public async Task UpdateForum_ForumDoesNotExist_ReturnsNull()
        {
            A.CallTo(() => ForumRepository.Read(1)).Returns(null as Forum);

            var response = await ForumService.Update(1, new UpdateForum());

            Assert.Null(response);
        }
Example #13
0
 public CreateSubForumWork(ForumRepository forumRepository, CategoryRepository categoryRepository,
                           ForumAccessSubwork forumAccessSubwork, CategoryContract category) : base(forumRepository)
 {
     m_forumRepository    = forumRepository;
     m_categoryRepository = categoryRepository;
     m_forumAccessSubwork = forumAccessSubwork;
     m_category           = category;
 }
Example #14
0
        public ActionResult ComposePost(ForumModel model)
        {
            ForumRepository repository = new ForumRepository();

            repository.AddPost(User.Identity.Name, model.title, model.content, model.courseId);

            return(RedirectToAction("PostMessage"));
        }
Example #15
0
        public ActionResult ReadPost(ForumModel model)
        {
            ForumRepository repository = new ForumRepository();

            repository.MarkRead(model.postId);

            return(View(model));
        }
        public async Task <ActionResult> ConcealComment(int projectid, int commentid, int commentDiscussionId)
        {
            await ClaimService.ConcealComment(projectid, commentid, commentDiscussionId, CurrentUserId);

            var discussion =
                await ForumRepository.GetDiscussion(projectid, commentDiscussionId);

            return(CommentRedirectHelper.RedirectToDiscussion(Url, discussion));
        }
Example #17
0
 public HomeController(ILogger <HomeController> logger, UserManager <User> userManager, UserRepository userRepository, ForumRepository forumRepository, TopicRepository topicRepository, PostRepository postRepository)
 {
     _logger          = logger;
     _userManager     = userManager;
     _userRepository  = userRepository;
     _forumRepository = forumRepository;
     _topicRepository = topicRepository;
     _postRepository  = postRepository;
 }
Example #18
0
 public UpdateForumWork(ForumRepository forumRepository, MessageSubwork messageSubwork,
                        UserRepository userRepository, ProjectDetailContract project, string messageText, string defaultAuthorUsername) : base(forumRepository)
 {
     m_forumRepository       = forumRepository;
     m_messageSubwork        = messageSubwork;
     m_userRepository        = userRepository;
     m_project               = project;
     m_messageText           = messageText;
     m_defaultAuthorUsername = defaultAuthorUsername;
 }
 public CreateVirtualForumsForCategoriesWork(ForumRepository forumRepository, ForumAccessSubwork forumAccessSubwork,
                                             ForumSiteUrlHelper forumSiteUrlHelper, IList <int> categoryIds, IList <int> oldCategoryIds, long projectId) : base(
         forumRepository)
 {
     m_forumRepository    = forumRepository;
     m_forumAccessSubwork = forumAccessSubwork;
     m_forumSiteUrlHelper = forumSiteUrlHelper;
     m_categoryIds        = categoryIds;
     m_oldCategoryIds     = oldCategoryIds;
     m_projectId          = projectId;
 }
Example #20
0
 public UnitOfWork(ANDbContext context)
 {
     _context  = context;
     Animes    = new AnimeRepository(_context);
     Favorites = new FavoriteRepository(_context);
     Forums    = new ForumRepository(_context);
     Messages  = new MessageRepository(_context);
     Genres    = new GenreRepository(_context);
     Ratings   = new RatingRepository(_context);
     Studios   = new StudioRepository(_context);
 }
Example #21
0
        public async Task UpdateForum_UserDoesNotOwnForum_ReturnsNull()
        {
            var forum = new Forum {
                UserId = "Id"
            };

            A.CallTo(() => ForumRepository.Read(1)).Returns(forum);
            A.CallTo(() => UserService.Is(forum.UserId)).Returns(false);

            var response = await ForumService.Update(1, new UpdateForum());

            Assert.Null(response);
        }
Example #22
0
        public async Task List_FetchesAllForums()
        {
            A.CallTo(() => ForumRepository.List())
            .Returns(new List <Forum> {
                new Forum()
            });

            var list = await ForumService.List();

            Assert.NotEmpty(list);
            A.CallTo(() => ForumRepository.List())
            .MustHaveHappenedOnceExactly();
        }
Example #23
0
 public ForumManager(ForumRepository forumRepository, CategoryRepository categoryRepository,
                     UserRepository userRepository, ForumAccessSubwork forumAccessSubwork, MessageSubwork messageSubwork,
                     ForumSiteUrlHelper forumSiteUrlHelper, ForumDefaultMessageGenerator forumDefaultMessageGenerator, IOptions <ForumOption> forumOptions)
 {
     m_forumRepository              = forumRepository;
     m_categoryRepository           = categoryRepository;
     m_userRepository               = userRepository;
     m_forumAccessSubwork           = forumAccessSubwork;
     m_messageSubwork               = messageSubwork;
     m_forumSiteUrlHelper           = forumSiteUrlHelper;
     m_forumDefaultMessageGenerator = forumDefaultMessageGenerator;
     m_forumOptions = forumOptions.Value;
 }
Example #24
0
        public async Task DeleteForum_UserDoesNotOwnForum_DoesNotDelete()
        {
            var forum = new Forum {
                UserId = "Id"
            };

            A.CallTo(() => ForumRepository.Read(1)).Returns(forum);
            A.CallTo(() => UserService.Is(forum.UserId)).Returns(false);

            await ForumService.Delete(1);

            A.CallTo(() => ForumRepository.Delete(A <Forum> .Ignored)).MustNotHaveHappened();
        }
        public async Task <ActionResult> ListThreadsByGroup(int projectid, int characterGroupId)
        {
            var group = await ProjectRepository.GetGroupAsync(projectid, characterGroupId);

            if (group == null)
            {
                return(NotFound());
            }
            var isMaster = group.HasMasterAccess(CurrentUserIdOrDefault);
            var threads  = await ForumRepository.GetThreads(projectid, isMaster, new[] { characterGroupId });

            var viewModel = new ForumThreadListForGroupViewModel(group, threads.Where(t => t.HasAnyAccess(CurrentUserIdOrDefault)), CurrentUserId);

            return(View(viewModel));
        }
        private async Task <ForumThread> GetForumThread(int projectid, int forumThreadId)
        {
            var forumThread = await ForumRepository.GetThread(projectid, forumThreadId);

            var isMaster = forumThread.HasMasterAccess(CurrentUserId);
            var isPlayer = forumThread.IsVisibleToPlayer &&
                           (await ClaimsRepository.GetClaimsForPlayer(projectid, ClaimStatusSpec.Approved, CurrentUserId)).Any(
                claim => claim.IsPartOfGroup(forumThread.CharacterGroupId));

            if (!isMaster && !isPlayer)
            {
                throw new NoAccessToProjectException(forumThread, CurrentUserId);
            }
            return(forumThread);
        }
Example #27
0
        public async Task Read_FetchesForum()
        {
            var forum = new Forum {
                Id = 1
            };

            A.CallTo(() => ForumRepository.Read(1))
            .Returns(forum);

            var response = await ForumService.Read(1);

            Assert.Equal(forum.Id, response.Id);
            A.CallTo(() => ForumRepository.Read(1))
            .MustHaveHappenedOnceExactly();
        }
        public async Task <ActionResult> CreateComment(AddCommentViewModel viewModel)
        {
            CommentDiscussion discussion = await ForumRepository.GetDiscussion(viewModel.ProjectId, viewModel.CommentDiscussionId);

            discussion.RequestAnyAccess(CurrentUserId);

            if (discussion == null)
            {
                return(NotFound());
            }

            try

            {
                if (viewModel.HideFromUser)
                {
                    _ = discussion.RequestMasterAccess(CurrentUserId);
                }

                var claim = discussion.GetClaim();
                if (claim != null)
                {
                    await ClaimService.AddComment(discussion.ProjectId,
                                                  claim.ClaimId,
                                                  viewModel.ParentCommentId,
                                                  !viewModel.HideFromUser,
                                                  viewModel.CommentText,
                                                  (FinanceOperationAction)viewModel.FinanceAction);
                }
                else
                {
                    var forumThread = discussion.GetForumThread();
                    if (forumThread != null)
                    {
                        await ForumService.AddComment(discussion.ProjectId, forumThread.ForumThreadId, viewModel.ParentCommentId,
                                                      !viewModel.HideFromUser, viewModel.CommentText);
                    }
                }

                return(CommentRedirectHelper.RedirectToDiscussion(Url, discussion));
            }
            catch
            {
                //TODO: Message that comment is not added
                return(CommentRedirectHelper.RedirectToDiscussion(Url, discussion));
            }
        }
Example #29
0
        public async Task UpdateForum_UserIsAuthorized_ReturnsUpdatedForum()
        {
            var forum = new Forum
            {
                Id     = 1,
                UserId = "User id",
            };

            A.CallTo(() => ForumRepository.Read(1)).Returns(forum);
            A.CallTo(() => UserService.Is(forum.UserId)).Returns(true);

            await ForumService.Delete(1);

            A.CallTo(() => ForumRepository.Delete(A <Forum> .That.Matches(f =>
                                                                          f.Id == forum.Id &&
                                                                          f.UserId == forum.UserId
                                                                          ))).MustHaveHappenedOnceExactly();
        }
Example #30
0
        public async Task UpdateForum_EverythingOk_ReturnsUpdatedForum()
        {
            var forum = new Forum
            {
                Description = "Description",
                UserId      = "User id",
            };

            A.CallTo(() => ForumRepository.Read(1)).Returns(forum);
            A.CallTo(() => UserService.Is(forum.UserId)).Returns(true);

            var update = await ForumService.Update(1, new UpdateForum());

            A.CallTo(() => ForumRepository.Update(A <Forum> .That.Matches(f =>
                                                                          f.Description == forum.Description &&
                                                                          f.UserId == forum.UserId
                                                                          ))).MustHaveHappenedOnceExactly();
            Assert.Equal(forum, update);
        }
Example #31
0
        public async Task Create_UserIsAuthenticated_CreatesForum()
        {
            var create = new CreateForum();
            var forum  = new Forum {
                Title = "title", Description = "description"
            };

            A.CallTo(() => UserService.Exists()).Returns(true);
            A.CallTo(() => Mapper.Map <Forum>(create)).Returns(forum);
            A.CallTo(() => UserService.Id()).Returns(UserId);

            await ForumService.Create(create);

            A.CallTo(() => ForumRepository.Create(A <Forum> .That.Matches(f =>
                                                                          f.Title == forum.Title &&
                                                                          f.Description == forum.Description &&
                                                                          f.UserId == UserId
                                                                          ))).MustHaveHappenedOnceExactly();
        }
Example #32
0
 public ForumController()
 {
     _repository = new ForumRepository();
 }
 public static ForumRepository GetForumRepository()
 {
     var repository = new ForumRepository();
     repository.UnitOfWork = GetUnitOfWork();
     return repository;
 }
 public static ForumRepository GetForumRepository(IUnitOfWork unitOfWork)
 {
     var repository = new ForumRepository();
     repository.UnitOfWork = unitOfWork;
     return repository;
 }