Example #1
0
        public bool FinishReg(Customer c)
        {
            bool res;
            CommonDAL commonDALObj = new CommonDAL();
            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ToString()))
            {
                string cmdtxt = String.Format("UPDATE Customer SET UserID = '{0}', Password = '******', CommunicationAddress = '{2}', TransactionPassword = '******', PhotoIDProof = '{4}' WHERE CustomerID = {5}", c.UserID, commonDALObj.GetHashedText(c.Password), c.CommunicationAddress, commonDALObj.GetHashedText(c.TransactionPassword), c.PhotoIDProof, c.CustomerID);

                SqlCommand command = new SqlCommand(cmdtxt, connection);
                connection.Open();
                int rowaff = command.ExecuteNonQuery();

                // Call Read before accessing data.
                if (rowaff == 0)
                    res = false;
                else
                    res = true;

                command.CommandText = String.Format("SELECT MAX(Id) FROM UserRoles ");

                SqlDataReader rd = command.ExecuteReader();
                rd.Read();
                int id = Convert.ToInt16(rd[0]) + 1;
                rd.Close();

                command.CommandText = String.Format("INSERT INTO UserRoles VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', 'A') ", id, c.UserID, commonDALObj.GetHashedText(c.Password), "Customer", DateTime.Now.ToString(), "0");
                command.ExecuteNonQuery();

            }

            return res;
        }
Example #2
0
        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;
        }
Example #3
0
        public Customer GetUserByTokenID(string token)
        {
            Customer c = new Customer();

            using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Database1ConnectionString"].ToString()))
            {
                SqlCommand command = new SqlCommand(String.Format("SELECT * FROM Customer WHERE Token = '{0}' ", token), connection);
                connection.Open();

                SqlDataReader reader = command.ExecuteReader();

                // Call Read before accessing data.
                if (reader.HasRows)
                {
                    reader.Read();
                    c.CustomerID = Convert.ToInt64(reader[0]);
                    c.CustomerName = String.Copy(reader[1].ToString());
                    c.DOB = Convert.ToDateTime(reader[2].ToString());
                    c.PermanentAddress = String.Copy(reader[5].ToString());
                    c.ContactNumber = String.Copy(reader[7].ToString());
                    c.Email = String.Copy(reader[8].ToString());
                }

                else
                    System.Windows.Forms.MessageBox.Show("Could Not access Customer Table !");

                reader.Close();
            }

            return c;
        }
Example #4
0
        public ActionResult FinishRegistration(Customer model, HttpPostedFileBase Image)
        {
            //MessageBox.Show("I am in POST");
            CustomerDAL obj = new CustomerDAL();

            if (obj.IsUniqueUserID(model.UserID) && ModelState.IsValid)
            {
                if (Image != null)
                {
                   // product.ImageMimeType = image.ContentType;
                    model.PhotoIDProof = new byte[Image.ContentLength];
                    Image.InputStream.Read(model.PhotoIDProof, 0, Image.ContentLength);
                }
                obj.FinishReg(model);
                return RedirectToAction("Login", "CommonBiz");
            }
            else
            {
                ModelState.AddModelError("", "User Id not available");
                return View(model);
            }
        }