public static async Task <HttpResponseMessage> SetBeneficialOwnerRun(
            [HttpTrigger(AuthorizationLevel.Function, "POST", Route = "SetBeneficialOwner/{accountnumber}/{ownername}")] HttpRequestMessage req,
            string accountnumber,
            string ownername,
            [EventStream("Bank", "Account", "{accountnumber}")]  EventStream bankAccountEvents)
        {
            // Set the start time for how long it took to process the message
            DateTime startTime = DateTime.UtcNow;

            if (await bankAccountEvents.Exists())
            {
                if (!string.IsNullOrEmpty(ownername))
                {
                    Account.Events.BeneficiarySet evtBeneficiary = new Account.Events.BeneficiarySet()
                    {
                        BeneficiaryName = ownername
                    };
                    await bankAccountEvents.AppendEvent(evtBeneficiary);
                }

                return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.OK,
                                                             FunctionResponse.CreateResponse(startTime,
                                                                                             false,
                                                                                             $"Beneficial owner of account {accountnumber} set"),
                                                             FunctionResponse.MEDIA_TYPE));
            }
            else
            {
                return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.OK,
                                                             FunctionResponse.CreateResponse(startTime,
                                                                                             true,
                                                                                             $"Account {accountnumber} does not exist"),
                                                             FunctionResponse.MEDIA_TYPE));
            }
        }
Exemplo n.º 2
0
        public static async Task <HttpResponseMessage> ApplyAccruedInterestCommand(
            [HttpTrigger(AuthorizationLevel.Function, "POST", Route = @"ApplyAccruedInterest/{accountnumber}")] HttpRequestMessage req,
            string accountnumber,
            [Command("Bank", "Apply Accrued Interest")] Command cmdApplyAccruedInterest)
        {
            // Set the start time for how long it took to process the message
            DateTime startTime = DateTime.UtcNow;

            // No parameters passed in - but set the as-of date/time so that if this command is
            // re-executed it does not return a different result
            await cmdApplyAccruedInterest.SetParameter("As Of Date", startTime);

            await cmdApplyAccruedInterest.SetParameter("Account Number", accountnumber);

            // Start the set-overdraft-for-interest command step
            await cmdApplyAccruedInterest.InitiateStep(COMMAND_STEP_OVERDRAFT);

            // The rest of the command should flow on from that step completing .. somehow..


            // Return that the command has been initiated...
            return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.OK,
                                                         FunctionResponse.CreateResponse(startTime,
                                                                                         false,
                                                                                         $"Interest accrual process for { accountnumber} initiated"),
                                                         FunctionResponse.MEDIA_TYPE));
        }
        public static async Task <HttpResponseMessage> GetAllAccountsRun(
            [HttpTrigger(AuthorizationLevel.Function, "GET", Route = @"GetAllAccounts/{asOfDate?}")] HttpRequestMessage req,
            string asOfDate,
            [Classification("Bank", "Account", "ALL", nameof(InterestAccruedToday))] Classification clsAllAccounts)
        {
            // Set the start time for how long it took to process the message
            DateTime startTime = DateTime.UtcNow;

            IEnumerable <string> allAccounts = await clsAllAccounts.GetAllInstanceKeys(null);

            System.Text.StringBuilder sbRet = new System.Text.StringBuilder();
            if (null != allAccounts)
            {
                foreach (string accountNumber in allAccounts)
                {
                    if (!(sbRet.Length == 0))
                    {
                        sbRet.Append(",");
                    }
                    sbRet.Append(accountNumber);
                }
            }

            return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.OK,
                                                         FunctionResponse.CreateResponse(startTime,
                                                                                         false,
                                                                                         $"Account numbers: {sbRet.ToString()}  "),
                                                         FunctionResponse.MEDIA_TYPE));
        }
Exemplo n.º 4
0
        public static async Task <HttpResponseMessage> AccountsBelowThresholdQuery(
            [HttpTrigger(AuthorizationLevel.Function, "POST", Route = @"AccountsBelowThresholdQuery")] HttpRequestMessage req,
            [QueryAttribute("Bank", "Accounts Below Threshold")] Query qryAccountsBelowThresholdQuery
            )
        {
            // Set the start time for how long it took to process the message
            DateTime startTime = DateTime.UtcNow;

            return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.Forbidden,
                                                         FunctionResponse.CreateResponse(startTime,
                                                                                         true,
                                                                                         $"Not implemented"),
                                                         FunctionResponse.MEDIA_TYPE));
        }
        public static async Task <HttpResponseMessage> DepositMoneyRun(
            [HttpTrigger(AuthorizationLevel.Function, "POST", Route = @"DepositMoney/{accountnumber}")] HttpRequestMessage req,
            string accountnumber,
            [EventStream("Bank", "Account", "{accountnumber}")]  EventStream bankAccountEvents)
        {
            // Set the start time for how long it took to process the message
            DateTime startTime = DateTime.UtcNow;

            if (!await bankAccountEvents.Exists())
            {
                return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.NotFound,
                                                             FunctionResponse.CreateResponse(startTime,
                                                                                             true,
                                                                                             $"Account {accountnumber} does not exist"),
                                                             FunctionResponse.MEDIA_TYPE));
            }
            else
            {
                // get the request body...
                MoneyDepositData data = await req.Content.ReadAsAsync <MoneyDepositData>();

                // create a deposited event
                DateTime dateDeposited = DateTime.UtcNow;
                Account.Events.MoneyDeposited evDeposited = new Account.Events.MoneyDeposited()
                {
                    LoggedDepositDate = dateDeposited,
                    AmountDeposited   = data.DepositAmount,
                    Commentary        = data.Commentary,
                    Source            = data.Source
                };

                await bankAccountEvents.AppendEvent(evDeposited);

                return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.OK,
                                                             FunctionResponse.CreateResponse(startTime,
                                                                                             false,
                                                                                             $"{data.DepositAmount} deposited to account {accountnumber} "),
                                                             FunctionResponse.MEDIA_TYPE));
            }
        }
        public static async Task <HttpResponseMessage> ApplyAccruedInterestCommand(
            [HttpTrigger(AuthorizationLevel.Function, "POST", Route = @"ApplyAccruedInterest/{accountnumber}")] HttpRequestMessage req,
            string accountnumber,
            [DurableClient] IDurableOrchestrationClient applyInterestOrchestration)
        {
            #region Tracing telemetry
            Activity.Current.AddTag("Account Number", accountnumber);
            #endregion

            // Set the start time for how long it took to process the message
            DateTime startTime = DateTime.UtcNow;

            // use a durable functions GUID so that the orchestration is replayable

            //Command cmdApplyAccruedInterest
            CommandAttribute commandToRun = new CommandAttribute("Bank", "Apply Accrued Interest");
            string           commandId    = await applyInterestOrchestration.StartNewAsync(nameof(StartCommand), commandToRun);

            commandToRun = new CommandAttribute("Bank", "Apply Accrued Interest", commandId);
            Command cmdApplyAccruedInterest = new Command(commandToRun);

            // No parameters passed in - but set the as-of date/time so that if this command is
            // re-executed it does not return a different result
            InstanceParameter paramAsOf = new InstanceParameter(cmdApplyAccruedInterest.AsAttribute(), "As Of Date", startTime);
            await applyInterestOrchestration.StartNewAsync(nameof(SetParametersCommandStep), paramAsOf);

            InstanceParameter paramAccount = new InstanceParameter(cmdApplyAccruedInterest.AsAttribute(), "Account Number", accountnumber);
            await applyInterestOrchestration.StartNewAsync(nameof(SetParametersCommandStep), paramAccount);

            // The rest of the command is performed by a durable functions orchestration
            await applyInterestOrchestration.StartNewAsync(nameof(ApplyAccruedInterestCommandStep), cmdApplyAccruedInterest.AsAttribute());

            // Return that the command has been initiated...
            return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.OK,
                                                         FunctionResponse.CreateResponse(startTime,
                                                                                         false,
                                                                                         $"Interest accrual process for { accountnumber} initiated"),
                                                         FunctionResponse.MEDIA_TYPE));
        }
        public static async Task <HttpResponseMessage> OpenAccountRun(
            [HttpTrigger(AuthorizationLevel.Function, "POST", Route = @"OpenAccount/{accountnumber}")] HttpRequestMessage req,
            string accountnumber,
            [EventStream("Bank", "Account", "{accountnumber}")]  EventStream bankAccountEvents)
        {
            // Set the start time for how long it took to process the message
            DateTime startTime = DateTime.UtcNow;

            if (await bankAccountEvents.Exists())
            {
                return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.Forbidden,
                                                             FunctionResponse.CreateResponse(startTime,
                                                                                             true,
                                                                                             $"Account {accountnumber} already exists"),
                                                             FunctionResponse.MEDIA_TYPE));
            }
            else
            {
                // Get request body
                AccountOpeningData data = await req.Content.ReadAsAsync <AccountOpeningData>();

                // Append a "created" event
                DateTime dateCreated            = DateTime.UtcNow;
                Account.Events.Opened evtOpened = new Account.Events.Opened()
                {
                    LoggedOpeningDate = dateCreated
                };
                if (!string.IsNullOrWhiteSpace(data.Commentary))
                {
                    evtOpened.Commentary = data.Commentary;
                }
                try
                {
                    await bankAccountEvents.AppendEvent(evtOpened,
                                                        streamConstraint : EventStreamExistenceConstraint.MustBeNew
                                                        );
                }
                catch (EventStreamWriteException exWrite)
                {
                    return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.Conflict,
                                                                 FunctionResponse.CreateResponse(startTime,
                                                                                                 true,
                                                                                                 $"Account {accountnumber} had a conflict error on creation {exWrite.Message }"),
                                                                 FunctionResponse.MEDIA_TYPE));
                }

                // If there is an initial deposit in the account opening data, append a "deposit" event
                if (data.OpeningBalance.HasValue)
                {
                    Account.Events.MoneyDeposited evtInitialDeposit = new Account.Events.MoneyDeposited()
                    {
                        AmountDeposited   = data.OpeningBalance.Value,
                        LoggedDepositDate = dateCreated,
                        Commentary        = "Opening deposit"
                    };
                    await bankAccountEvents.AppendEvent(evtInitialDeposit);
                }

                // If there is a beneficiary in the account opening data append a "beneficiary set" event
                if (!string.IsNullOrEmpty(data.ClientName))
                {
                    Account.Events.BeneficiarySet evtBeneficiary = new Account.Events.BeneficiarySet()
                    {
                        BeneficiaryName = data.ClientName
                    };
                    await bankAccountEvents.AppendEvent(evtBeneficiary);
                }

                return(req.CreateResponse <FunctionResponse>(System.Net.HttpStatusCode.Created,
                                                             FunctionResponse.CreateResponse(startTime,
                                                                                             false,
                                                                                             $"Account { accountnumber} created"),
                                                             FunctionResponse.MEDIA_TYPE));
            }
        }