Exemplo n.º 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "delete", Route = "accounts/{accountNumber}")] HttpRequest req,
            string accountNumber,
            ILogger log)
        {
            log.LogInformation("AccountDeleteHttpTrigger function processed a request.");


            if (string.IsNullOrWhiteSpace(accountNumber))
            {
                return(new BadRequestObjectResult("'accountNumber' required in the uri, e.g. 'accounts/{accountNumber}'."));
            }


            var accountData =
                await _accountDataStore.FetchByAccountNumberAsync(
                    accountNumber);

            if (accountData == null)
            {
                return(new NotFoundObjectResult($"Account '{accountNumber}' cannot be found."));
            }

            await _accountDataStore.DeleteByIdAsync(
                accountData.Id,
                accountData.AccountNumber);

            return(new NoContentResult());
        }