public static void ValidateBody(JObject body) { BaseBodyValidator.ValidateBody(body); var userId = body.Value <string>("userId"); if (String.IsNullOrWhiteSpace(userId)) { throw new Exception("Missing parameter: userId cannot be null or empty."); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { try { var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); log.LogInformation($"Request body: {requestBody}"); var requestBodyParsed = JObject.Parse(requestBody); BaseBodyValidator.ValidateBody(requestBodyParsed); var contractAddress = requestBodyParsed.Value <string>("contractAddress"); var web3 = Web3Service.Initialize(); var stockService = new StockService(web3, contractAddress); var createItem = JsonConvert.DeserializeObject <CreateItemFunction>(requestBody); var receiptForCreateItemFunctionCall = await stockService.CreateItemRequestAndWaitForReceiptAsync(createItem); var itemCreatedEvent = receiptForCreateItemFunctionCall.DecodeAllEvents <ItemCreatedEventDTO>().FirstOrDefault().Event; log.LogInformation("Event:"); log.LogInformation($" Message: {itemCreatedEvent.Message}"); log.LogInformation($" Item ID: {itemCreatedEvent.Id}"); return(new OkObjectResult(itemCreatedEvent.Id)); } catch (Exception e) { log.LogInformation($"The following Exception was raised in CreateItem: {e.Message}"); if (e is SmartContractRevertException || e is RpcResponseException) { return(new ContentResult { StatusCode = 401, Content = Messages.UnAuthorizedMessage }); } return(new BadRequestObjectResult(e.Message)); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { try { var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); log.LogInformation($"Request body: {requestBody}"); var requestBodyParsed = JObject.Parse(requestBody); BaseBodyValidator.ValidateBody(requestBodyParsed); var contractAddress = requestBodyParsed.Value <string>("contractAddress"); var web3 = Web3Service.Initialize(); var retailerService = new RetailerService(web3, contractAddress); var checkOrderItemsAvailability = JsonConvert.DeserializeObject <CheckOrderItemsAvailabilityFunction>(requestBody); await retailerService.CheckOrderItemsAvailabilityQueryAsync(checkOrderItemsAvailability); log.LogInformation($"Order {checkOrderItemsAvailability.OrderId} availability checked."); return(new OkResult()); } catch (Exception e) { log.LogInformation($"The following Exception was raised in CheckOrderItemsAvailability: {e.Message}"); if (e is SmartContractRevertException || e is RpcResponseException) { return(new ContentResult { StatusCode = 401, Content = Messages.UnAuthorizedMessage }); } return(new BadRequestObjectResult(e.Message)); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { try { var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); log.LogInformation($"Request body: {requestBody}"); var requestBodyParsed = JObject.Parse(requestBody); BaseBodyValidator.ValidateBody(requestBodyParsed); var contractAddress = requestBodyParsed.Value <string>("contractAddress"); var web3 = Web3Service.Initialize(); var stockService = new StockService(web3, contractAddress); var updateItemCategory = JsonConvert.DeserializeObject <UpdateItemCategoryFunction>(requestBody); await stockService.UpdateItemCategoryRequestAsync(updateItemCategory); log.LogInformation($"Category of the Item {updateItemCategory.Id} updated to: {updateItemCategory.Category}"); return(new OkResult()); } catch (Exception e) { log.LogInformation($"The following Exception was raised in UpdateItemCategory: {e.Message}"); if (e is SmartContractRevertException || e is RpcResponseException) { return(new ContentResult { StatusCode = 401, Content = Messages.UnAuthorizedMessage }); } return(new BadRequestObjectResult(e.Message)); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { try { var requestBody = await new StreamReader(req.Body).ReadToEndAsync(); log.LogInformation($"Request body: {requestBody}"); var requestBodyParsed = JObject.Parse(requestBody); BaseBodyValidator.ValidateBody(requestBodyParsed); var contractAddress = requestBodyParsed.Value <string>("contractAddress"); var web3 = Web3Service.Initialize(); var retailerService = new RetailerService(web3, contractAddress); var newOrders = await retailerService.GetNewOrdersQueryAsync(); log.LogInformation($"The amount of new orders is: {newOrders.Count}"); return(new OkObjectResult(newOrders)); } catch (Exception e) { log.LogInformation($"The following Exception was raised in GetNewOrders: {e.Message}"); if (e is SmartContractRevertException || e is RpcResponseException) { return(new ContentResult { StatusCode = 401, Content = Messages.UnAuthorizedMessage }); } return(new BadRequestObjectResult(e.Message)); } }