• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# DomainModel.Topic类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中MVCForum.Domain.DomainModel.Topic的典型用法代码示例。如果您正苦于以下问题:C# Topic类的具体用法?C# Topic怎么用?C# Topic使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Topic类属于MVCForum.Domain.DomainModel命名空间,在下文中一共展示了Topic类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Delete_Post_Removed_From_TopicList_And_Last_Post

        public void Delete_Post_Removed_From_TopicList_And_Last_Post()
        {
            var postRepository = Substitute.For<IPostRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var roleService = Substitute.For<IRoleService>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();
            var localisationService = Substitute.For<ILocalizationService>();
            var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);
            
            // Create topic
            var topic = new Topic { Name = "Captain America"};

            // Create some posts with one to delete
            var postToDelete = new Post { Id = Guid.NewGuid(), Topic = topic, IsTopicStarter = false, DateCreated = DateTime.UtcNow};
            var postToStay = new Post { Id = Guid.NewGuid(), Topic = topic, IsTopicStarter = false, DateCreated = DateTime.UtcNow.Subtract(TimeSpan.FromDays(2)) };
            var postToStayTwo = new Post { Id = Guid.NewGuid(), Topic = topic, IsTopicStarter = false, DateCreated = DateTime.UtcNow.Subtract(TimeSpan.FromDays(3)) };

            // set last post
            topic.LastPost = postToDelete;

            // Set the post list to the topic
            var posts = new List<Post> {postToDelete, postToStay, postToStayTwo};
            topic.Posts = posts;

            // Save
            postService.Delete(postToDelete);

            // Test that settings is no longer in cache
            Assert.IsTrue(topic.LastPost == postToStay);
            Assert.IsTrue(topic.Posts.Count == 2);         
        }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:32,代码来源:PostServiceTests.cs


示例2: IsSpam

        /// <summary>
        /// Check whether a topic is spam or not
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public bool IsSpam(Topic topic)
        {
            // If akisment is is not enable always return false
            if (_settingsService.GetSettings().EnableAkisment == null || _settingsService.GetSettings().EnableAkisment == false) return false;

            // Akisment must be enabled
            var firstOrDefault = topic.Posts.FirstOrDefault(x => x.IsTopicStarter);
            if (firstOrDefault != null)
            {
                var comment = new Comment
                {
                    blog = StringUtils.CheckLinkHasHttp(_settingsService.GetSettings().ForumUrl),
                    comment_type = "comment",
                    comment_author = topic.User.UserName,
                    comment_author_email = topic.User.Email,
                    comment_content = firstOrDefault.PostContent,
                    permalink = String.Empty,
                    referrer = HttpContext.Current.Request.ServerVariables["HTTP_REFERER"],
                    user_agent = HttpContext.Current.Request.ServerVariables["HTTP_USER_AGENT"],
                    user_ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]
                };
                var validator = new Validator(_settingsService.GetSettings().AkismentKey);
                return validator.IsSpam(comment);
            }
            return true;
        }
开发者ID:dragon6776,项目名称:mvcforumdemo,代码行数:31,代码来源:AkismetHelper.cs


示例3: GetByTopic

 public IList<TopicNotification> GetByTopic(Topic topic)
 {
     return _context.TopicNotification
         .Where(x => x.Topic.Id == topic.Id)
         .AsNoTracking()
         .ToList();
 }
开发者ID:huchao007,项目名称:mvcforum,代码行数:7,代码来源:TopicNotificationRepository.cs


示例4: Delete_Topic_Deleted_If_Topic_Starter

        public void Delete_Topic_Deleted_If_Topic_Starter()
        {
            var postRepository = Substitute.For<IPostRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var roleService = Substitute.For<IRoleService>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();
            var localisationService = Substitute.For<ILocalizationService>();
            var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);

            var tags = new List<TopicTag>
                           {
                               new TopicTag{Tag = "Thor"},
                               new TopicTag{Tag = "Gambit"}
                           };
            var topic = new Topic { Name = "Captain America", Tags = tags };
            var post = new Post { Id = Guid.NewGuid(), Topic = topic, IsTopicStarter = true};
            topic.LastPost = post;
            topic.Posts = new List<Post>();
            post.IsTopicStarter = true;
            topic.Posts.Add(post);

            // Save
            var deleteTopic = postService.Delete(post);

            Assert.IsTrue(deleteTopic);
        }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:27,代码来源:PostServiceTests.cs


示例5: AddPost

        public void AddPost()
        {
            var postRepository = Substitute.For<IPostRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var roleService = Substitute.For<IRoleService>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();
            settingsService.GetSettings().Returns(new Settings { PointsAddedPerPost = 20 });
            var localisationService = Substitute.For<ILocalizationService>();
            var postService = new PostService(membershipUserPointsService, settingsService, roleService, postRepository, topicRepository, localisationService, _api);

            var category = new Category();
            var role = new MembershipRole{RoleName = "TestRole"};

            var categoryPermissionForRoleSet = new List<CategoryPermissionForRole>
                                                   {
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionEditPosts }, IsTicked = true},
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionDenyAccess }, IsTicked = false},
                                                       new CategoryPermissionForRole { Permission = new Permission { Name = AppConstants.PermissionReadOnly  }, IsTicked = false}
                                                   };

            var permissionSet = new PermissionSet(categoryPermissionForRoleSet);
            roleService.GetPermissions(category, role).Returns(permissionSet);

            var topic = new Topic { Name = "Captain America", Category = category};
            var user = new MembershipUser {
                UserName = "SpongeBob",
                Roles = new List<MembershipRole>{role}
            };

            var newPost = postService.AddNewPost("A test post", topic, user, out permissionSet);

            Assert.AreEqual(newPost.User, user);
            Assert.AreEqual(newPost.Topic, topic);
        }
开发者ID:kangjh0815,项目名称:test,代码行数:35,代码来源:PostServiceTests.cs


示例6: AddNewPost

        /// <summary>
        /// Add a new post
        /// </summary>
        /// <param name="postContent"> </param>
        /// <param name="topic"> </param>
        /// <param name="user"></param>
        /// <param name="permissions"> </param>
        /// <returns>True if post added</returns>
        public Post AddNewPost(string postContent, Topic topic, MembershipUser user, out PermissionSet permissions)
        {
            // Get the permissions for the category that this topic is in
            permissions = _roleService.GetPermissions(topic.Category, UsersRole(user));

            // Check this users role has permission to create a post
            if (permissions[AppConstants.PermissionDenyAccess].IsTicked || permissions[AppConstants.PermissionReadOnly].IsTicked)
            {
                // Throw exception so Ajax caller picks it up
                throw new ApplicationException(_localizationService.GetResourceString("Errors.NoPermission"));
            }

            // Has permission so create the post
            var newPost = new Post
                               {
                                   PostContent = postContent,
                                   User = user,
                                   Topic = topic,
                                   IpAddress = StringUtils.GetUsersIpAddress(),
                                   DateCreated = DateTime.UtcNow,
                                   DateEdited = DateTime.UtcNow
                               };

            // Sort the search field out

            var category = topic.Category;
            if (category.ModeratePosts == true)
            {
                newPost.Pending = true;
            }

            var e = new PostMadeEventArgs { Post = newPost };
            EventManager.Instance.FireBeforePostMade(this, e);

            if (!e.Cancel)
            {
                // create the post
                Add(newPost);

                // Update the users points score and post count for posting
                _membershipUserPointsService.Add(new MembershipUserPoints
                                                     {
                                                         Points = _settingsService.GetSettings().PointsAddedPerPost,
                                                         User = user,
                                                         PointsFor = PointsFor.Post,
                                                         PointsForId = newPost.Id
                                                     });

                // add the last post to the topic
                topic.LastPost = newPost;

                EventManager.Instance.FireAfterPostMade(this, new PostMadeEventArgs { Post = newPost });

                return newPost;
            }

            return newPost;
        }
开发者ID:VerdantAutomation,项目名称:mvcforum,代码行数:66,代码来源:PostService.cs


示例7: Update

 public void Update(Topic item)
 {
     // Check there's not an object with same identifier already in context
     if (_context.Topic.Local.Select(x => x.Id == item.Id).Any())
     {
         throw new ApplicationException("Object already exists in context - you do not need to call Update. Save occurs on Commit");
     }
     _context.Entry(item).State = EntityState.Modified;
 }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:9,代码来源:TopicRepository.cs


示例8: GetByUserAndTopic

 public IList<TopicNotification> GetByUserAndTopic(MembershipUser user, Topic topic, bool addTracking = false)
 {
     var notifications = _context.TopicNotification
         .Where(x => x.User.Id == user.Id && x.Topic.Id == topic.Id);
     if (addTracking)
     {
         return notifications.ToList();
     }
     return notifications.AsNoTracking().ToList();
 }
开发者ID:huchao007,项目名称:mvcforum,代码行数:10,代码来源:TopicNotificationRepository.cs


示例9: Add

        /// <summary>
        /// Create a new topic and also the topic starter post
        /// </summary>
        /// <param name="topic"></param>
        /// <returns></returns>
        public Topic Add(Topic topic)
        {
            topic = SanitizeTopic(topic);

            topic.CreateDate = DateTime.UtcNow;

            // url slug generator
            topic.Slug = ServiceHelpers.GenerateSlug(topic.Name, _topicRepository.GetTopicBySlugLike(ServiceHelpers.CreateUrl(topic.Name)), null);

            return _topicRepository.Add(topic);
        }
开发者ID:R3MUSDevPack,项目名称:Forums,代码行数:16,代码来源:TopicService.cs


示例10: AddNewPost

        /// <summary>
        /// Add a new post
        /// </summary>
        /// <param name="postContent"> </param>
        /// <param name="topic"> </param>
        /// <param name="user"></param>
        /// <param name="permissions"> </param>
        /// <returns>True if post added</returns>
        public Post AddNewPost(string postContent, Topic topic, MembershipUser user, out PermissionSet permissions)
        {
            // Get the permissions for the category that this topic is in
            permissions = _roleService.GetPermissions(topic.Category, UsersRole(user));

            // Check this users role has permission to create a post
            if (permissions[AppConstants.PermissionDenyAccess].IsTicked || permissions[AppConstants.PermissionReadOnly].IsTicked)
            {
                // Throw exception so Ajax caller picks it up
                throw new ApplicationException(_localizationService.GetResourceString("Errors.NoPermission"));
            }

            // Has permission so create the post
            var newPost = new Post
                               {
                                   PostContent = postContent,
                                   User = user,
                                   Topic = topic,
                                   IpAddress = StringUtils.GetUsersIpAddress()
                               };

            newPost = SanitizePost(newPost);

            var e = new PostMadeEventArgs { Post = newPost, Api = _api };
            EventManager.Instance.FireBeforePostMade(this, e);

            if (!e.Cancel)
            {
                // create the post
                Add(newPost);

                // Update the users points score and post count for posting
                _membershipUserPointsService.Add(new MembershipUserPoints
                                                     {
                                                         Points = _settingsService.GetSettings().PointsAddedPerPost,
                                                         User = user
                                                     });

                // add the last post to the topic
                topic.LastPost = newPost;

                // Removed as its updated via the commit
                //_topicRepository.Update(topic);

                EventManager.Instance.FireAfterPostMade(this, new PostMadeEventArgs { Post = newPost, Api = _api });

                return newPost;
            }

            return newPost;
        }
开发者ID:kangjh0815,项目名称:test,代码行数:59,代码来源:PostService.cs


示例11: CreatePostViewModels

 /// <summary>
 /// Maps the posts for a specific topic
 /// </summary>
 /// <param name="posts"></param>
 /// <param name="votes"></param>
 /// <param name="permission"></param>
 /// <param name="topic"></param>
 /// <param name="loggedOnUser"></param>
 /// <param name="settings"></param>
 /// <param name="favourites"></param>
 /// <returns></returns>
 public static List<PostViewModel> CreatePostViewModels(IEnumerable<Post> posts, List<Vote> votes, PermissionSet permission, Topic topic, MembershipUser loggedOnUser, Settings settings, List<Favourite> favourites)
 {
     var viewModels = new List<PostViewModel>();
     var groupedVotes = votes.ToLookup(x => x.Post.Id);
     var groupedFavourites = favourites.ToLookup(x => x.Post.Id);
     foreach (var post in posts)
     {
         var id = post.Id;
         var postVotes = (groupedVotes.Contains(id) ? groupedVotes[id].ToList() : new List<Vote>());
         var postFavs = (groupedFavourites.Contains(id) ? groupedFavourites[id].ToList() : new List<Favourite>());
         viewModels.Add(CreatePostViewModel(post, postVotes, permission, topic, loggedOnUser, settings, postFavs));
     }
     return viewModels;
 }
开发者ID:petemidge,项目名称:mvcforum,代码行数:25,代码来源:ViewModelMapping.cs


示例12: Add

        /// <summary>
        /// Add new tags to a topic, ignore existing ones
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="topic"></param>
        public void Add(string tags, Topic topic)
        {
            if(!string.IsNullOrEmpty(tags))
            {
                tags = StringUtils.SafePlainText(tags);

                var splitTags = tags.Replace(" ", "").Split(',');

                if(topic.Tags == null)
                {
                    topic.Tags = new List<TopicTag>();
                }

                var newTagNames = splitTags.Select(tag => tag);
                var newTags = new List<TopicTag>();
                var existingTags = new List<TopicTag>();

                foreach (var newTag in newTagNames.Distinct())
                {
                    var tag = _tagRepository.GetTagName(newTag);
                    if (tag != null)
                    {
                        // Exists
                        existingTags.Add(tag);
                    }
                    else
                    {
                        // Doesn't exists
                        var nTag = new TopicTag
                            {
                                Tag = newTag,
                                Slug = ServiceHelpers.CreateUrl(newTag)
                            };

                        _tagRepository.Add(nTag);
                        newTags.Add(nTag);
                    }
                }

                newTags.AddRange(existingTags);
                topic.Tags = newTags;

                // Fire the tag badge check
                _badgeService.ProcessBadge(BadgeType.Tag, topic.User);
            }
        }
开发者ID:petemidge,项目名称:mvcforum,代码行数:51,代码来源:TopicTagService.cs


示例13: GetTopicBreadcrumb

 public PartialViewResult GetTopicBreadcrumb(Topic topic)
 {
     var category = topic.Category;
     using (UnitOfWorkManager.NewUnitOfWork())
     {
         var viewModel = new BreadcrumbViewModel
         {
             Categories = _categoryService.GetCategoryParents(category).ToList(),
             Topic = topic
         };
         if (!viewModel.Categories.Any())
         {
             viewModel.Categories.Add(topic.Category);
         }
         return PartialView("GetCategoryBreadcrumb", viewModel);
     }
 }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:17,代码来源:TopicController.cs


示例14: Add_Test

        public void Add_Test()
        {
            const string tag = "testtag";
            var tagRepository = Substitute.For<ITopicTagRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var topicTagService = new TopicTagService(tagRepository, topicRepository);

            tagRepository.GetTagName(tag).Returns(x => null);

            var topic = new Topic();

            topicTagService.Add(tag, topic);

            Assert.IsTrue(topic.Tags.Count() == 1);
            Assert.IsTrue(topic.Tags[0].Tag == tag);
            tagRepository.Received().Add(Arg.Is<TopicTag>(x => x.Tag == tag));
        }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:17,代码来源:TopicTagServiceTests.cs


示例15: Add_Test_With_No_Existing_Tags

        public void Add_Test_With_No_Existing_Tags()
        {
            const string testtag = "testtag";
            const string testtagtwo = "testtagtwo";
            const string andthree = "andthree";
            var tagRepository = Substitute.For<ITopicTagRepository>();
            var topicRepository = Substitute.For<ITopicRepository>();
            var topicTagService = new TopicTagService(tagRepository, topicRepository);

            tagRepository.GetTagName(testtag).Returns(x => new TopicTag { Tag = testtag });
            tagRepository.GetTagName(testtagtwo).Returns(x => new TopicTag { Tag = testtagtwo });
            tagRepository.GetTagName(andthree).Returns(x => new TopicTag { Tag = andthree });

            var topic = new Topic();

            topicTagService.Add(string.Concat(testtag, " , ", testtagtwo, " , ", andthree), topic);

            Assert.IsTrue(topic.Tags.Count() == 3);
            tagRepository.DidNotReceive().Add(Arg.Is<TopicTag>(x => x.Tag == testtag));
            tagRepository.DidNotReceive().Add(Arg.Is<TopicTag>(x => x.Tag == testtagtwo));
            tagRepository.DidNotReceive().Add(Arg.Is<TopicTag>(x => x.Tag == andthree));
        }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:22,代码来源:TopicTagServiceTests.cs


示例16: AddLastPost

        /// <summary>
        /// Add a last post to a topic. Must be part of a separate database update
        /// in EF because of circular dependencies. So save the topic before calling this.
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="postContent"></param>
        /// <returns></returns>
        public Post AddLastPost(Topic topic, string postContent)
        {
            topic = SanitizeTopic(topic);

            // Create the post
            var post = new Post
            {
                DateCreated = DateTime.UtcNow,
                IsTopicStarter = true,
                DateEdited = DateTime.UtcNow,
                PostContent = StringUtils.GetSafeHtml(postContent),
                User = topic.User,
                Topic = topic
            };

            // Add the post
            _postRepository.Add(post);

            topic.LastPost = post;

            return post;
        }
开发者ID:R3MUSDevPack,项目名称:Forums,代码行数:29,代码来源:TopicService.cs


示例17: Delete_Check_Tags_Are_Cleared

        public void Delete_Check_Tags_Are_Cleared()
        {
            var topicRepository = Substitute.For<ITopicRepository>();
            var postRepository = Substitute.For<IPostRepository>();
            var membershipUserPointsService = Substitute.For<IMembershipUserPointsService>();
            var settingsService = Substitute.For<ISettingsService>();

            var topicService = new TopicService(membershipUserPointsService, settingsService, topicRepository, postRepository, _api, _topicNotificationService);

            var topic = new Topic 
                { 
                    Name = "something",
                    Tags = new List<TopicTag>
                               {
                                   new TopicTag{Tag = "tagone"},
                                   new TopicTag{Tag = "tagtwo"}
                               }
                };          

            topicService.Delete(topic);

            Assert.IsTrue(!topic.Tags.Any());
        }
开发者ID:StefanoPireddu,项目名称:mvcforum,代码行数:23,代码来源:TopicServiceTests.cs


示例18: CreatePostViewModel

        public static PostViewModel CreatePostViewModel(Post post, List<Vote> votes, PermissionSet permission, Topic topic, MembershipUser loggedOnUser, Settings settings, List<Favourite> favourites)
        {
            var allowedToVote = (loggedOnUser != null && loggedOnUser.Id != post.User.Id &&
                                 loggedOnUser.TotalPoints > settings.PointsAllowedToVoteAmount &&
                                 votes.All(x => x.User.Id != loggedOnUser.Id));

            var hasFavourited = false;
            if (loggedOnUser != null && loggedOnUser.Id != post.User.Id)
            {
                hasFavourited = favourites.Any(x => x.Member.Id == loggedOnUser.Id);
            }

            return new PostViewModel
            {
                Permissions = permission,
                Votes = votes,
                Post = post,
                ParentTopic = topic,
                AllowedToVote = allowedToVote,
                MemberHasFavourited = hasFavourited,
                Favourites = favourites,
                PermaLink = string.Concat(topic.NiceUrl, "?", AppConstants.PostOrderBy, "=", AppConstants.AllPosts, "#comment-", post.Id)
            };
        }
开发者ID:Xamarui,项目名称:mvcforum,代码行数:24,代码来源:ViewModelMapping.cs


示例19: CreatePostViewModel

        public static PostViewModel CreatePostViewModel(Post post, List<Vote> votes, PermissionSet permission, Topic topic, MembershipUser loggedOnUser, Settings settings, List<Favourite> favourites)
        {
            var allowedToVote = (loggedOnUser != null && loggedOnUser.Id != post.User.Id &&
                                 loggedOnUser.TotalPoints >= settings.PointsAllowedToVoteAmount);

            // Remove votes where no VotedBy has been recorded
            votes.RemoveAll(x => x.VotedByMembershipUser == null);

            var hasVotedUp = false;
            var hasVotedDown = false;
            var hasFavourited = false;
            if (loggedOnUser != null && loggedOnUser.Id != post.User.Id)
            {
                hasFavourited = favourites.Any(x => x.Member.Id == loggedOnUser.Id);
                hasVotedUp = votes.Count(x => x.Amount > 0 && x.VotedByMembershipUser.Id == loggedOnUser.Id) > 0;
                hasVotedDown = votes.Count(x => x.Amount < 0 && x.VotedByMembershipUser.Id == loggedOnUser.Id) > 0;
            }

            // Check for online status
            var date = DateTime.UtcNow.AddMinutes(-AppConstants.TimeSpanInMinutesToShowMembers);

            return new PostViewModel
            {
                Permissions = permission,
                Votes = votes,
                Post = post,
                ParentTopic = topic,
                AllowedToVote = allowedToVote,
                MemberHasFavourited = hasFavourited,
                Favourites = favourites,
                PermaLink = string.Concat(topic.NiceUrl, "?", AppConstants.PostOrderBy, "=", AppConstants.AllPosts, "#comment-", post.Id),
                MemberIsOnline = post.User.LastActivityDate > date,
                HasVotedDown = hasVotedDown,
                HasVotedUp = hasVotedUp
            };
        }
开发者ID:petemidge,项目名称:mvcforum,代码行数:36,代码来源:ViewModelMapping.cs


示例20: MovePost

        public ActionResult MovePost(MovePostViewModel viewModel)
        {

            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
            {
                // Firstly check if this is a post and they are allowed to move it
                var post = _postService.Get(viewModel.PostId);
                if (post == null)
                {
                    return ErrorToHomePage(LocalizationService.GetResourceString("Errors.GenericMessage"));
                }

                var permissions = RoleService.GetPermissions(post.Topic.Category, UsersRole);
                var allowedCategories = _categoryService.GetAllowedCategories(UsersRole);

                // Does the user have permission to this posts category
                var cat = allowedCategories.FirstOrDefault(x => x.Id == post.Topic.Category.Id);
                if (cat == null)
                {
                    return ErrorToHomePage(LocalizationService.GetResourceString("Errors.NoPermission"));
                }

                // Does this user have permission to move
                if (!permissions[SiteConstants.Instance.PermissionEditPosts].IsTicked)
                {
                    return NoPermission(post.Topic);
                }

                var previousTopic = post.Topic;
                var category = post.Topic.Category;
                var postCreator = post.User;

                Topic topic;
                var cancelledByEvent = false;
                // If the dropdown has a value, then we choose that first
                if (viewModel.TopicId != null)
                {
                    // Get the selected topic
                    topic = _topicService.Get((Guid) viewModel.TopicId);
                }
                else if(!string.IsNullOrEmpty(viewModel.TopicTitle))
                {
                    // We get the banned words here and pass them in, so its just one call
                    // instead of calling it several times and each call getting all the words back
                    var bannedWordsList = _bannedWordService.GetAll();
                    List<string> bannedWords = null;
                    if (bannedWordsList.Any())
                    {
                        bannedWords = bannedWordsList.Select(x => x.Word).ToList();
                    }

                    // Create the topic
                    topic = new Topic
                    {
                        Name = _bannedWordService.SanitiseBannedWords(viewModel.TopicTitle, bannedWords),
                        Category = category,
                        User = postCreator
                    };

                    // Create the topic
                    topic = _topicService.Add(topic);

                    // Save the changes
                    unitOfWork.SaveChanges();

                    // Set the post to be a topic starter
                    post.IsTopicStarter = true;

                    // Check the Events
                    var e = new TopicMadeEventArgs { Topic = topic };
                    EventManager.Instance.FireBeforeTopicMade(this, e);
                    if (e.Cancel)
                    {
                        cancelledByEvent = true;
                        ShowMessage(new GenericMessageViewModel
                        {
                            MessageType = GenericMessages.warning, Message = LocalizationService.GetResourceString("Errors.GenericMessage")
                        });
                    }                    
                }
                else
                {
                    // No selected topic OR topic title, just redirect back to the topic
                    return Redirect(post.Topic.NiceUrl);
                }

                // If this create was cancelled by an event then don't continue
                if (!cancelledByEvent)
                {
                    // Now update the post to the new topic
                    post.Topic = topic;

                    // Also move any posts, which were in reply to this post
                    if (viewModel.MoveReplyToPosts)
                    {
                        var relatedPosts = _postService.GetReplyToPosts(viewModel.PostId);
                        foreach (var relatedPost in relatedPosts)
                        {
                            relatedPost.Topic = topic;
                        }
//.........这里部分代码省略.........
开发者ID:ivanchen52,项目名称:mvcforum,代码行数:101,代码来源:PostController.cs



注:本文中的MVCForum.Domain.DomainModel.Topic类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# MWControlSuite.MWCancelEventArgs类代码示例发布时间:2022-05-26
下一篇:
C# DomainModel.MembershipUser类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap