コード例 #1
0
ファイル: BankerDAL.cs プロジェクト: IBIBank/IBITest
        public TokenInfo GenerateToken(GenerateTokenViewModel tv)
        {
            Customer c = new Customer();
            TokenInfo res = new TokenInfo();

            c.CustomerName = String.Copy(tv.CustomerName);
            c.DOB = tv.DOB;
            c.PermanentAddress = String.Copy(tv.PermanentAddress);
            c.ContactNumber = String.Copy(tv.ContactNumber);
            c.Email = String.Copy(tv.Email);

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ToString()))
            {
                SqlCommand command = new SqlCommand("SELECT MAX(CustomerID) FROM Customer", connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();
                reader.Read();

                // Call Read before accessing data.
                if (!reader.IsDBNull(0))
                {
                    c.CustomerID = Convert.ToInt64(reader[0]) + 1;
                }

                else
                    c.CustomerID = 1001;

                reader.Close();
            }

            Random rnd = new Random();
            int num = rnd.Next(9999);
            c.Token = String.Copy("IBI" + c.CustomerID + num);

            c.UserID = null;
            c.Password = null;
            c.CommunicationAddress = null;
            c.TransactionPassword = null;
            c.PhotoIDProof = null;

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ToString()))
            {
                SqlCommand command = new SqlCommand(String.Format("INSERT INTO Customer VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}')", c.CustomerID, c.CustomerName, c.DOB, c.UserID,c.Password, c.PermanentAddress, c.CommunicationAddress, c.ContactNumber, c.Email, c.TransactionPassword, c.Token, c.PhotoIDProof), connection);
                connection.Open();

                int rowsaffected = command.ExecuteNonQuery();

                // Call Read before accessing data.
                if (rowsaffected > 0)
                {
                    res.CustomerID = c.CustomerID;
                    res.Token = String.Copy(c.Token);

                }
                else
                    res.Token = String.Copy("Error");
            }

            return res;
        }
コード例 #2
0
ファイル: BankerController.cs プロジェクト: IBIBank/IBITest
        public ActionResult GenerateToken(GenerateTokenViewModel model)
        {
            if (!ModelState.IsValid)
                return View(model);

            BankerDAL obj = new BankerDAL();
            TokenInfo tf = new TokenInfo();

            tf = obj.GenerateToken(model);

            ViewBag.CustomerID = String.Format("Customer ID : {0}", tf.CustomerID);
            ViewBag.token = String.Format("Token : {0}", tf.Token);

            ModelState.Clear();
            return View(new GenerateTokenViewModel());
        }