Beispiel #1
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger log)
        {
            log.LogInformation("Processing your request...");

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var    command     = JsonConvert.DeserializeObject <CreateOrUpdateProductCommand>(requestBody);

            if (command == null)
            {
                return(new BadRequestObjectResult("Product information is required"));
            }

            var productRepository = new ProductsRepository();

            var result = await productRepository.CreateOrUpdateProductAsync(command);

            if (result.IsSuccess)
            {
                return(new OkObjectResult("Prodcut processed"));
            }
            else
            {
                return(new BadRequestObjectResult("An error occured: " + result.Errors[0]));
            }
        }