public async Task <IActionResult> Create([FromBody] CreateCategoryDto createCategoryDto) { AuthorizationResult authorizationResult = await _authorizationService.AuthorizeAsync(User, PolicyConstants.ManageCategoryRolePolicy); if (!authorizationResult.Succeeded) { return(ActionResults.UnauthorizedResult(User.Identity.IsAuthenticated)); } string categoryId = await _mediator.Send(new CreateCategoryCommand(createCategoryDto)); return(Created($"{HttpContext.Request.GetDisplayUrl()}/{categoryId}", null)); }
public async Task <IActionResult> Delete([FromRoute] string categoryId) { AuthorizationResult authorizationResult = await _authorizationService.AuthorizeAsync(User, PolicyConstants.ManageCategoryRolePolicy); if (!authorizationResult.Succeeded) { return(ActionResults.UnauthorizedResult(User.Identity.IsAuthenticated)); } await _mediator.Send(new DeleteCategoryCommand(categoryId)); return(Ok()); }
public async Task <IActionResult> Delete([FromRoute] string commentId) { Comment comment = await _mediator.Send(new GetCommentEntityQuery(commentId)); AuthorizationResult authorizationResult = await _authorizationService.AuthorizeAsync(User, comment, PolicyConstants.UpdateCommentRolePolicy); if (!authorizationResult.Succeeded) { return(ActionResults.UnauthorizedResult(User.Identity.IsAuthenticated)); } await _mediator.Send(new DeleteCommentCommand(comment)); return(Ok()); }
public async Task <IActionResult> Update([FromRoute] string categoryId, [FromBody] UpdateCategoryDto updateCategoryDto) { AuthorizationResult authorizationResult = await _authorizationService.AuthorizeAsync(User, PolicyConstants.ManageCategoryRolePolicy); if (!authorizationResult.Succeeded) { return(ActionResults.UnauthorizedResult(User.Identity.IsAuthenticated)); } return(Ok(new Response <CategoryViewModel> { Data = await _mediator.Send(new UpdateCategoryCommand(categoryId, updateCategoryDto)), })); }
public async Task <IActionResult> AddModerator([FromRoute] string communityId, [FromBody] AddModeratorDto addModeratorDto) { Community community = await _mediator.Send(new GetCommunityEntityQuery(communityId)); AuthorizationResult authorizationResult = await _authorizationService.AuthorizeAsync(User, community, PolicyConstants.AddModeratorRolePolicy); if (!authorizationResult.Succeeded) { return(ActionResults.UnauthorizedResult(User.Identity.IsAuthenticated)); } await _mediator.Send(new AddModeratorCommand(community, addModeratorDto)); return(Ok()); }
public async Task <IActionResult> Update([FromRoute] string commentId, [FromBody] UpdateCommentDto updateCommentDto) { Comment comment = await _mediator.Send(new GetCommentEntityQuery(commentId)); AuthorizationResult authorizationResult = await _authorizationService.AuthorizeAsync(User, comment, PolicyConstants.UpdateCommentRolePolicy); if (!authorizationResult.Succeeded) { return(ActionResults.UnauthorizedResult(User.Identity.IsAuthenticated)); } return(Ok(new Response <CommentViewModel> { Data = await _mediator.Send(new UpdateCommentCommand(comment, updateCommentDto)), })); }