コード例 #1
0
ファイル: PostsController.cs プロジェクト: PDmatrix/Blog
        public async Task <ActionResult> Create(PostRequest postRequest)
        {
            var addPostCommand = new AddPostCommand
            {
                Content = postRequest.Content,
                Title   = postRequest.Title,
                Excerpt = postRequest.Excerpt
            };
            var createdPostId = await Mediator.Send(addPostCommand);

            return(CreatedAtRoute(nameof(GetById), new { Id = createdPostId }));
        }
コード例 #2
0
        public async Task <IActionResult> AddPost([FromBody] AddPostCommandDto data)
        {
            var cmd = new AddPostCommand
            {
                UserUuid     = User.Identity.Name,
                Description  = data.Description,
                ResourceName = data.ResourceName
            };

            await _mediator.Publish(cmd);

            return(Ok());
        }
コード例 #3
0
ファイル: PostService.cs プロジェクト: wojtek-rak/PaintStore
 public Posts AddImage(AddPostCommand post)
 {
     using (var db = _paintStoreContext)
     {
         UsersManager.UserPostsCountPlus(db, post.UserId);
         var postToAdd = _mapper.Map <Posts>(post);
         postToAdd.CreationDate  = DateTime.Now;
         postToAdd.UserOwnerName = db.Users.First(x => x.Id == post.UserId).Name;
         db.Posts.Add(postToAdd);
         db.SaveChanges();
         return(postToAdd);
     }
 }
コード例 #4
0
        public async Task AddPostCommandTest()
        {
            var post = new AddPostCommand
            {
                Title   = "first-post",
                Slug    = "first-post",
                Summary = "This is a summery",
                Content = "This is a content"
            };
            var rs = await _postCommandHandler.Handle(post, CancellationToken.None);

            Assert.AreEqual(rs.Message, "Successfully saved post");
            Assert.AreEqual(rs.Data, 1);
        }
コード例 #5
0
    public void AddPost(Post post)
    {
        bool exists = IsUsernamePresentQuery <bool> .Execute(new { profile.Username });

        if (exists)
        {
            AddPostCommand.Execute(new
            {
                post.Author,
                post.Content,
                post.Timestamp
            });
        }
    }
コード例 #6
0
        public async Task <ActionResult> Create(PostRequest postRequest)
        {
            var addPostCommand = new AddPostCommand
            {
                Title   = postRequest.Title,
                Excerpt = postRequest.Excerpt,
                DreamId = postRequest.DreamId,
                Tags    = postRequest.Tags.Split(','),
                UserId  = User.FindFirst(ClaimTypes.NameIdentifier)?.Value
            };
            var createdPostId = await Mediator.Send(addPostCommand);

            return(CreatedAtAction(nameof(GetById), new { id = createdPostId }, null));
        }
コード例 #7
0
        public async Task <IActionResult> Add(AddPostCommand addPostCommand)
        {
            if (!ModelState.IsValid)
            {
                return(View(addPostCommand));
            }
            var rs = await Mediator.Send(addPostCommand);

            if (rs.Succeeded)
            {
                return(RedirectToAction("Index",
                                        new { area = "Admin", id = rs.Data, succeeded = rs.Succeeded, message = rs.Message }));
            }
            return(View(addPostCommand));
        }
コード例 #8
0
        // Post
        public void Handle(AddPostCommand message)
        {
            var post = new Post(message.TopicId, message.UserId, message.Text);

            if (!post.IsValid())
            {
                NotifyErrors(post.ValidationResult);
                return;
            }

            _topicRepository.AddPost(post);
            if (Commit())
            {
                _bus.RaiseEvent(new AddedPostEvent(post.Id, post.UserId, post.TopicId, post.Text, post.Created));
            }
        }
コード例 #9
0
        public async Task <Response <int> > Handle(AddPostCommand command, CancellationToken cancellationToken)
        {
            var post = _mapper.Map <Domain.Persistence.Entities.Post>(command);

            try
            {
                post = await _persistenceUnitOfWork.Post.AddAsync(post);

                await _persistenceUnitOfWork.CommitAsync();
            }
            catch (Exception e)
            {
                _persistenceUnitOfWork.Dispose();
                _logger.LogError(e, "Failed to save new post in database");
            }
            return(Response <int> .Success(post.Id, "Successfully saved post"));
        }
コード例 #10
0
        // [ValidateInput(false)]
        public IActionResult Add(string postTitle, string postSlug, string postSubTitle, string headMask, int layoutType,
                                 string postMarkDown, string tags, int published, string pubDate, string postHeadImageUrl)
        {
            AddPostCommand command = new AddPostCommand();

            command.HeadMask         = headMask;
            command.LayoutType       = layoutType;
            command.PostHeadImageUrl = postHeadImageUrl;
            command.PostMarkDown     = postMarkDown;
            command.PostSlug         = postSlug;
            command.postSubTitle     = postSubTitle;
            command.PostTitle        = postTitle;
            command.Published        = published;
            command.Tags             = tags;
            var result = _addPostCommandInvorker.Execute(command);

            return(RedirectToAction("Index"));
        }
コード例 #11
0
    public void AddPost(Post post)
    {
        bool exists = IsUsernamePresentQuery <bool> .Execute(new { profile.Username });

        if (exists)
        {
            var id = AddPostCommand.Execute(new
            {
                post.Author,
                post.Content,
                post.Timestamp
            });

            var hash = HashObject(post).ToHexString();

            Connector connector = new Connector(credentialManager.PublicKey, credentialManager.PrivateKey);
            connector.Call("addPostHash", id, hash);
        }
    }
コード例 #12
0
        // POST api/posts
        public HttpResponseMessage Post(AddPostCommand command)
        {
            var post = new Post
            {
                Id = GetNextId(),
                Title = command.Title,
                Slug = command.Slug ?? command.Title.ToSlug(),
                Summary = command.Summary,
                ContentType = command.ContentType,
                Content = command.Content,
                Tags = command.Tags,
                PublishDate = command.PublishDate ?? DateTime.UtcNow
            };

            posts.Add(post);

            var response = Request.CreateResponse(HttpStatusCode.Created, new PostModel(post, GetCategoryScheme()));
            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "posts", id = post.Id }));

            return response;
        }
コード例 #13
0
        // POST api/posts
        public HttpResponseMessage Post(AddPostCommand command)
        {
            var post = new Post
            {
                Id          = GetNextId(),
                Title       = command.Title,
                Slug        = command.Slug ?? command.Title.ToSlug(),
                Summary     = command.Summary,
                ContentType = command.ContentType,
                Content     = command.Content,
                Tags        = command.Tags,
                PublishDate = command.PublishDate ?? DateTime.UtcNow
            };

            posts.Add(post);

            var response = Request.CreateResponse(HttpStatusCode.Created, new PostModel(post, GetCategoryScheme()));

            response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "posts", id = post.Id }));

            return(response);
        }
コード例 #14
0
        public async Task <IActionResult> Add2([FromBody] AddPostCommand command)
        {
            var result = await _mediator.Send(command);

            return(Ok(result));
        }
コード例 #15
0
        public async Task <IActionResult> AddPost([FromBody] Post post, [FromServices] IMemoryCache cache, [FromServices] AddPostCommand command)
        {
            cache.Remove("/");
            await command.ExecuteAsync(post);

            return(Ok());
        }
コード例 #16
0
 public async Task <ActionResult <long> > Post([FromBody] AddPostCommand command)
 => Ok(await Handle(command));
コード例 #17
0
ファイル: AddPost.cshtml.cs プロジェクト: ofpinewood/pineblog
        public IActionResult OnGet()
        {
            Post = new AddPostCommand();

            return(Page());
        }
コード例 #18
0
        // POST api/posts
        public async Task<HttpResponseMessage> Post(AddPostCommand command)
        {
            HttpResponseMessage result;
            ClaimsPrincipal user = User as ClaimsPrincipal;
            Claim userIdClaim = user.Claims.FirstOrDefault(claim => claim.Type == ClaimTypes.NameIdentifier);

            if (userIdClaim == null || string.IsNullOrEmpty(userIdClaim.Value))
            {
                result = Request.CreateResponse(HttpStatusCode.InternalServerError);
            }
            else
            {
                BlogPost post = new BlogPost
                {
                    AuthorId = userIdClaim.Value,
                    Language = "en-US",
                    Title = command.Title,
                    BriefInfo = command.Summary,
                    Content = command.Content,
                    Tags = new Collection<Tag>(command.Tags.Select(tag => new Tag { Name = tag, Slug = tag.ToSlug() }).ToList()),
                    CreatedOn = command.PublishDate ?? DateTimeOffset.Now,
                    LastUpdatedOn = command.PublishDate ?? DateTimeOffset.Now,
                    AllowComments = true,
                    IsApproved = true
                };

                post.Slugs.Add(new Slug
                {
                    IsDefault = true,
                    Path = command.Slug ?? command.Title.ToSlug(),
                    CreatedOn = command.PublishDate ?? DateTimeOffset.Now
                });

                await RavenSession.StoreAsync(post);
                HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created, new PostModel(post, GetCategoryScheme()));
                response.Headers.Location = new Uri(Url.Link("DefaultApi", new { controller = "posts", id = post.Id.ToIntId() }));
                result = response;
            }

            return result;
        }
コード例 #19
0
 public IActionResult AddImage([FromBody] AddPostCommand post)
 {
     return(Ok(_postsService.AddImage(post)));
 }
コード例 #20
0
 public Task <Post> AddPostAsync(AddPostCommand command)
 {
     return(api.PostAsync <AddPostCommand, Post>(GetPostsPath(), command));
 }