public static async Task <IActionResult> Run([Inject] IDB fakeDB, [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogInformation("C# HTTP trigger function processed a request."); string name = null; string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); log.LogInformation("request body", requestBody); dynamic data = JsonConvert.DeserializeObject(requestBody); name = name ?? data?.name; if (name != null) { log.LogInformation("name", name); var product = fakeDB.CreateProduct(name); var json = JsonConvert.SerializeObject(new { product = product }); return((ActionResult) new OkObjectResult(json)); } else { return(new BadRequestObjectResult("Missing name in posted Body")); } }
void CreateProduct(string name, string description, double price, int minInStock, int id) { Product product = new Product(name, description, price, minInStock, id); db.CreateProduct(product); }