Example #1
0
        public async Task <IActionResult> Get()
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5002");
            var client  = new ProductsBuf.ProductsBufClient(channel);

            var response = await client.GetAsync(new Empty());


            return(Ok(response));
        }
Example #2
0
        public async Task <IActionResult> Post([FromBody] ProductViewModel data)
        {
            var channel = GrpcChannel.ForAddress("https://localhost:5002");
            var client  = new ProductsBuf.ProductsBufClient(channel);

            var response = await client.PostAsync(new ProductBuf {
                Name        = data.Name,
                Description = data.Description,
                Price       = Convert.ToInt64(data.Price),
                Photo       = data.Photo
            });

            if (response.StatusCode == 201)
            {
                return(StatusCode(201));
            }
            else
            {
                return(BadRequest());
            }
        }