private static async Task Main(string[] args) { Console.WriteLine("--------------CLIENT ---------"); var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new ProductService.ProductServiceClient(channel); var products = client.GetAll(new Empty()); Console.WriteLine("[ GetAll ]"); products.CDump("-- products"); Console.WriteLine(""); Console.WriteLine("[ Get Id=1 ]"); var product = client.Get(new ProductId { Id = 1 }); product.CDump("-- product id=1"); Console.WriteLine(""); Console.WriteLine("[ Insert ]"); var newProduct = new Product { Name = "Melon", Brand = "Vegi", Amount = 10, Value = 2.99f }; var createdProduct = client.Insert(newProduct); createdProduct.DDump("createdProduct"); Console.WriteLine(""); Console.WriteLine("[ GetAll ]"); var products01 = client.GetAll(new Empty()); products01.CDump("-- products"); createdProduct.Name = "MELON"; Console.WriteLine(""); Console.WriteLine("[ Update ]"); var updatedProduct = await client.UpdateAsync(createdProduct); updatedProduct.CDump("updatedProduct"); Console.WriteLine(""); Console.WriteLine("[ Delete ]"); var deletedProduct = await client.DeleteAsync(new ProductId { Id = 1 }); updatedProduct.CDump("updatedProduct"); Console.WriteLine(""); Console.WriteLine("[ GetAll ]"); products01 = client.GetAll(new Empty()); products01.CDump("-- products"); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
public IActionResult GetById(int id) { var client = new ProductService.ProductServiceClient(channel); var product = client.Get(new ProductId { Id = id }); if (product == null) { return(NotFound()); } //return new ObjectResult(product); return(Ok(product)); }
public static void Get() { Console.Write("Name:"); string name = Console.ReadLine(); var replay = client.Get(new ProductRequest() { Name = name }); if (replay == null) { Console.WriteLine("No Product!"); } else { Console.WriteLine($"{replay.Name}"); } }