Beispiel #1
0
        //uses LUIS to understand user query inteligently, and respond appropriately
        private async Task <Activity> NaturalInteractionHandler(Activity message)
        {
            if ((message.Text.Trim().ToLower() ?? "") == "")
            {
                return(message.CreateReply("Error: Message type unsupported"));
            }
            LUISHandler.LUISQueryResult LUISResult = await LUISHandler.HandleQuery(message.Text);

            switch (LUISResult.responseType)
            {
            case LUISHandler.ResponseType.ExchangeRate:
                return(await ExchangeRateHandler.HandleExchangeRateMessage(message, LUISResult));

            case LUISHandler.ResponseType.Logout:
                return(await FacebookHandler.LogoutHandler(message));

            case LUISHandler.ResponseType.None:
                return(await UnknownHandler(message));

            case LUISHandler.ResponseType.AccountBalance:
                return(await BankHandler.HandleBalance(message));

            case LUISHandler.ResponseType.MakePayment:
                return(await BankHandler.HandleTransaction(message, LUISResult));

            case LUISHandler.ResponseType.TransactionHistory:
                return(await BankHandler.HandleHistory(message));

            default:
                return(message.CreateReply("Error: Unimplemented"));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Executes the plug-in.
        /// </summary>
        /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the
        /// <see cref="IPluginExecutionContext"/>,
        /// <see cref="IOrganizationService"/>
        /// and <see cref="ITracingService"/>
        /// </param>
        /// <remarks>
        /// For improved performance, Microsoft Dynamics CRM caches plug-in instances.
        /// The plug-in's Execute method should be written to be stateless as the constructor
        /// is not called for every invocation of the plug-in. Also, multiple system threads
        /// could execute the plug-in at the same time. All per invocation state information
        /// is stored in the context. This means that you should not use global variables in plug-ins.
        /// </remarks>
        protected void ExecutePostBankCreate(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }

            IPluginExecutionContext context = localContext.PluginExecutionContext;
            IOrganizationService    service = localContext.OrganizationService;
            ITracingService         trace   = localContext.TracingService;
            Entity bankEntity = (Entity)context.InputParameters["Target"];

            string message = context.MessageName;
            string error   = "";

            Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null;

            try
            {
                BankHandler bankHandler = new BankHandler(service, trace);
                bankHandler.SetCity(bankEntity);
            }
            catch (Exception ex)
            {
                throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace, Environment.NewLine, error));
            }
        }
Beispiel #3
0
        public void GetBankAccountsTest()
        {
            var bh     = new BankHandler();
            var result = bh.GetBank(1);

            Assert.IsNotNull(result.Accounts);
        }
        public void WithdrawFromBalance_NullUserShouldThrowExeption()
        {
            // Arrange
            decimal balanceAdd = 1000;

            // Assert
            Assert.Throws <ArgumentException>("user", () => BankHandler.WithdrawFromBalance(null, (balanceAdd + 1)));
        }
        public void AddToBalance_NullUser()
        {
            // Arrange
            decimal balanceAdd = 10;

            // Act
            Assert.Throws <AuthenticationException>(() => BankHandler.AddToBalance(null, balanceAdd));
        }
        public void AddToBalance_InvalidDecimals(decimal balanceAdd)
        {
            // Arrange
            UserHandler user = new UserHandler();

            user.Login("1234");

            // Act
            Assert.Throws <InvalidOperationException>(() => BankHandler.AddToBalance(user.CurrentUser, balanceAdd));
        }
        public void ShowBalance_ValidUserShouldWork()
        {
            // Arrange
            string      pin         = "1234";
            UserHandler userHandler = new UserHandler();

            // Act
            userHandler.Login(pin);

            // Assert
            Assert.IsType <decimal>(BankHandler.ShowBalance(userHandler.CurrentUser));
        }
        public void AddToBalance_ValidUserDecimalTests(decimal balanceAdd)
        {
            // Arrange
            UserHandler user = new UserHandler();

            user.Login("1234");

            // Act
            var ex = Record.Exception(() => BankHandler.AddToBalance(user.CurrentUser, balanceAdd));

            // Assert
            Assert.Null(ex);
        }
        public void WithdrawFromBalance_CantWithdrawOverBalance(decimal balanceAdd)
        {
            // Arrange
            UserHandler user = new UserHandler();

            user.Login("1234");

            // Act
            user.CurrentUser.Account.Balance = balanceAdd;

            // Assert
            Assert.Throws <ArgumentException>("amount", () => BankHandler.WithdrawFromBalance(user.CurrentUser, (balanceAdd + 1)));
        }
        public void AddToBalance_ValidUserAndDecimalShouldWork()
        {
            // Arrange
            decimal     balanceAdd = 123312;
            UserHandler user       = new UserHandler();

            user.Login("1234");

            // Act
            var ex = Record.Exception(() => BankHandler.AddToBalance(user.CurrentUser, balanceAdd));

            // Assert
            Assert.Null(ex);
        }
        public void WithdrawFromBalance_ValidDecimals(decimal balanceAdd)
        {
            // Arrange
            UserHandler user = new UserHandler();

            user.Login("1234");

            // Act
            user.CurrentUser.Account.Balance = balanceAdd;

            var ex = Record.Exception(() => BankHandler.WithdrawFromBalance(user.CurrentUser, (balanceAdd - 1)));

            // Assert
            Assert.Null(ex);
        }
Beispiel #12
0
 public BanksForm(Bank bank, BankHandler handler)
 {
     this.InitializeComponent();
     this.set_Font(Manager.WindowFont);
     this.bankHandler = handler;
     if ((bank != null) && (bank != Bank.Null))
     {
         this.tbName.set_Text(bank.ShortName);
         this.mtbCode.set_Text(((long) bank.Code).ToString());
         this.mtbBIK.set_Text(bank.BIK);
         this.mtbLoro.set_Text(bank.LoroAccount.ToString());
         this.tbCity.set_Text(bank.City);
     }
     this.tsBtnSearch_Click(null, null);
     this.tsBtnSelect.set_Visible((bool) (this.selecting = true));
 }
Beispiel #13
0
        //Handle message as a confirmation or response to a bot query
        private async Task <Activity> ConfirmationHandler(Activity message)
        {
            StateClient stateClient = message.GetStateClient();
            BotData     userData    = await stateClient.BotState.GetUserDataAsync(message.ChannelId, message.From.Id);

            string pendingOn = userData.GetProperty <string>("Pending");

            switch (pendingOn)
            {
            case "Transaction":
                return(await BankHandler.CompletePendingTransaction(message));

            case "Logout":
                return(await FacebookHandler.HandlePendingLogout(message));

            default:
                userData.SetProperty <string>("Pending", null);
                await stateClient.BotState.SetUserDataAsync(message.ChannelId, message.From.Id, userData);

                return(message.CreateReply("Something went wrong, please try again"));
            }
        }
Beispiel #14
0
 // ---------------------------------------------------------------------
 void onBankCorrectionChanged()
 {
     bankHandler = bankCorrection ? (BankHandler)applyBankCorrectedInput : (BankHandler)applyBankInput;
 }
Beispiel #15
0
        // Creates a new client user
        public ActionResult CreateClient()
        {
            // Ensures logged in
            if (Session["loggedInState"] == null)
            {
                return(Redirect("/403.html"));
            }

            // Checks if logged in
            bool state = (bool)Session["loggedInState"];

            if (state == true)
            {
                // Establishes models
                ClientUserModel cModel = new ClientUserModel();

                // Establishes handlers
                AccountHandler  accHand = new AccountHandler();
                AddressHandler  addHand = new AddressHandler();
                BankHandler     banHand = new BankHandler();
                ContactHandler  conHand = new ContactHandler();
                CustomerHandler cusHand = new CustomerHandler();

                // Extract for account details
                int accountType = int.Parse(Request.Form["accountTypes"]);

                // Extract for bank details
                String sortCode      = Request.Form["sortCode"];
                int    accountNumber = int.Parse(Request.Form["accountNumber"]);

                // Extract for client details
                String username = Request.Form["username"];
                String password = Request.Form["password1"];
                String name     = Request.Form["clientName"];

                // Extract contact details
                String forename    = Request.Form["contactForename"];
                String surname     = Request.Form["contactSurname"];
                String position    = Request.Form["contactPosition"];
                String phoneNumber = Request.Form["contactPhone"];

                // Extract bank address details
                //String blineOne = Request.Form["bankL1"];
                //String blineTwo = Request.Form["bankL2"]; ;
                //String blineThree = Request.Form["bankL3"];
                //String blineFour = Request.Form["bankL4"];
                //String blineFive = Request.Form["bankL5"];
                //String bcState = Request.Form["bankState"];
                //String bcounty = Request.Form["bankCounty"];
                //String bcountry = Request.Form["bankCountry"];
                //String bpostalCode = Request.Form["bankPostalCode"];

                // Extract for customer details
                String compName = Request.Form["clientName"];

                // Extract customer address details
                String clineOne    = Request.Form["address1"];
                String clineTwo    = Request.Form["address2"];;
                String clineThree  = Request.Form["address3"];
                String clineFour   = Request.Form["address4"];
                String clineFive   = Request.Form["address5"];
                String ccState     = Request.Form["state"];
                String ccounty     = Request.Form["county"];
                String ccountry    = Request.Form["country"];
                String cpostalCode = Request.Form["postcode"];

                // Creates objects for user
                //int bankAddressID = addHand.create(blineOne, blineTwo, blineThree, blineFour, blineFive, bcState,
                //                                   bcounty, bcountry, bpostalCode);
                int custAddressID = addHand.create(clineOne, clineTwo, clineThree, clineFour, clineFive, ccState,
                                                   ccounty, ccountry, cpostalCode);
                int bankID     = banHand.create(sortCode, accountNumber);
                int contactID  = conHand.create(forename, surname, position, phoneNumber);
                int customerID = cusHand.create(compName, custAddressID);
                int accountID  = accHand.create(accountType, bankID, customerID, contactID);

                // Holds new objects
                ClientUser newClient = new ClientUser();

                // Acquires needed Account ID
                newClient.Username = username;


                // Stored details for the customer
                newClient.Name      = name;
                newClient.Username  = username;
                newClient.Password  = password;
                newClient.AccountID = accountID;

                // Creates the customer
                int clientID = cModel.CreateClientUser(newClient);

                // Return created department to view
                return(Redirect("/Index/adminIndex"));
            }
            else
            {
                // If not logged in
                return(Redirect("/login.html"));
            }
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            bool showMenu = true;

            do
            {
                bool showEnd = true;

                Console.Clear();

                Console.WriteLine("Bank ATM");
                ShowDivider();

                Console.WriteLine("1. Login");
                Console.WriteLine("2. Exit");

                char userInput = Console.ReadKey().KeyChar;

                if (userInput == '1')
                {
                    UserHandler userHandler   = new UserHandler();
                    bool        incorrectPin  = true;
                    byte        numberofTries = 0;

                    do
                    {
                        Console.Clear();
                        Console.Write("Pin: ");
                        string pinCode = Console.ReadLine();

                        if (userHandler.Login(pinCode))
                        {
                            incorrectPin = false;
                        }
                        else
                        {
                            if (numberofTries < 3)
                            {
                                numberofTries++;
                                Console.WriteLine($"Invalid Pin. Please try again. Try number {numberofTries} / 3");
                                Console.ReadKey();
                            }
                            else
                            {
                                Console.WriteLine($"Too many incorrect attempts. Closing application.");
                                showMenu = false;
                            }
                        }
                    } while (incorrectPin & showMenu);


                    // Main menu
                    if (userHandler.LoggedIn())
                    {
                        bool showMainMenu = true;
                        do
                        {
                            DisplayMainMenu();

                            userInput = Console.ReadKey().KeyChar;

                            switch (userInput)
                            {
                            // Show Balance
                            case '1':
                                Console.Clear();
                                Console.WriteLine("Here is your current balance:");
                                ShowDivider();
                                Console.WriteLine("   " + BankHandler.ShowBalance(userHandler.CurrentUser));

                                Console.WriteLine();
                                ShowContinue();

                                break;

                            // Add to Balance
                            case '2':
                                Console.Clear();
                                Console.WriteLine("Add to balance:");
                                ShowDivider();
                                Console.Write("   Add amount: ");

                                string addToBalanceUserInput = Console.ReadLine();

                                try
                                {
                                    BankHandler.AddToBalance(userHandler.CurrentUser, decimal.Parse(addToBalanceUserInput));
                                }
                                catch (Exception)
                                {
                                    Console.WriteLine();
                                    Console.WriteLine("An error ocured...");
                                    ShowContinue();
                                }


                                break;


                            // Withdraw from Balance
                            case '3':

                                Console.Clear();
                                Console.WriteLine("Withdraw from Balance:");
                                ShowDivider();
                                Console.Write("   Withdraw amount: ");

                                string withdrawFromBalanceUserInput = Console.ReadLine();

                                try
                                {
                                    BankHandler.WithdrawFromBalance(userHandler.CurrentUser, decimal.Parse(withdrawFromBalanceUserInput));
                                }
                                catch (Exception)
                                {
                                    Console.WriteLine();
                                    Console.WriteLine("An error ocured...");
                                    ShowContinue();
                                }

                                break;

                            case '4':

                                showMainMenu = false;
                                showEnd      = false;

                                break;

                            default:
                                break;
                            }
                        } while (showMainMenu);
                    }
                }
                else if (userInput == '2')
                {
                    showMenu = false;
                    showEnd  = false;
                }


                if (showEnd)
                {
                    ShowContinue();
                }
            } while (showMenu);
        }
 public void ShowBalance_NullUserShouldGiveExeption()
 {
     Assert.Throws <AuthenticationException>(() => BankHandler.ShowBalance(null));
 }