public override async Task <DeleteBlogResponse> DeleteBlog(DeleteBlogRequest request, ServerCallContext context) { var blogId = request.BlogId; var filter = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", new ObjectId(blogId)); var deleted = await mongoCollection.DeleteOneAsync(filter); if (deleted.DeletedCount == 0) { throw new RpcException(new Status(StatusCode.NotFound, $"Blog with id={blogId} was not found")); } return(new DeleteBlogResponse { BlogId = blogId }); }
/// <summary> /// Delete Blog Method /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override async Task <DeleteBlogResponse> DeleteBlog(DeleteBlogRequest request, ServerCallContext context) { var filter = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", new ObjectId(request.BlogId)); var result = await mongoCollection.DeleteOneAsync(filter); if (result.DeletedCount == 0) { throw new RpcException(new Status(StatusCode.NotFound, "The blog id " + request.BlogId + " was not find")); } return(new DeleteBlogResponse() { BlogId = request.BlogId }); }
public async Task <IActionResult> Delete(Guid id) { var deleteRequest = new DeleteBlogRequest() { Id = id, Username = User.Identity.Name }; var response = await _blogs.DeleteAsync(deleteRequest); if (!response.Success) { return(BadRequest(response.ErrorMessage)); } var blog = response.Result; var readDto = _mapper.Map <BlogReadDto>(blog); return(Ok(readDto)); }
public void Delete(DeleteBlogRequest request) { this._BlogManager.DeleteBlog(request.BlogId); }