public async Task <IActionResult> DeletePost(int?id) { if (id == null) { return(NotFound()); } await _postManager.DeletePostAsync(new PostDto { Id = (int)id }); return(RedirectToAction(nameof(Index))); }
public async Task <ActionResult> Delete(int postId) { return(await HandleExceptions(async() => { var role = User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimsIdentity.DefaultRoleClaimType))?.Value; var userId = User.Claims.FirstOrDefault(x => x.Type.Equals(ClaimsIdentity.DefaultNameClaimType))?.Value; var authorId = await _postManager.GetPostAuthorIdAsync(postId); if (role != "Admin" && Int32.Parse(userId) != authorId) { return Forbid("Access denied"); } var hostRoot = _hostServices.GetHostPath(); await _postManager.DeletePostAsync(postId, false, hostRoot); return Ok(); })); }
public async Task <ActionResult> Delete(int id) { await postManager.DeletePostAsync(id); return(Ok()); }
public Task DeletePost(Guid postId) { return(_postManager.DeletePostAsync(postId)); }