public IActionResult Create([Bind("Id,Name")] Forum forum) { if (ModelState.IsValid) { _forumRep.Create(forum); return(RedirectToAction(nameof(Index))); } return(View(forum)); }
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(); }
protected override void ExecuteWorkImplementation() { foreach (var bookType in BookTypeHelper.GetBookTypeEnumsWithCategories()) { var category = m_categoryRepository.GetCategoryByExternalId((short)bookType); Forum parentForum = null; if (m_category.ParentCategoryId != null) { parentForum = m_forumRepository.GetForumByExternalCategoryIdAndCategory((int)m_category.ParentCategoryId, category.CategoryID); } var forum = new Forum(m_category.Description, category, (short)ForumTypeEnum.SubCategory) { ExternalId = m_category.Id, ParentForum = parentForum }; m_forumRepository.Create(forum); m_forumAccessSubwork.SetAdminAccessToForumForAdminGroup(forum); } }
protected override void ExecuteWorkImplementation() { IList <int> newCategories = m_categoryIds.Except(m_oldCategoryIds).ToList(); IList <int> deletedCategories = m_oldCategoryIds.Except(m_categoryIds).ToList(); var mainForum = m_forumRepository.GetMainForumByExternalProjectId(m_projectId); if (mainForum == null) { return; } var forumCategoriesToDelete = m_forumRepository.GetForumsByExternalCategoryIds(deletedCategories); var forums = m_forumRepository.GetForumsByExternalProjectId(m_projectId); foreach (var forum in forums) { if (forumCategoriesToDelete.Contains(forum.ParentForum)) { var forumAccesses = m_forumRepository.GetAllAccessesForForum(forum.ForumID); m_forumRepository.DeleteAll(forumAccesses); m_forumRepository.Delete(forum); } } var forumsToCreate = m_forumRepository.GetForumsByExternalCategoryIds(newCategories); foreach (var forum in forumsToCreate) { var tempForum = new Forum(mainForum.Name, forum.Category, (short)ForumTypeEnum.Forum) { ExternalProjectId = m_projectId, ParentForum = forum, RemoteURL = m_forumSiteUrlHelper.GetTopicsUrl(mainForum.ForumID) }; m_forumRepository.Create(tempForum); m_forumAccessSubwork.SetAdminAccessToForumForAdminGroup(tempForum); } }
public void PostMessageInTopic(Topic topic, User user, string messageText) { var message = new Message(topic, user, DateTime.UtcNow, messageText); m_forumRepository.Create(message); topic.LastMessage = message; topic.LastUser = message.User; topic.LastPosted = message.Posted; topic.LastMessageFlags = message.Flags; topic.LastUserDisplayName = message.UserDisplayName; topic.NumPosts++; m_forumRepository.Update(topic); Forum forum = message.Topic.Forum; forum.LastPosted = topic.Posted; forum.LastTopic = topic; forum.LastUser = topic.User; forum.LastUserDisplayName = topic.UserDisplayName; forum.LastMessage = topic.LastMessage; forum.NumPosts++; m_forumRepository.Update(forum); }