public async Task <IActionResult> Update([FromBody] CreateOrEditCommentDto dto, [FromRoute] long id, long slug) { // we need to load the user in order to let the Handler check it agains the owner if needed Comment comment = await _commentService.FetchCommentByIdAsync(id, includeUser : true); if (comment == null) { return(StatusCodeAndDtoWrapper.BuildGenericNotFound()); } var result = await _authorizationService.AuthorizeAsync(User, comment, _configService.GetDeleteCommentPolicyName()); if (result.Succeeded) { int result2 = await _commentService.UpdateAsync(comment, dto); return(StatusCodeAndDtoWrapper.BuildSuccess(CommentDetailsDto.Build(comment), "Comment updated successfully")); //return StatusCodeAndDtoWrapper.BuildSuccess("Comment updated successfully"); } else { return(StatusCodeAndDtoWrapper.BuildUnauthorized("Permission denied")); } }
public static ProductDetailsDto Build(Product product) { var commentDtos = new List <CommentDetailsDto>(); if (product.Comments != null) { foreach (var comment in product.Comments) { commentDtos.Add(CommentDetailsDto.Build(comment)); } } return(new ProductDetailsDto { Id = product.Id, Name = product.Name, Slug = product.Slug, Description = product.Description, PublishedAt = product.PublishAt, Comments = commentDtos, Tags = TagOnlyNameDto.BuildAsStringList(product.ProductTags), Categories = CategoryOnlyNameDto.BuildAsStringList(product.ProductCategories), ImageUrls = product.ProductImages.Select(pi => pi.FilePath) }); }
public async Task <IActionResult> Create(string slug, [FromBody] CreateOrEditCommentDto model) { if (!ModelState.IsValid) { return(StatusCodeAndDtoWrapper.BuilBadRequest(ModelState)); } long userId = Convert.ToInt64(User.FindFirst(ClaimTypes.NameIdentifier).Value); ApplicationUser user = await _usersService.GetCurrentUserAsync(); Comment comment = await _commentService.CreateAsync(user, slug, model, userId); return(StatusCodeAndDtoWrapper.BuildSuccess(CommentDetailsDto.Build(comment))); }
public async Task <IActionResult> Create(string slug, [FromBody] CreateOrEditCommentDto model) { if (!ModelState.IsValid) { return(StatusCodeAndDtoWrapper.BuilBadRequest(ModelState)); } string userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; ApplicationUser user = await _usersService.GetCurrentUserAsync(); Comment comment = await _commentService.CreateComment(user, slug, model.Content, userId); // return RedirectToAction("GetArticleBySlug", "Articles", new {slug = slug}); return(StatusCodeAndDtoWrapper.BuildSuccess(CommentDetailsDto.Build(comment))); }
public static ArticleDetailsDto Build(Entities.Article article) { var commentDtos = new List <CommentDetailsDto>(); foreach (var comment in article.Comments) { commentDtos.Add(CommentDetailsDto.Build(comment)); } return(new ArticleDetailsDto { Id = article.Id, Slug = article.Slug, Title = article.Slug, Body = article.Body, PublishedAt = article.PublishedOn, Comments = commentDtos, User = UserBasicEmbeddedInfoDto.Build(article.User), Tags = TagOnlyNameDto.BuildAsStringList(article.ArticlesTags), Categories = CategoryOnlyNameDto.BuildAsStringList(article.ArticleCategories), }); }
public async Task <IActionResult> GetDetails(string slug, long commentId, CreateOrEditCommentDto model) { Comment comment = await _commentService.FetchCommentByIdAsync(commentId); return(StatusCodeAndDtoWrapper.BuildSuccess(CommentDetailsDto.Build(comment))); }