public async Task <ActionResult> Post([FromBody] ResponseProduct response) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { ProductName productName = new ProductName(response.name); Price price = new Price(response.price); Stock stock = new Stock(response.stock); ProductEntity product = new ProductEntity(productName, price, stock); var result = await _service.Post(product); if (result != null) { return(Created(new Uri(Url.Link("GetWithId", new { id = result.Id })), result)); } else { return(BadRequest()); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public async Task <IActionResult> Post([FromBody] Models.Product product) { using GrpcChannel channel = GrpcChannel.ForAddress("https://localhost:5001"); var client = new Product.ProductClient(channel); var r = new RequestProduct { Title = product.Title, Price = (double)product.Price }; ResponseProduct response = await client.SendProductAsync(r); return(Ok(response)); }
public IHttpActionResult GetAll(int page) { IProducManager mprod = new IProducManager(); DALProduct dalProduct = new DALProduct(); var responseProducs = new ResponseProduct(); responseProducs.totalPaginas = mprod.Pagination(); responseProducs.products = dalProduct.GetProducts(page); return(Ok(responseProducs)); }
public async Task <ActionResult> Put([FromBody] ResponseProduct response) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { ProductEntity product = await _service.Get(response.id); if (product == null) { return(BadRequest()); } product.SetName(new ProductName(response.name)); product.SetPrice(new Price(response.price)); product.SetStock(new Stock(response.stock)); var result = await _service.Put(product); if (result == null) { return(BadRequest()); } else { return(Ok(result)); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public void SuccessGetProducts(ResponseProduct resp) { Description.text = resp.Description; }