public void Test_CommentPostRequest_1_Returns_Valid_UriPathParameters() { var request = new CommentPostRequest <TraktCommentPost>(); var uriParams = request.GetUriPathParameters(); uriParams.Should().NotBeNull().And.BeEmpty().And.HaveCount(0); }
public async Task <CommentPostResponse> CommentPostAsync(CommentPostRequest request, string userId) { var entity = new PostCommentEntity { PostId = request.PostId, UserId = userId, Comment = request.Comment, CommentDate = DateTime.UtcNow }; var result = await _postRepository.CommentPostAsync(entity); if (!result) { return new CommentPostResponse { StatusCode = (int)HttpStatusCode.Unauthorized } } ; var response = new CommentPostResponse { StatusCode = (int)HttpStatusCode.Created }; return(response); }
public void Test_CommentPostRequest_1_Validate_Throws_ArgumentNullException() { var request = new CommentPostRequest <TraktCommentPost>(); Action act = () => request.Validate(); act.Should().Throw <ArgumentNullException>(); }
public async Task CommentPost(AddCommentModel model) { var commentPostRequest = new CommentPostRequest { Content = model.Content, PostId = model.PostId }; await _postsManagementService.CommentPost(commentPostRequest); }
public CommentGetResponse PostNewComment(CommentPostRequest request, string Author) { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); return(connection.QueryFirst <CommentGetResponse>( @" EXEC [Blog].[dbo].[SP_Create_New_Comment] @EntryId = @EntryId, @Content = @Content, @Author = @Author", new { EntryId = request.EntryId, Content = request.Content, Author = Author } )); } }
public async Task CommentPost(CommentPostRequest request) { var comment = new Comment { AuthorId = request.AuthorId, Content = request.Content, PostId = request.PostId }; DbContext.Comments.Add(comment); await DbContext.SaveChangesAsync(); }
public async Task <IActionResult> CommentPost([FromBody] CommentPostRequest request) { var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value; if (userId == null) { return(BadRequest()); } var response = await _postService.CommentPostAsync(request, userId); return(GenerateResponse(response)); }
public async Task <IActionResult> PostNewComment(CommentPostRequest request) { var userEmail = await GetUserName(); var access = _dataRepository.GetUserAccess(userEmail); if (access.Admin != 1 && access.Editor != 1) { return(Unauthorized(new { message = "Access Denied" })); } var results = _dataRepository.PostNewComment(request, userEmail); return(Ok(results)); }
/** * Używamy atrybutu [HttpPost] ponieważ do tworzenia zasobów powinniśmy używać metody HTTP POST (nie musimy, ale powinniśmy). * Bez tego atrybutu wszystkie metody HTTP będą mogły być wykonane na tej metodzie klasy, więc nie jest potrzebna do działa (technicznie). */ // [HttpPost] // Dzieki tej adnotacji metoda CommentPost klasy PostsController odpowie tylko na zapytania HTTP POST public async Task <IActionResult> CommentPost(CommentPostRequest commentPostRequest) { // Tworzymy nowy obiekt komentarza i wpisujemy do niego wartości z obiekty klasy CommentPostRequest Comment comment = new Comment(); comment.PostId = commentPostRequest.PostId; // Znajdujemy w bazie danych Post, który komentujemy i przypisujemy do komentarza ten post. comment.post = _context.Posts.Find(commentPostRequest.PostId); comment.Content = commentPostRequest.Content; // Deklarujemy, że chcemy zapisać komentarz w bazie danych _context.Add(comment); // Zapisujmey wszystkie zmiany w bazie danych w ramach tej metody await _context.SaveChangesAsync(); // Przekierowujemy tę metodę do akcji /Details/{postId} return(RedirectToAction("Details", new { id = commentPostRequest.PostId })); }
public void Test_CommentPostRequest_1_Has_Valid_UriTemplate() { var request = new CommentPostRequest <TraktCommentPost>(); request.UriTemplate.Should().Be("comments"); }
public void Test_CommentPostRequest_1_Has_AuthorizationRequirement_Required() { var request = new CommentPostRequest <TraktCommentPost>(); request.AuthorizationRequirement.Should().Be(AuthorizationRequirement.Required); }
public async Task CommentPost(CommentPostRequest request) { await ProcessRequest(request, _postsRepository.CommentPost); }