public JsonResult OnPostDeleteProduct([FromBody] BindModel model) { var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new GRPCCoreCrudExampleServer.Product.ProductClient(channel); client.DeleteProduct(new GRPCCoreCrudExampleServer.ProductMessage() { Id = model.Id }); return(new JsonResult("Success")); }
public JsonResult OnGetEditProduct(int Id) { var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new GRPCCoreCrudExampleServer.Product.ProductClient(channel); var product = client.GetProduct(new GRPCCoreCrudExampleServer.ProductMessage() { Id = Id }); return(new JsonResult(product, new JsonSerializerOptions { PropertyNamingPolicy = null })); }
public IActionResult OnGet() { try { var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new GRPCCoreCrudExampleServer.Product.ProductClient(channel); var productsRepsonse = client.GetProducts(new ProductMessage()); ProductsList = _mapper.Map <List <ProductModel> >(productsRepsonse.Items); return(Page()); } catch (Exception ex) { ViewData["Error"] = ex.Message.ToString().Split(',').SingleOrDefault(a => a.Trim().StartsWith("Detail=")); return(Page()); } }
public async Task <IActionResult> OnPost() { if (string.IsNullOrEmpty(Input.Name)) { return(RedirectToPage("Index")); } var channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new GRPCCoreCrudExampleServer.Product.ProductClient(channel); var product = _mapper.Map <ProductMessage>(Input); if (Input.Id == 0) { await client.AddProductAsync(product); } else { await client.UpdateProductAsync(product); } return(RedirectToPage("Index")); }