示例#1
0
        public async Task <IdResource> Handle(CreatePostCommand command, CancellationToken ct)
        {
            var post = _mapper.Map <Post>(command);

            post.SetInitialTimestamps();

            var postId = await _postsRepository.Create(post, ct);

            return(new IdResource(postId));
        }
        public async Task <IActionResult> Create(Posts posts)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var isCreated = await postsRepository.Create(posts);

            return(Ok(new { isCreated }));
        }
示例#3
0
 public void Create(int parentId, string title, string content, string authorId, bool isPublished)
 {
     _postsRepository.Create(new Post()
     {
         AuthorId    = authorId,
         IsPublished = isPublished,
         ModifiedAt  = null,
         ParentId    = parentId,
         PublishedAt = null,
         Title       = title,
         CreatedAt   = DateTime.Now,
         Content     = content
     });
 }
        public async Task <IActionResult> AddPost([FromBody] NewPostDto newPostDto)
        {
            var post = _mapper.Map <Posts>(newPostDto);

            post.CreatedDate = DateTime.UtcNow;
            await _iPostsRepository.Create(post);

            if (await _iPostsRepository.SaveAll())
            {
                return(Ok(_mapper.Map <NewPostDto>(post)));
            }

            throw new Exception("Error adding the category");
        }
示例#5
0
        public NewPostAndSuggestions GetSuggestionsAfterAccept(string threadId, ThreadPost acceptedPost, string askingUser)
        {
            if (!hasAccessToThread(threadId, askingUser))
            {
                throw new Exception("You have no access to this thread!");
            }


            var thread = threadRepository.Find(threadId);
            var dbId   = ObjectId.GenerateNewId().ToString();

            thread.ThreadPosts.Add(dbId);
            threadRepository.Update(thread);

            var storedThreadPosts        = postsRepository.Querry(p => thread.ThreadPosts.Contains(p.Id)).ToList();
            var acceptedStoredThreadPost = new StoredThreadPost
            {
                Id             = dbId,
                ThreadId       = threadId,
                PostId         = acceptedPost.Id,
                ConnectedPosts = acceptedPost.ConnectedPosts,
                ThreadIndex    = storedThreadPosts.Count() > 0 ? storedThreadPosts.MaxBy(sTP => sTP.ThreadIndex).First().ThreadIndex + 1 : 0
            };

            storedThreadPosts.Add(acceptedStoredThreadPost);
            postsRepository.Create(acceptedStoredThreadPost);

            var recommendedQuestions = elasticSuggestionHelper.GetRecommendedQuestions(storedThreadPosts.OrderByDescending(sTP => sTP.ThreadIndex)
                                                                                       .Select(sTP => sTP.PostId)
                                                                                       .ToList(),
                                                                                       thread.LastSearched,
                                                                                       thread.TagList.ToList());
            var threadQuestions = questionsElasticRepository.GetAllByIds(storedThreadPosts.Select(sTP => sTP.PostId)
                                                                         .Concat(recommendedQuestions.Select(recQ => recQ.Id))
                                                                         .ToList());

            return(new NewPostAndSuggestions
            {
                NewPost = new ThreadPost
                {
                    Id = acceptedStoredThreadPost.Id,
                    ThreadIndex = acceptedStoredThreadPost.ThreadIndex,
                    Title = acceptedPost.Title,
                    Body = acceptedPost.Body,
                    ConnectedPosts = acceptedStoredThreadPost.ConnectedPosts
                },
                Suggestions = elasticSuggestionHelper.ParseQuestionsToThreadPosts(recommendedQuestions, storedThreadPosts.ToList())
            });
        }
        public IActionResult dostuff()
        {
            using var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
            {
                IsolationLevel = IsolationLevel.RepeatableRead
            });

            var author = _authorRepository.Create(RandomString(10));
            var posts  = _postsRepository.Create(RandomString(10), RandomString(10), author);

            var post = _postsRepository.Get(posts);

            var authorAgain = post;

            return(Ok(JsonSerializer.Serialize(authorAgain)));
        }
        public IActionResult dostuff()
        {
            using var transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions()
            {
                IsolationLevel = IsolationLevel.RepeatableRead
            });

            var author = _authorRepository.Create(RandomString(10));
            var posts  = _postsRepository.Create(RandomString(10), RandomString(10), author);

            Thread.Sleep(3000);

            var post = _postsRepository.Get(posts);

            transaction.Complete();
            return(Ok(post));
        }
示例#8
0
        public Post CreatePost(CreatePostDto postDto, User user)
        {
            string postId = Guid.NewGuid().ToString();

            string imgUrl = null;

            try
            {
                imgUrl = postDto.Image == null ? null : _s3Uploader.UploadFile(postDto.Image, postId);

                Post post = new Post()
                {
                    Content    = postDto.Content,
                    CreatedOn  = DateTime.UtcNow,
                    PostId     = postId,
                    Visability = postDto.WhoIsWatching,
                    ImgUrl     = imgUrl
                };

                _postsRepository.Create(post, user.UserId);

                foreach (var reference in postDto.Referencing)
                {
                    _postsRepository.CreateReference(postId, reference.UserId, reference.StartIndex, reference.EndIndex);

                    if (user.UserId != reference.UserId)
                    {
                        object referencigNoification = new { user, postId, ReciverId = reference.UserId };
                        _serverComunication.NotifyUser("/ReferenceInPost", referencigNoification);
                    }
                }
                return(post);
            }
            catch (Exception e)
            {
                _log.Error(e);
                return(null);
            }
        }
 public ActionResult Create(PostModel post)
 {
     _postsRepository.Create(post);
     return(Ok());
 }
示例#10
0
 public void Create(PostDto post)
 {
     _postRepository.Create(_mapper.Map <PostDto, Post>(post));
     _postRepository.Save();
 }
        public RootMutation(
            IApplicationUsersRepository applicationUserRepository,
            IPostsRepository postRepository)
        {
            Name = "Mutation";

            Field <ApplicationUserType>(
                "SignUp",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType> {
                Name = "userName"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "email"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                var userName = context.GetArgument <string>("userName");
                var email    = context.GetArgument <string>("email");
                var password = context.GetArgument <string>("password");
                return(applicationUserRepository.Create(userName, email, password));
            }
                );

            Field <ApplicationUserType>(
                "SignIn",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "email"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "password"
            }),
                resolve: context =>
            {
                var email    = context.GetArgument <string>("email");
                var password = context.GetArgument <string>("password");
                return(applicationUserRepository.GetAuthenticatedUser(email, password));
            }
                );

            Field <PostType>(
                "CreatePost",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PostInputType> > {
                Name = "newPost"
            }),
                resolve: context => postRepository.Create(context.GetArgument <Post>("newPost"))
                );

            Field <PostType>(
                "UpdatePost",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <PostInputType> > {
                Name = "updatedPost"
            }),
                resolve: context => postRepository.Update(context.GetArgument <Post>("updatedPost"))
                );

            Field <PostType>(
                "DeletePost",
                arguments: new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "postId"
            }),
                resolve: context => postRepository.Delete(context.GetArgument <string>("postId"))
                );
        }