Example #1
0
    public bool TransferChkToSavViaSP(string chkAcctNum, string savAcctNum,
                                      double amt)
    {
        bool res = false;

        try
        {
            string sql  = "SPXferChkToSav"; // name of SP
            int    rows = _idataAccess.TransferViaSP(chkAcctNum, savAcctNum, amt, sql);
            if (rows > 0)
            {
                res = true;
            }
            else
            {
                res = false;
            }

            // clear cache for TransferHistory
            string key = String.Format("TransferHistory_{0}",
                                       chkAcctNum);
            webCache.Remove(key);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return(res);
    }
        public bool UpdateProduct(ProductModel product)
        {
            bool bRes = false;

            try
            {
                string sql1 = "update Products set CatID=@catID, ProductSDesc=@ProductSDesc, ProductLDesc=@ProductLDesc,"
                              + "Price=@Price, Inventory=@Inventory where ProductId=@prodId";
                List <DbParameter> PList1 = new List <DbParameter>();
                DbParameter        p1a    = new SqlParameter("@catID", SqlDbType.Int);
                p1a.Value = product.CatagoryID;
                PList1.Add(p1a);

                DbParameter p2a = new SqlParameter("@ProductSDesc", SqlDbType.VarChar, 50);
                p2a.Value = product.ShortDesc;
                PList1.Add(p2a);

                DbParameter p3a = new SqlParameter("@ProductLDesc", SqlDbType.Text);
                p3a.Value = product.LongDesc;
                PList1.Add(p3a);

                DbParameter p4a = new SqlParameter("@Price", SqlDbType.Money);
                p4a.Value = product.Price;
                PList1.Add(p4a);

                DbParameter p5a = new SqlParameter("@Inventory", SqlDbType.Int);
                p5a.Value = product.Inventory;
                PList1.Add(p5a);

                DbParameter p6a = new SqlParameter("@prodId", SqlDbType.Int);
                p6a.Value = product.ProductID;
                PList1.Add(p6a);

                bRes = idataAccess.InsOrUpdOrDel(sql1, PList1) > 0 ? true : false;
                if (bRes)
                {
                    string key = String.Format("Product_{0}", product.ProductID);
                    cache.Remove(key);
                    key = String.Format("Products_{0}", product.CatagoryID);
                    cache.Remove(key);
                    key = "Products_";
                    cache.Remove(key);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(bRes);
        }
Example #3
0
        public bool TransferSavingToChecking(long checkingAccountNum, long savingAccountNum, decimal amount, decimal transactionFee)
        {
            // transfer saving to checking has to be done as a transaction
            // transactions are assocated with a connection
            bool           ret     = false;
            string         CONNSTR = ConfigurationManager.ConnectionStrings["MYBANK"].ConnectionString;
            SqlConnection  conn    = new SqlConnection(CONNSTR);
            SqlTransaction sqtr    = null;

            try
            {
                conn.Open();
                sqtr = conn.BeginTransaction();
                int rows = UpdateSavingBalanceTR(savingAccountNum, -1 * amount, conn, sqtr, true);
                if (rows == 0)
                {
                    throw new Exception("Problem in transferring from Checking Account..");
                }

                object obj = GetSavingBalanceTR(savingAccountNum, conn, sqtr, true);
                if (obj != null)
                {
                    if (decimal.Parse(obj.ToString()) < 0)  // exception causes transaction to be rolled back
                    {
                        throw new Exception("Insufficient funds in Checking Account - rolling back transaction");
                    }
                }

                rows = UpdateCheckingBalanceTR(checkingAccountNum, amount, conn, sqtr, true);
                if (rows == 0)
                {
                    throw new Exception("Problem in transferring to Saving Account..");
                }
                string transtype = "SavingToChecking";
                rows = AddToTransactionHistoryTR(checkingAccountNum, savingAccountNum, amount, transtype, 101, transactionFee, conn, sqtr, true);

                if (rows == 0)
                {
                    throw new Exception("Problem in transferring to Saving Account..");
                }
                else
                {
                    sqtr.Commit();
                    ret = true;
                    // clear the cache
                    CacheAbstraction cabs = new CacheAbstraction();
                    cabs.Remove("TRHISTORY");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(ret);
        }
Example #4
0
        public bool payBill(long checkingAccountNum, int billId, decimal?amount)
        {
            bool           res     = false;
            string         CONNSTR = ConfigurationManager.ConnectionStrings["MYBANK"].ConnectionString;
            SqlConnection  conn    = new SqlConnection(CONNSTR);
            SqlTransaction sqtr    = null;

            try
            {
                conn.Open();
                sqtr = conn.BeginTransaction();
                int rows = UpdateCheckingBalanceTR(checkingAccountNum, -1 * (decimal)amount, conn, sqtr, true);
                if (rows == 0)
                {
                    throw new Exception("Problem in transferring from Checking Account..");
                }

                object obj = GetCheckingBalanceTR(checkingAccountNum, conn, sqtr, true);
                if (obj != null)
                {
                    if (decimal.Parse(obj.ToString()) < 0)  // exception causes transaction to be rolled back
                    {
                        throw new Exception("Insufficient funds in Checking Account - rolling back transaction");
                    }

                    int result = 0;

                    result = AddToTransactionHistoryTR(checkingAccountNum, billId, (decimal)amount, 102, 0, conn, sqtr, true); //102 for tanstype for billpay

                    if (result > 0)
                    {
                        result = UpdateBillsPaymentStatus(billId, conn, sqtr, true);
                        sqtr.Commit();
                        res = true;
                        // clear the cache
                        CacheAbstraction cabs = new CacheAbstraction();
                        cabs.Remove("TRHISTORY");
                    }
                    else
                    {
                        throw new Exception("Error in Updating the transaction history");
                    }
                }
                else
                {
                    throw new Exception("Error in Updating the checking Balance");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }

            return(res);
        }
Example #5
0
    public bool TransferChkToSavViaSP(string chkAcctNum, string savAcctNum,
                                      double amt)
    {
        string        CONNSTR = ConfigurationManager.ConnectionStrings["BANKDBCONN"].ConnectionString;
        bool          res     = false;
        SqlConnection conn    = new SqlConnection(CONNSTR);

        try
        {
            conn.Open();
            string       sql = "SPXferChkToSav"; // name of SP
            SqlCommand   cmd = new SqlCommand(sql, conn);
            SqlParameter p1  = new SqlParameter("@ChkAcctNum",
                                                System.Data.SqlDbType.VarChar, 50);

            cmd.CommandType = System.Data.CommandType.StoredProcedure;
            p1.Value        = chkAcctNum;
            cmd.Parameters.Add(p1);
            SqlParameter p2 = new SqlParameter("@SavAcctNum",
                                               System.Data.SqlDbType.VarChar, 50);
            p2.Value = savAcctNum;
            cmd.Parameters.Add(p2);
            SqlParameter p3 = new SqlParameter("@amt",
                                               System.Data.SqlDbType.Money);
            p3.Value = amt;
            cmd.Parameters.Add(p3);
            int rows = cmd.ExecuteNonQuery();
            if (rows == 3)
            {
                res = true;
            }

            // clear cache for TransferHistory
            string key = String.Format("TransferHistory_{0}",
                                       chkAcctNum);
            webCache.Remove(key);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return(res);
    }
Example #6
0
        public ActionResult Login(LoginModel lm)
        {
            IBusinessAuthentication iba = GenericFactory <Business, IBusinessAuthentication> .GetInstance();

            IBusinessBanking ibank = GenericFactory <Business, IBusinessBanking> .GetInstance();

            IBusinessLoan iloan = GenericFactory <Business, IBusinessLoan> .GetInstance();

            if (ModelState.IsValid)
            {
                // check if valid user
                bool ret = iba.CheckIfValidUser(lm.Username, lm.Password);
                if (ret == true)
                {
                    string roles = iba.GetRolesForUser(lm.Username);
                    // send the pipedelimited roles as an authentication cookie back to the browser
                    FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, lm.Username, DateTime.Now, DateTime.Now.AddMinutes(15), false, roles);
                    string     encryptedTicket           = FormsAuthentication.Encrypt(authTicket);
                    HttpCookie ck = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    Response.Cookies.Add(ck);
                    // ----obtaing checking account number and saving account number for user
                    long     checkingAccountNum  = ibank.GetCheckingAccountNumForUser(lm.Username);
                    long     savingAccountNumber = ibank.GetSavingAccountNumForUser(lm.Username);
                    UserInfo ui = new UserInfo();
                    ui.CheckingAcccountNumber = checkingAccountNum;
                    ui.SavingAccountNumber    = savingAccountNumber;
                    ui.Username = lm.Username;
                    //HttpCookie ckuser = new HttpCookie("UserInfo");
                    //ckuser["USERDATA"] = ui.LosSerialize();
                    //Response.Cookies.Add(ckuser);
                    CookieFacade.USERINFO = ui;
                    CacheAbstraction cabs = new CacheAbstraction();
                    cabs.Remove("TRHISTORY" + ":" + checkingAccountNum);
                    //----------------------------------------------------
                    string redirectURL = FormsAuthentication.GetRedirectUrl(lm.Username, false);
                    if (redirectURL == "/default.aspx")
                    {
                        redirectURL = "~/home/index";
                    }
                    //Response.Redirect(redirectURL);
                    // causes antiforgery token exception
                    return(Redirect(redirectURL));
                }
                ViewBag.Message = "Invalid login..";
            }
            return(View(lm));
        }
Example #7
0
        public bool ApplyLoan(long checkingAccountNum, long savingAccountNum, decimal amount, string username, decimal transactionFee)
        {
            // apply loan by a user has to be done as a transaction
            // transactions are assocated with a connection
            bool           ret     = false;
            string         CONNSTR = ConfigurationManager.ConnectionStrings["MYBANK"].ConnectionString;
            SqlConnection  conn    = new SqlConnection(CONNSTR);
            SqlTransaction sqtr    = null;

            try
            {
                conn.Open();
                sqtr = conn.BeginTransaction();
                string roles = GetRolesForUser(username);
                int    rows  = UpdateStatusTR(checkingAccountNum, roles, username, conn, sqtr, true);

                if (rows == 0)
                {
                    throw new Exception("Problem in appyling the loan..");
                }
                string TransType = "Apply Loan";
                rows = AddToTransactionHistoryTR(checkingAccountNum, savingAccountNum, amount, TransType, 103, transactionFee, conn, sqtr, true);

                if (rows == 0)
                {
                    throw new Exception("Problem in appyling the loan..");
                }
                else
                {
                    sqtr.Commit();
                    ret = true;
                    // clear the cache
                    CacheAbstraction cabs = new CacheAbstraction();
                    cabs.Remove("TRHISTORY");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(ret);
        }
Example #8
0
        public bool LoanApproval(long checkingAccountNum, long savingAccountNum, decimal amount, List <string> Username, decimal transactionFee)
        {
            // transfer checking to saving has to be done as a transaction
            // transactions are assocated with a connection
            bool           ret     = false;
            string         CONNSTR = ConfigurationManager.ConnectionStrings["MYBANK"].ConnectionString;
            SqlConnection  conn    = new SqlConnection(CONNSTR);
            SqlTransaction sqtr    = null;

            try
            {
                conn.Open();
                sqtr = conn.BeginTransaction();
                int rows = UpdateLoanApprovalStatusTR(checkingAccountNum, Username, conn, sqtr, true);
                if (rows == 0)
                {
                    throw new Exception("Problem in updating loan status..");
                }
                string TransType = "Loan Approval";
                rows = AddToTransactionHistoryTR(checkingAccountNum, savingAccountNum, amount, TransType, 100, transactionFee, conn, sqtr, true);

                if (rows == 0)
                {
                    throw new Exception("Problem in updating to Transaction history for the loan status..");
                }
                else
                {
                    sqtr.Commit();
                    ret = true;
                    // clear the cache
                    CacheAbstraction cabs = new CacheAbstraction();
                    cabs.Remove("TRHISTORY");
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
            return(ret);
        }
Example #9
0
    public bool TransferChkToSav(string chkAcctNum, string savAcctNum, double amt)
    {
        bool           res         = false;
        string         CONNSTR     = ConfigurationManager.ConnectionStrings["BANKDBCONN"].ConnectionString;
        SqlConnection  conn        = new SqlConnection(CONNSTR);
        SqlTransaction Transection = null;

        try
        {
            conn.Open();
            Transection = conn.BeginTransaction();
            DbParameter p1 = new SqlParameter("@chkAcctNum", SqlDbType.VarChar, 50);
            p1.Value = chkAcctNum;
            string sql1 = "update  CheckingAccounts set balance=balance-" +
                          amt.ToString() + " where checkingaccountnumber=@chkAcctNum";
            SqlCommand cmd1 = new SqlCommand(sql1, conn);
            cmd1.Parameters.Add(p1);
            cmd1.Transaction = Transection;
            int rows = cmd1.ExecuteNonQuery();

            string      sql2 = "select balance from CheckingAccounts where CheckingAccountNumber=@chkAcctNum";
            DbCommand   cmd2 = new SqlCommand(sql2, conn);
            DbParameter p2   = new SqlParameter("@chkAcctNum", SqlDbType.VarChar, 50);
            p2.Value = chkAcctNum;
            cmd2.Parameters.Add(p2);
            cmd2.Transaction = Transection;
            object obal = cmd2.ExecuteScalar();
            if (double.Parse(obal.ToString()) < 0)
            {
                throw new Exception("Amount cannot be transferred - results in negative balance..");
            }

            string sql3 = "update  SavingAccounts set balance=balance+" +
                          amt.ToString() + " where SavingAccountnumber=@savAcctNum";
            SqlCommand  cmd3 = new SqlCommand(sql3, conn);
            DbParameter p1a  = new SqlParameter("@savAcctNum", SqlDbType.VarChar, 50);
            p1a.Value = savAcctNum;
            cmd3.Parameters.Add(p1a);
            cmd3.Transaction = Transection;
            rows             = cmd3.ExecuteNonQuery();

            string sql4 = "insert into TransferHistory(FromAccountNum,ToAccountNum,Amount," +
                          "CheckingAccountNumber) values (@chkAcctNum,@savAcctNum,@amt,@chkAcctNum)";
            SqlCommand  cmd4 = new SqlCommand(sql4, conn);
            DbParameter p4a  = new SqlParameter("@chkAcctNum", SqlDbType.VarChar, 50);
            p4a.Value = chkAcctNum;
            cmd4.Parameters.Add(p4a);
            DbParameter p4b = new SqlParameter("@savAcctNum", SqlDbType.VarChar, 50);
            p4b.Value = savAcctNum;
            cmd4.Parameters.Add(p4b);
            DbParameter p4c = new SqlParameter("@amt", SqlDbType.Decimal, 20);
            p4c.Value = amt;
            cmd4.Parameters.Add(p4c);
            cmd4.Transaction = Transection;
            rows             = cmd4.ExecuteNonQuery();
            Transection.Commit();
            res = true;

            // clear cache for TransferHistory
            string key = String.Format("TransferHistory_{0}",
                                       chkAcctNum);
            webCache.Remove(key);
        }
        catch (Exception ex)
        {
            if (Transection != null)
            {
                Transection.Rollback();
            }
            throw ex;
        }
        finally
        {
            if (Transection != null)
            {
                Transection.Dispose();
            }
        }

        return(res);
    }