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 })); }
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()); }
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); } }
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); }
public void AddPost(Post post) { bool exists = IsUsernamePresentQuery <bool> .Execute(new { profile.Username }); if (exists) { AddPostCommand.Execute(new { post.Author, post.Content, post.Timestamp }); } }
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)); }
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)); }
// 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)); } }
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")); }
// [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")); }
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); } }
// 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; }
// 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); }
public async Task <IActionResult> Add2([FromBody] AddPostCommand command) { var result = await _mediator.Send(command); return(Ok(result)); }
public async Task <IActionResult> AddPost([FromBody] Post post, [FromServices] IMemoryCache cache, [FromServices] AddPostCommand command) { cache.Remove("/"); await command.ExecuteAsync(post); return(Ok()); }
public async Task <ActionResult <long> > Post([FromBody] AddPostCommand command) => Ok(await Handle(command));
public IActionResult OnGet() { Post = new AddPostCommand(); return(Page()); }
// 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; }
public IActionResult AddImage([FromBody] AddPostCommand post) { return(Ok(_postsService.AddImage(post))); }
public Task <Post> AddPostAsync(AddPostCommand command) { return(api.PostAsync <AddPostCommand, Post>(GetPostsPath(), command)); }