当前位置: 首页>>代码示例>>C#>>正文


C# DomainModel.Topic类代码示例

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


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


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