void ContentService_Deleted(IContentService sender, Umbraco.Core.Events.DeleteEventArgs<Umbraco.Core.Models.IContent> e)
        {
            var fs = new ForumService(ApplicationContext.Current.DatabaseContext);
            foreach (var ent in e.DeletedEntities.Where(x => x.ContentType.Alias == "Forum"))
            {

                var f = fs.GetById(ent.Id);
                if (f != null)
                    fs.Delete(f);
            }
        }
Exemple #2
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_userManager != null)
         {
             _userManager.Dispose();
             _userManager = null;
         }
         if (_forumService != null)
         {
             _forumService.Dispose();
             _forumService = null;
         }
         if (_reputationSystem != null)
         {
             _reputationSystem.Dispose();
             _reputationSystem = null;
         }
         if (_forumUserManager != null)
         {
             _forumUserManager.Dispose();
             _forumUserManager = null;
         }
         if (_groupManager != null)
         {
             _groupManager.Dispose();
             _groupManager = null;
         }
         if (_messageManager != null)
         {
             _messageManager.Dispose();
             _messageManager = null;
         }
         if (_privateMessagingSystem != null)
         {
             _privateMessagingSystem.Dispose();
             _privateMessagingSystem = null;
         }
         if (_threadManager != null)
         {
             _threadManager.Dispose();
             _threadManager = null;
         }
     }
     base.Dispose(disposing);
 }
        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));
            }
        }
Exemple #4
0
        public void ForumServiceGetPosts_InjectCustomPosts_PostsShouldEquals()
        {
            //arrange
            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.Posts.GetAll()).Returns(uowt.Posts.GetAll());

            var service = new ForumService(mock.Object);

            //act
            var result = service.GetPosts(1).ToList();

            //assert
            Assert.AreEqual(uowt.Posts.GetAll().Where(p => p.CategoryID == 1).ToList().Count, result.Count);
            Assert.AreEqual(uowt.Posts.GetAll().ToList()[0].Title, result[0].Title);
            Assert.AreEqual(uowt.Posts.GetAll().ToList()[1].Title, result[1].Title);
        }
        public ActionResult Update(string categoryName, int?boardIDnull)
        {
            int             boardID = boardIDnull ?? 0;
            CategoryService cs      = new CategoryService();
            ForumService    fs      = new ForumService();

            if (categoryName == null || boardIDnull == null || cs.GetCategory(categoryName, boardID) == null)
            {
                return(Redirect("~/ForumAdmin"));
            }
            Category category = cs.GetCategory(categoryName, boardID);

            ViewBag.forumList       = fs.GetForumList(category.Id);
            ViewBag.preCategoryName = category.Name;
            ViewBag.boardID         = category.BoardId;
            return(View(category));
        }
Exemple #6
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();
        }
Exemple #7
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();
        }
Exemple #8
0
        public void ForumServiceGetCategories_InjectCustomCategories_CategoriesShouldEquals()
        {
            //arrange
            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(m => m.Categories.GetAll()).Returns(uowt.Categories.GetAll());

            var service = new ForumService(mock.Object);

            //act
            var result = service.GetCategories().ToList();

            //assert
            Assert.AreEqual(uowt.Categories.GetAll().ToList().Count, result.Count);
            Assert.AreEqual(uowt.Categories.GetAll().ToList()[0].Title, result[0].Title);
            Assert.AreEqual(uowt.Categories.GetAll().ToList()[1].Title, result[1].Title);
            Assert.AreEqual(uowt.Categories.GetAll().ToList()[2].Title, result[2].Title);
            Assert.AreEqual(uowt.Categories.GetAll().ToList()[3].Title, result[3].Title);
        }
Exemple #9
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);
        }
Exemple #10
0
        public MitternachtBot(int shardId, int parentProcessId, int?port = null)
        {
            if (shardId < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(shardId));
            }

            LogSetup.SetupLogger();
            _log = LogManager.GetCurrentClassLogger();
            TerribleElevatedPermissionCheck();

            Credentials = new BotCredentials();
            _db         = new DbService(Credentials);
            _fs         = new ForumService(Credentials);
            Client      = new DiscordSocketClient(new DiscordSocketConfig
            {
                MessageCacheSize    = 10,
                LogLevel            = LogSeverity.Warning,
                ConnectionTimeout   = int.MaxValue,
                TotalShards         = Credentials.TotalShards,
                ShardId             = shardId,
                AlwaysDownloadUsers = false
            });
            CommandService = new CommandService(new CommandServiceConfig {
                CaseSensitiveCommands = false,
                DefaultRunMode        = RunMode.Sync
            });

            port       = port ?? Credentials.ShardRunPort;
            _comClient = new ShardComClient(port.Value);

            using (var uow = _db.UnitOfWork)
            {
                _botConfig = uow.BotConfig.GetOrCreate();
                OkColor    = new Color(Convert.ToUInt32(_botConfig.OkColor, 16));
                ErrorColor = new Color(Convert.ToUInt32(_botConfig.ErrorColor, 16));
            }

            SetupShard(parentProcessId, port.Value);

            Client.Log += Client_Log;
        }
        public async Task Edit_Forum_Correctrly_By_EditForum()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Edit_Forum").Options;

            //Arrange
            using (var ctx = new ApplicationDbContext(options))
            {
                ctx.Forums.Add(new Forum
                {
                    Id          = 228,
                    Title       = "Test Forum",
                    Description = "Desc for test forum"
                });

                ctx.Forums.Add(new Forum
                {
                    Id          = 554,
                    Title       = "Second Forum",
                    Description = "desc for second forum"
                });

                ctx.SaveChanges();
            }

            //Act
            using (var ctx = new ApplicationDbContext(options))
            {
                var forumService = new ForumService(ctx);
                var newForum     = new EditForumModel {
                    Title = "Edited Title", Description = "Edited desc"
                };
                var forum = ctx.Forums.Find(228);
                forum.Title       = newForum.Title;
                forum.Description = newForum.Description;
                await forumService.Edit(forum);

                //Assert
                Assert.AreEqual(newForum.Title, forum.Title);
                Assert.AreEqual(newForum.Description, forum.Description);
            }
        }
Exemple #12
0
        public void Filtered_Posts_Returns_Correct_Result_Count()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Search_Database").Options;

            using (var ctx = new ApplicationDbContext(options))
            {
                ctx.Forums.Add(new Data.Models.Forum()
                {
                    Id = 19
                });

                ctx.Posts.Add(new Post
                {
                    Forum   = ctx.Forums.Find(19),
                    Id      = 21341,
                    Title   = "Functional programming",
                    Content = "Does anyone have experience deploying Haskell to production?"
                });

                ctx.Posts.Add(new Post
                {
                    Forum   = ctx.Forums.Find(19),
                    Id      = -324,
                    Title   = "Haskell Tail Recursion",
                    Content = "Haskell Haskell"
                });

                ctx.SaveChanges();
            }

            using (var ctx = new ApplicationDbContext(options))
            {
                var postService      = new PostService(ctx);
                var postReplyService = new PostReplyService(ctx);
                var forumService     = new ForumService(ctx, postService, postReplyService);
                var postCount        = forumService.GetFilteredPosts(19, "Haskell").Count();
                Assert.AreEqual(2, postCount);
            }
        }
Exemple #13
0
        private async Task <IForumService> Setup(CakeItDbContext db)
        {
            var mockLogger = new Mock <ILogger <ForumService> >();

            this.logger      = mockLogger.Object;
            this.postRepo    = new Repository <Post>(db);
            this.commentRepo = new Repository <Comment>(db);
            this.userRepo    = new Repository <CakeItUser>(db);
            await SeedUsers(userRepo);

            this.tagRepo = new Repository <Tag>(db);
            await SeedTags(tagRepo);

            this.tagPostsRepo = new Repository <TagPosts>(db);
            var mockSanitizer = new Mock <HtmlSanitizerAdapter>();

            this.sanitizer = mockSanitizer.Object;

            var forumService = new ForumService(logger, postRepo, commentRepo, userRepo, tagRepo, tagPostsRepo, this.Mapper, sanitizer);

            return(forumService);
        }
        public async Task Add_WritesToDatabase()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Add_Dtabase")
                          .Options;

            //Act
            // Run the test against one instance of the context
            using (var context = new ApplicationDbContext(options))
            {
                var forumService = new ForumService(context, _postService);
                await forumService.Add(new Forum());
            }

            // Assert
            // Use a separate instance of the context to verify correct data was saved to database
            using (var context = new ApplicationDbContext(options))
            {
                Assert.Equal(expected: 1, actual: context.Forums.Count());
            }
        }
        public ActionResult Update(Category category, string SortOrder, string submitFlag,
                                   string forumName, string forumSortOrder, string forumDescription, int boardIDnull,
                                   string categoryName, string preCategoryName, int?parentForumID)
        {
            CategoryService cs = new CategoryService();

            if (submitFlag.Equals(SubmitFlagUtilities.UpdateCategory.ToString()))
            {
                //If Update Category
                if (!category.Name.Equals(preCategoryName))
                {
                    if (cs.GetCategory(category.Name, category.BoardId) != null)
                    {
                        TempData["Fail"] = "Category Name Already exist!";
                        return(RedirectToAction("Update", new { categoryName = preCategoryName, boardIDnull = category.BoardId }));
                    }
                }
                cs.UpdateCategory(category);
                TempData["Success"] = "Updated Successfully!";
                return(RedirectToAction("Update", new { categoryName = category.Name, boardIDnull = category.BoardId }));
            }
            if (submitFlag.Equals(SubmitFlagUtilities.CreateForum.ToString()))
            {
                //If Create New Forum
                ForumService fs = new ForumService();
                if (fs.AddForum(category.Id, forumName, int.Parse(forumSortOrder), forumDescription, parentForumID))
                {
                    TempData["CreateForum"] = "Forum Created!";
                    return(RedirectToAction("Update", new { categoryName = categoryName, boardIDnull = boardIDnull }));
                }
                else
                {
                    TempData["ForumExist"] = "Forum name already exist!";
                    return(RedirectToAction("Update", new { categoryName = categoryName, boardIDnull = boardIDnull }));
                }
            }
            return(View());
        }
        void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
        {
            var fs = new ForumService(ApplicationContext.Current.DatabaseContext);
            foreach (var ent in e.PublishedEntities.Where(x => x.ContentType.Alias == "Forum"))
            {
                Forum f = fs.GetById(ent.Id);

                if (f == null)
                {
                    f = new Forum();
                    f.Id = ent.Id;
                    f.ParentId = ent.ParentId;
                    f.SortOrder = ent.SortOrder;
                    f.TotalTopics = 0;
                    f.TotalComments = 0;
                    f.LatestPostDate = DateTime.Now;
                    f.LatestAuthor = 0;
                    f.LatestComment = 0;
                    f.LatestTopic = 0;
                    fs.Save(f);
                }
            }
        }
        void ContentService_Published(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs <Umbraco.Core.Models.IContent> e)
        {
            var fs = new ForumService(ApplicationContext.Current.DatabaseContext);

            foreach (var ent in e.PublishedEntities.Where(x => x.ContentType.Alias == "Forum"))
            {
                Models.Forum f = fs.GetById(ent.Id);

                if (f == null)
                {
                    f                = new Models.Forum();
                    f.Id             = ent.Id;
                    f.ParentId       = ent.ParentId;
                    f.SortOrder      = ent.SortOrder;
                    f.TotalTopics    = 0;
                    f.TotalComments  = 0;
                    f.LatestPostDate = DateTime.Now;
                    f.LatestAuthor   = 0;
                    f.LatestComment  = 0;
                    f.LatestTopic    = 0;
                    fs.Save(f);
                }
            }
        }
Exemple #18
0
        public async Task Create_PostIsCreated_ReturnsPostWithExpectedValues()
        {
            var create = new CreatePost();
            var post   = new Post {
                Content = "Content"
            };
            var forum = new Forum {
                Id = 1
            };

            A.CallTo(() => User.Exists()).Returns(true);
            A.CallTo(() => ForumService.Read(forum.Id)).Returns(forum);
            A.CallTo(() => Mapper.Map <Post>(create)).Returns(post);
            A.CallTo(() => User.Id()).Returns("User Id");

            var result = await PostService.Create(1, create);

            Assert.Equal("User Id", result.UserId);
            A.CallTo(() => PostRepository.Create(A <Post> .That.Matches(p =>
                                                                        p.Content == "Content" &&
                                                                        p.UserId == "User Id" &&
                                                                        p.Forum.Id == forum.Id
                                                                        ))).MustHaveHappenedOnceExactly();
        }
        public async Task Create_Forum_Creates_New_Forum_Via_Context()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Create_Forum_Test").Options;

            using (var ctx = new ApplicationDbContext(options))
            {
                var forumService = new ForumService(ctx);

                var forum = new Forum
                {
                    Title       = "Test Forum Title",
                    Description = "New Forum"
                };

                await forumService.Create(forum);
            }

            using (var ctx = new ApplicationDbContext(options))
            {
                Assert.AreEqual(1, ctx.Forums.CountAsync().Result);
                Assert.AreEqual("Test Forum Title", ctx.Forums.SingleAsync().Result.Title);
            }
        }
Exemple #20
0
        public ForumServiceTests()
        {
            //Setup
            forumData           = new ForumModel();
            forumThreadData     = new ForumThreadModel();
            forumThreadPostData = new ForumThreadPostModel();
            forumUserData       = new ForumUserModel();

            settingsData           = new SettingsData();
            mockedSettingsProvider = new Mock <ISettingsProvider>();
            mockedSettingsProvider.SetupGet <SettingsData>(sd => sd.Current).Returns(settingsData);

            mockedForumDal = new Mock <IForumDal>();
            mockedForumDal.Setup(fd => fd.InsertForum(forumData, false)).Returns(Task.Delay(0));
            mockedForumDal.Setup(fd => fd.UpdateForum(forumData)).Returns(Task.Delay(0));
            mockedForumDal.Setup(fd => fd.GetForumById(invalidGuid, null)).ReturnsAsync((ForumModel)null);
            mockedForumDal.Setup(fd => fd.GetForumById(validGuid, null)).ReturnsAsync(new ForumModel());
            mockedForumDal.Setup(ad => ad.GetForumById(visibleGuid, null)).ReturnsAsync(new ForumModel()
            {
                VisibleFlag = true
            });
            mockedForumDal.Setup(ad => ad.GetForumById(hiddenGuid, null)).ReturnsAsync(new ForumModel()
            {
                VisibleFlag = false
            });
            mockedForumDal.Setup(ad => ad.ListForums()).ReturnsAsync(new List <ForumModel> {
                new ForumModel()
                {
                    VisibleFlag = true
                },
                new ForumModel()
                {
                    VisibleFlag = false
                }
            });
            mockedForumDal.Setup(fd => fd.InsertForumThread(forumThreadData, false)).Returns(Task.Delay(0));
            mockedForumDal.Setup(fd => fd.UpdateForumThread(forumThreadData)).Returns(Task.Delay(0));
            mockedForumDal.Setup(fd => fd.GetForumThreadById(invalidGuid, null)).ReturnsAsync((ForumThreadModel)null);
            mockedForumDal.Setup(fd => fd.GetForumThreadById(validGuid, null)).ReturnsAsync(new ForumThreadModel()
            {
                ForumUserGuid = validGuid, VisibleFlag = true, LockFlag = false, CreatedUTC = DateTime.UtcNow.AddMinutes(-1)
            });
            mockedForumDal.Setup(fd => fd.GetForumThreadById(semiValidGuid1, null)).ReturnsAsync(new ForumThreadModel()
            {
                ForumUserGuid = validGuid, VisibleFlag = false, LockFlag = false, CreatedUTC = DateTime.UtcNow.AddMinutes((-1 * settingsData.TimeLimitForumPostEdit) - 1)
            });
            mockedForumDal.Setup(fd => fd.GetForumThreadById(semiValidGuid2, null)).ReturnsAsync(new ForumThreadModel()
            {
                ForumUserGuid = validGuid, VisibleFlag = true, LockFlag = true, CreatedUTC = DateTime.UtcNow.AddMinutes((-1 * settingsData.TimeLimitForumPostEdit) - 1)
            });
            mockedForumDal.Setup(ad => ad.GetForumThreadById(visibleGuid, null)).ReturnsAsync(new ForumThreadModel()
            {
                VisibleFlag = true
            });
            mockedForumDal.Setup(ad => ad.GetForumThreadById(hiddenGuid, null)).ReturnsAsync(new ForumThreadModel()
            {
                VisibleFlag = false
            });
            mockedForumDal.Setup(ad => ad.ListForumThreads(null, null)).ReturnsAsync(new List <ForumThreadModel> {
                new ForumThreadModel()
                {
                    VisibleFlag = true
                },
                new ForumThreadModel()
                {
                    VisibleFlag = false
                }
            });
            mockedForumDal.Setup(fd => fd.InsertForumThreadPost(forumThreadPostData, false)).Returns(Task.Delay(0));
            mockedForumDal.Setup(fd => fd.UpdateForumThreadPost(forumThreadPostData)).Returns(Task.Delay(0));
            mockedForumDal.Setup(fd => fd.GetForumThreadPostById(invalidGuid)).ReturnsAsync((ForumThreadPostModel)null);
            mockedForumDal.Setup(fd => fd.GetForumThreadPostById(validGuid)).ReturnsAsync(new ForumThreadPostModel()
            {
                ForumUserGuid = validGuid, VisibleFlag = true, LockFlag = false, CreatedUTC = DateTime.UtcNow.AddMinutes(-1)
            });
            mockedForumDal.Setup(fd => fd.GetForumThreadPostById(semiValidGuid1)).ReturnsAsync(new ForumThreadPostModel()
            {
                ForumUserGuid = validGuid, VisibleFlag = false, LockFlag = false, CreatedUTC = DateTime.UtcNow.AddMinutes((-1 * settingsData.TimeLimitForumPostEdit) - 1)
            });
            mockedForumDal.Setup(fd => fd.GetForumThreadPostById(semiValidGuid2)).ReturnsAsync(new ForumThreadPostModel()
            {
                ForumUserGuid = validGuid, VisibleFlag = true, LockFlag = true, CreatedUTC = DateTime.UtcNow.AddMinutes((-1 * settingsData.TimeLimitForumPostEdit) - 1)
            });
            mockedForumDal.Setup(ad => ad.GetForumThreadPostById(visibleGuid)).ReturnsAsync(new ForumThreadPostModel()
            {
                VisibleFlag = true
            });
            mockedForumDal.Setup(ad => ad.GetForumThreadPostById(hiddenGuid)).ReturnsAsync(new ForumThreadPostModel()
            {
                VisibleFlag = false
            });
            mockedForumDal.Setup(ad => ad.ListForumThreadPosts(null, null, null, null)).ReturnsAsync(new List <ForumThreadPostModel> {
                new ForumThreadPostModel()
                {
                    VisibleFlag = true
                },
                new ForumThreadPostModel()
                {
                    VisibleFlag = false
                }
            });
            mockedForumDal.Setup(fd => fd.InsertForumUser(forumUserData, false)).Returns(Task.Delay(0));
            mockedForumDal.Setup(fd => fd.UpdateForumUser(forumUserData)).Returns(Task.Delay(0));
            mockedForumDal.Setup(fd => fd.GetForumUserById(invalidGuid, null)).ReturnsAsync((ForumUserModel)null);
            mockedForumDal.Setup(fd => fd.GetForumUserById(validGuid, null)).ReturnsAsync(new ForumUserModel());

            forumService = new ForumService(mockedForumDal.Object, mockedSettingsProvider.Object);
        }
Exemple #21
0
 public ForumAllCategoryListViewViewModel()
 {
     _ds = new ForumService();
     GetData();
 }
Exemple #22
0
 public GommeTeamRoleCommands(IUnitOfWork uow, ForumService fs)
 {
     this.uow = uow;
     _fs      = fs;
 }
 public ForumController()
 {
     this.service = new ForumService();
 }
 public Verification(IUnitOfWork uow, IBotCredentials creds, CommandHandler ch, ForumService fs)
 {
     this.uow = uow;
     _creds   = creds;
     _ch      = ch;
     _fs      = fs;
 }
 public DefaultViewModel(ForumService forumService, OrderService orderService)
 {
     _orderService = orderService ?? throw new ArgumentNullException(nameof(orderService));
     _forumService = forumService ?? throw new ArgumentNullException(nameof(forumService));
 }
Exemple #26
0
 public VerificationsController(DbService db, ForumService forum)
 {
     _db    = db;
     _forum = forum;
 }
Exemple #27
0
 public ActionResult Index()
 {
     ViewBag.GroupList = ForumService.GroupList(true).Where(p => p.IsDeleted == false);
     return(View());
 }
Exemple #28
0
        public ActionResult PulishThread(ForumTopicInfo oldModel)
        {
            #region == 发表主题 ==
            if (CECRequest.GetFormString("event_submit_do_publish") == "anything")
            {
                //发布或编辑
                var forumInfo = ForumService.Get(oldModel.ForumId);
                //检查用户是否查看的权限
                //获取通过审核的用户,只有审核通过的用户才能查看论坛
                var userInfo = UserService.Get(User.Identity.Name);
                if (!CheckApplyUserAuth(userInfo.Id, forumInfo.GroupId))
                {
                    return(new TipView()
                    {
                        Msg = ErrorMsg.APPLYNOTPASS
                    });
                }

                ViewBag.ForumInfo = forumInfo;

                //在这里多设一个
                //下面更新问oldModel就会自动变成新的实体
                int requestTopicId = oldModel.Id;

                oldModel.PosterId = userInfo.Id;
                oldModel.Poster   = userInfo.UserName;
                if (string.IsNullOrEmpty(oldModel.Title))
                {
                    ModelState.AddModelError("Title", "帖子标题不能为空!");
                }
                if (string.IsNullOrEmpty(oldModel.Content))
                {
                    ModelState.AddModelError("Content", "帖子内容不能为空!");
                }
                if (ModelState.IsValid)
                {
                    oldModel = ForumTopicService.PostTopic(oldModel);
                    string url = String.Format("/thread/{0}.html", oldModel.Id);
                    return(new TipView()
                    {
                        Msg = string.Format("{0}成功!", requestTopicId > 0 ? "编辑" : "发表"), Url = url, Success = true
                    });
                }
            }
            #endregion

            #region == 删除主题 ==
            if (CECRequest.GetFormString("event_submit_do_delete") == "anything")
            {
                //删除主题
                int    forumId   = CECRequest.GetFormInt("catalogId", 0);
                int    topicId   = CECRequest.GetFormInt("threadId", 0);
                string returnUrl = string.Format("/catalog/{0}.html", forumId);

                var forumInfo = ForumService.Get(forumId);
                //检查用户是否查看的权限
                //获取通过审核的用户,只有审核通过的用户才能查看论坛
                var userInfo = UserService.Get(User.Identity.Name);
                if (!CheckApplyUserAuth(userInfo.Id, forumInfo.GroupId))
                {
                    return(new TipView()
                    {
                        Msg = ErrorMsg.APPLYNOTPASS
                    });
                }

                var topicInfo = ForumTopicService.Get(topicId);
                if (topicInfo.Id > 0 && topicInfo.ForumId == forumId && !topicInfo.IsDeleted)
                {
                    //执行删除操作
                    ForumTopicService.DeleteTopic(topicInfo);
                    return(new TipView()
                    {
                        Msg = ErrorMsg.DELETETHREADSUCCESS, Success = true, Url = returnUrl
                    });
                }
                return(new TipView()
                {
                    Msg = ErrorMsg.NOTNORMALOPERATE, Url = returnUrl
                });
            }
            #endregion

            return(View(oldModel));
        }
Exemple #29
0
 public DefaultViewModel(ForumService forumService)
 {
     this.forumService = forumService;
 }
Exemple #30
0
        public ActionResult ReplyThread(FormCollection fc)
        {
            int forumId = CECRequest.GetFormInt("catalogId", 0);
            int topicId = CECRequest.GetFormInt("threadId", 0);

            var forumInfo = ForumService.Get(forumId);
            //检查用户是否查看的权限
            //获取通过审核的用户,只有审核通过的用户才能查看论坛
            var userInfo = UserService.Get(User.Identity.Name);

            if (!CheckApplyUserAuth(userInfo.Id, forumInfo.GroupId))
            {
                return(new TipView()
                {
                    Msg = ErrorMsg.APPLYNOTPASS
                });
            }

            //判断主题是否存在
            var topicInfo = ForumTopicService.Get(topicId);

            string threadUrlFormat = "/thread/{0}.html{1}";

            if (topicInfo.Id == 0 || topicInfo.ForumId != forumId || topicInfo.IsDeleted)
            {
                return(new TipView()
                {
                    Msg = ErrorMsg.THREADNOTEXISTS
                });
            }

            #region == 发表回帖 ==
            //判断提交类型
            if (CECRequest.GetFormString("event_submit_do_publish") == "anything")
            {
                string replyContent = fc["txtReplyContent"];

                //判断回复内容是否为空
                if (string.IsNullOrEmpty(replyContent))
                {
                    return(new TipView()
                    {
                        Msg = "请输入回复内容", Url = String.Format(threadUrlFormat, topicInfo.Id, string.Empty)
                    });
                }


                //回复
                ForumReplyInfo replyInfo = new ForumReplyInfo();
                replyInfo.Content  = replyContent;
                replyInfo.ForumId  = topicInfo.ForumId;
                replyInfo.TopicId  = topicInfo.Id;
                replyInfo.Poster   = userInfo.UserName;
                replyInfo.PosterId = userInfo.Id;

                replyInfo = ForumTopicService.PostReply(topicInfo, replyInfo);

                return(new TipView()
                {
                    Msg = ErrorMsg.POSTREPLYSUCCESS, Url = String.Format(threadUrlFormat, topicInfo.Id, String.Format("#reply{0}", replyInfo.Id)), Success = true
                });
            }
            #endregion

            #region == 删除回帖 ==
            if (CECRequest.GetFormString("event_submit_do_delete") == "anything")
            {
                int replyId = CECRequest.GetFormInt("replyId", 0);

                var replyInfo = ForumTopicService.GetReplyInfo(replyId);
                if (replyInfo.Id == 0 || replyInfo.IsDeleted || topicInfo.Id != replyInfo.TopicId || replyInfo.ForumId != forumId)
                {
                    return(new TipView()
                    {
                        Msg = ErrorMsg.NOTNORMALOPERATE, Url = String.Format(threadUrlFormat, topicInfo.Id, string.Empty)
                    });
                }

                ForumTopicService.DeleteReply(replyInfo);
                return(new TipView()
                {
                    Msg = ErrorMsg.DELETEREPLYSUCCESS, Url = String.Format(threadUrlFormat, topicInfo.Id, string.Empty), Success = true
                });
            }
            #endregion

            return(new TipView()
            {
                Msg = ErrorMsg.NOTNORMALOPERATE, Url = String.Format(threadUrlFormat, topicInfo.Id, string.Empty)
            });
        }
 public InfoCommands(DiscordSocketClient client, IStatsService stats, DbService db, ForumService fs)
 {
     _client = client;
     _stats  = stats;
     _db     = db;
     _fs     = fs;
 }
Exemple #32
0
 public ForumController(ForumService service, CoreIdentity.UserManager <User> userManager)
 {
     this.service     = service;
     this.userManager = userManager;
 }
 protected ForumControllerBase()
 {
     TopicService = new TopicService(DatabaseContext);
     CommentService = new CommentService(DatabaseContext, TopicService);
     ForumService = new ForumService(DatabaseContext);
 }