protected void btndeposit_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                Accnum = Convert.ToInt32(ddlWithdraw.SelectedValue);

                using (BNS_DBContainer customer = new BNS_DBContainer())
                {
                    Account2 account = customer.Accounts.SingleOrDefault(x => x.AccountNumber == Accnum);
                    account.Balance -= Convert.ToDouble(txtamount.Text);

                    // Write Transaction to table
                    Transaction withdrawTransaction = new Transaction
                    {
                        Amount  = Convert.ToDouble(txtamount.Text),
                        Details = "Money was removed from account",
                        Date    = DateTime.Now.ToString(),
                        AccountAccountNumber = account.AccountNumber,
                        Type = "Withdrawal"
                    };
                    customer.Transactions.Add(withdrawTransaction);
                    customer.SaveChanges();
                }

                lblResult.Visible = true;
                lblResult.Text    = "Yay!! Money was withdrawed successfully.";
                ClearControls();
            }
        }
Exemple #2
0
        // Insert methods
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();
            var user          = new ApplicationUser()
            {
                UserName = tbEmail.Text, Email = tbEmail.Text
            };
            IdentityResult result = manager.Create(user, "Password123!");

            //userMgr.AddToRole(user.Id,ddlrrole.SelectedValue);
            if (result.Succeeded)
            {
                string   strnewUserId   = user.Id;
                Customer ScotiaCustomer = new Customer()
                {
                    CustomerID = strnewUserId,
                    Address    = tbAddress.Text,
                    FirstName  = tbFname.Text,
                    LastName   = tbLName.Text
                };
                AddUserToRole(tbEmail.Text, ddlrrole.SelectedValue);

                // Save additional fields to Customer Table
                BNS_DBContainer customer = new BNS_DBContainer();
                customer.Customers.Add(ScotiaCustomer);
                customer.SaveChanges();
                Response.Redirect(Request.RawUrl);
            }
            else
            {
                // ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            ApplicationDbContext context = new ApplicationDbContext();
            var             UserManager  = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));
            ApplicationUser currentUser  = UserManager.FindById(User.Identity.GetUserId());

            Account2 account = new Account2
            {
                AccountType_AccountTID = Convert.ToInt32(DDacc.SelectedValue),
                Balance            = 0.00,
                CustomerCustomerID = currentUser.Id
            };

            BNS_DBContainer customer = new BNS_DBContainer();

            customer.Accounts.Add(account);

            try
            {
                // Your code...
                // Could also be before try if you know the exception occurs in SaveChanges
                customer.SaveChanges();
                String        strConnString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
                SqlConnection con           = new SqlConnection(@strConnString);
                SqlCommand    cmd           = new SqlCommand("cardInsert", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("card", account.AccountNumber);

                con.Open();
                int k = cmd.ExecuteNonQuery();

                con.Close();
            }
            catch (DbEntityValidationException x)
            {
                foreach (var eve in x.EntityValidationErrors)
                {
                    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                      eve.Entry.Entity.GetType().Name, eve.Entry.State);
                    foreach (var ve in eve.ValidationErrors)
                    {
                        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                          ve.PropertyName, ve.ErrorMessage);
                    }
                }
                throw;
            }
            Response.Redirect("Transactions.aspx");
        }
        protected void CreateUser_Click(object sender, EventArgs e)
        {
            var manager       = Context.GetOwinContext().GetUserManager <ApplicationUserManager>();
            var signInManager = Context.GetOwinContext().Get <ApplicationSignInManager>();
            var user          = new ApplicationUser()
            {
                UserName = Email.Text, Email = Email.Text
            };
            IdentityResult result = manager.Create(user, Password.Text);

            if (result.Succeeded)
            {
                signInManager.SignIn(user, isPersistent: false, rememberBrowser: false);
                string   strCurrentUserId = user.Id;
                Customer ScotiaCustomer   = new Customer()
                {
                    CustomerID = strCurrentUserId,
                    Address    = tbAddress.Text,
                    FirstName  = tbFname.Text,
                    LastName   = tbLName.Text
                };

                BNS_DBContainer customer = new BNS_DBContainer();
                customer.Customers.Add(ScotiaCustomer);
                try
                {
                    customer.SaveChanges();
                }
                catch (DbEntityValidationException x)
                {
                    foreach (var eve in x.EntityValidationErrors)
                    {
                        Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                          eve.Entry.Entity.GetType().Name, eve.Entry.State);
                        foreach (var ve in eve.ValidationErrors)
                        {
                            Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                              ve.PropertyName, ve.ErrorMessage);
                        }
                    }
                    throw;
                }
                IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
            }
            else
            {
                ErrorMessage.Text = result.Errors.FirstOrDefault();
            }
        }
        private void TransferFunds(float amount, string billID)
        {
            using (BNS_DBContainer jpsAccount = new BNS_DBContainer())
            {
                Account2 accountInfo = jpsAccount.Accounts.SingleOrDefault(a => a.AccountNumber == 9190002);
                accountInfo.Balance = accountInfo.Balance + amount;


                Transaction jpsTransaction = new Transaction
                {
                    AccountAccountNumber = accountInfo.AccountNumber,
                    Amount  = amount,
                    Details = $"Payment for JPS Bill {billID}",
                    Type    = "Deposit",
                    Date    = DateTime.Now.ToString()
                };
                jpsAccount.Transactions.Add(jpsTransaction);
                jpsAccount.SaveChanges();
            }
        }
        public void getPayment(float amount, long cardNumber, string billID)
        {
            SqlConnection sqlConnection = new SqlConnection(ConnectionString);

            string qry = "Select AccountAccountNumber from CardNumbers where CardNum='" + cardNumber + "'";

            sqlConnection.Open();

            SqlCommand cmd = new SqlCommand(qry, sqlConnection);

            SqlDataReader reader;

            reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                accountNum = reader.GetInt32(0);
            }

            using (BNS_DBContainer customer = new BNS_DBContainer())
            {
                Account2 account = customer.Accounts.SingleOrDefault(x => x.AccountNumber == accountNum);
                account.Balance = account.Balance - amount;

                Transaction customerTransaction = new Transaction
                {
                    AccountAccountNumber = account.AccountNumber,
                    Amount  = amount,
                    Details = "Payment for JPS Bill " + billID,
                    Type    = "",
                    Date    = DateTime.Now.ToString()
                };

                TransferFunds(amount, billID);
                customer.SaveChanges();
            }
        }