public IActionResult Post([FromBody] NewProductApiModel value)
 {
     try
     {
         myProductService.AddProduct(value);
     }
     catch (Exception e)
     {
         return(BadRequest());
     }
     return(Ok());
 }
示例#2
0
        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);
        }
示例#3
0
        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)
            {
            }
        }