コード例 #1
0
        async Task <OneOf <Success, Banned, ImageCountExceeded, PostCountExceeded> > IPostService.Add(Guid postId, Guid threadId, TripCodedName name, string comment, bool isSage, IIpHash ipAddress, Option <File> file, CancellationToken cancellationToken)
        {
            if (await this.bannedIpRepository.IsBanned(ipAddress, cancellationToken))
            {
                return(new Banned());
            }

            if (ImageLimit <= await this.fileRepository.GetImageCount(threadId, cancellationToken))
            {
                return(new ImageCountExceeded());
            }

            if (PostLimit <= await this.postRepository.GetThreadPostCount(threadId, cancellationToken))
            {
                return(new PostCountExceeded());
            }

            var post = new Domain.Post(postId, threadId, DateTime.UtcNow, name.Val, comment, isSage, ipAddress.Val);

            await this.postRepository.Add(post).ConfigureAwait(false);

            await file.MapToTask(some => this.fileRepository.Add(some));

            return(new Success());
        }
コード例 #2
0
        public void CommentOnPost(Post post, string commentAuthor, string commentText)
        {
            var comment = new Comment {Author = commentAuthor, Text = commentText, PostedDate = DateTime.Now};
            post.AddComment(comment);

            commentRepository.Create(comment);
            postRepository.Update(post);

            postLogger.LogMessage("Created comment from '{0}' on post '{1}'",
                                  comment.Author, post.Title);
        }
コード例 #3
0
ファイル: PostService.cs プロジェクト: Andrei243/SocializR
        public bool AddPost(Domain.Post post)
        {
            var isBanned = unitOfWork.Users.Query.FirstOrDefault(e => e.Id == CurrentUser.Id)?.IsBanned ?? false;

            if (isBanned)
            {
                return(false);
            }

            post.AddingMoment    = DateTime.Now;
            post.UserId          = CurrentUser.Id;
            post.Confidentiality = post.Confidentiality ?? Confidentiality.FriendsOnly;
            unitOfWork.Posts.Add(post);
            return(unitOfWork.SaveChanges() != 0);
        }
コード例 #4
0
        async Task <OneOf <Success, Banned> > IPostService.AddThread(Guid postId, Guid threadId, Guid boardId, string subject, TripCodedName name, string comment, bool isSage, IIpHash ipAddress, Option <File> file, CancellationToken cancellationToken)
        {
            if (await this.bannedIpRepository.IsBanned(ipAddress, cancellationToken))
            {
                return(new Banned());
            }

            var thread = new Thread(threadId, boardId, subject);
            await threadRepository.Add(thread).ConfigureAwait(false);

            var post = new Domain.Post(postId, threadId, DateTime.UtcNow, name.Val, comment, isSage, ipAddress.Val);

            await this.postRepository.Add(post).ConfigureAwait(false);

            await file.MapToTask(some => this.fileRepository.Add(some));

            return(new Success());
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: jglozano/presentations
        private static void CreatePost(string title)
        {
            var postRepository = new PostRepository();
            var categoryRepository = new CategoryRepository();
            var commentRepository = new CommentRepository();

            var post = new Post
                           {
                               Title = title,
                               PostedDate = DateTime.Now,
                               Contents = "This is just a simple test post..."
                           };

            for (int i = 0; i < 10; i++)
            {
                var category = new Category
                                   {
                                       Name = "Category " + i,
                                       CreatedDate = DateTime.Now,
                                       Description = "Just a test..."
                                   };

                post.AddCategory(category);
                categoryRepository.Create(category);
            }

            for (int i = 0; i < 20; i++)
            {
                var comment = new Comment
                                  {
                                      PostedDate = DateTime.Now,
                                      Author = "Author " + i,
                                      Text = "testing..."
                                  };

                post.AddComment(comment);
                commentRepository.Create(comment);
            }

            postRepository.Create(post);
        }
コード例 #6
0
 public void SavePost(Post post)
 {
     if (post != null)
     {
         postRepository.Update(post);
     }
 }
コード例 #7
0
 public void RemovePost(Post post)
 {
     if (post != null)
     {
         postRepository.Delete(post);
     }
 }
コード例 #8
0
        public Post NewPost(string title, string contents, DateTime postDate, Category[] categories)
        {
            var post = new Post {Title = title, Contents = contents, PostedDate = postDate};

            if (categories != null)
            {
                foreach (Category category in categories)
                {
                    post.AddCategory(category);
                }
            }

            postRepository.Create(post);

            postLogger.LogMessage("Created post '{0}'", post.Title);

            return post;
        }