public IActionResult Post([FromBody] NewProductApiModel value) { try { myProductService.AddProduct(value); } catch (Exception e) { return(BadRequest()); } return(Ok()); }
public void AddProduct(NewProductApiModel product) { if (string.IsNullOrEmpty(product.Name)) { return; } myProductDataAdapter.AddProduct(new LightProduct { Name = product.Name }, out Guid newId); myProductDataAdapter.AddQuantityToProduct(new ProductQuantity { Barcode = product.Barcode, MeasurementType = product.UnitQuantityType, UnitQuantityTypeVolume = product.UnitQuantity }, newId); }
public async Task AddProduct(NewProductApiModel product) { try { var json = JsonConvert.SerializeObject(product); var data = new StringContent(json, Encoding.UTF8, "application/json"); var client = new HttpClient(); var response = await client.PostAsync(new Uri("http://localhost:5005/api/product"), data); string result = response.Content.ReadAsStringAsync().Result; client.Dispose(); } catch (Exception) { } }