public override async Task <UpdateBlogResponse> UpdateBlog(UpdateBlogRequest request, ServerCallContext context) { var blogId = request.Blog.Id; var filter = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", new ObjectId(blogId)); var result = mongoCollection.Find(filter).FirstOrDefault(); if (result == null) { throw new RpcException(new Status(StatusCode.NotFound, $"The blog id {blogId} wasn't find")); } var doc = new BsonDocument("author_id", request.Blog.AuthorId) .Add("title", request.Blog.Title) .Add("content", request.Blog.Content); mongoCollection.ReplaceOne(filter, doc); var blog = new Blog.Blog() { AuthorId = doc.GetValue("author_id").AsString, Title = doc.GetValue("title").AsString, Content = doc.GetValue("content").AsString }; blog.Id = blogId; return(new UpdateBlogResponse() { Blog = blog }); }
private static void DeleteBlog(BlogService.BlogServiceClient client, Blog.Blog blog) { try { var response = client.DeleteBlog(new DeleteBlogrequest() { BlogId = blog.Id }); Console.WriteLine("The blog id " + blog.Id + " is deleted"); } catch (RpcException ex) { Console.WriteLine(ex.Status.Detail); } }
private static void DeleteBlog(BlogService.BlogServiceClient client, Blog.Blog blog) { try { var response = client.DeleteBlog(new DeleteBlogRequest() { BlogId = blog.Id }); Console.WriteLine($"The blog with id {response.BlogId} was deleted."); } catch (RpcException e) { Console.WriteLine(e.Status.Detail); } }
private static void UpdateBlog(BlogService.BlogServiceClient client, Blog.Blog blog) { try { blog.Title = "Updated Title"; var response = client.UpdateBlog(new UpdateBlogRequest() { Blog = blog }); Console.WriteLine(response.Blog.ToString()); } catch (RpcException ex) { Console.WriteLine(ex.Status.Detail); } }
private static void UpdateBlog(BlogService.BlogServiceClient client, Blog.Blog blog) { try { blog.AuthorId = "Maria camila"; blog.Title = "Blog de cami"; blog.Content = "barbies y muñecos"; var response = client.UpdateBlog(new UpdateBlogRequest() { Blog = blog }); Console.WriteLine(response.Blog.ToString()); } catch (RpcException e) { Console.WriteLine(e.Status.Detail); } }
public static string updateBlog(BlogService.BlogServiceClient client, Blog.Blog blog) { try { blog.Id = "5f9f0f21a772b24eadb150a8"; blog.AuthorId = "Ali"; blog.Content = "Agah"; blog.Title = "Welcome To Iran"; var response = client.UpdateBlog(new UpdateBlogRequest() { Blog = blog }); return(response.Blog.ToString()); } catch (System.IO.IOException e) { Console.WriteLine("client error:" + e.Message); throw; } }
/// <summary> /// GetById Blog Method /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override async Task <ReadBlogResponse> ReadBlog(ReadBlogRequest request, ServerCallContext context) { var filter = new FilterDefinitionBuilder <BsonDocument>().Eq("_id", new ObjectId(request.BlogId)); var result = await mongoCollection.Find(filter).FirstOrDefaultAsync(); if (result == null) { throw new RpcException(new Status(StatusCode.NotFound, "The blog id " + request.BlogId + " was not find")); } Blog.Blog blog = new Blog.Blog() { AuthorId = result.GetValue("author_id").AsString, Title = result.GetValue("title").AsString, Content = result.GetValue("content").AsString }; return(new ReadBlogResponse() { Blog = blog }); }
private static void UpdateBlog(BlogService.BlogServiceClient client) { try { var blog = new Blog.Blog { AuthorId = "Şefik Can Totti", Content = "Test Content v2", Title = "Test Title v2", Id = "5e91e157d31ecb45c8f84714" }; var response = client.UpdateBlog(new UpdateBlogRequest() { Blog = blog }); Console.WriteLine(response.Blog.ToString()); } catch (RpcException e) { Console.WriteLine(e.Status.Detail); } }
public List<Post> GetPostsFor(Blog.Blog blog) { throw new NotImplementedException(); }
public Blog.Blog GetBlog(Blog.Blog blog) { throw new NotImplementedException(); }