Beispiel #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());
        }
        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);
        }
Beispiel #3
0
        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);
        }
Beispiel #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());
        }
Beispiel #5
0
        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);
        }
 public void SavePost(Post post)
 {
     if (post != null)
     {
         postRepository.Update(post);
     }
 }
 public void RemovePost(Post post)
 {
     if (post != null)
     {
         postRepository.Delete(post);
     }
 }
        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;
        }