public List<UserAccount> GetUserByType(string type)
        {
            List<UserAccount> userList = new List<UserAccount>();
            SqlConnection connection = new SqlConnection(connectionString);
            string query = "Select * From UserAccount where UserType='" + type + "'";
            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                UserAccount account=new UserAccount();

                account.UserId = reader["UserID"].ToString();
                account.UserType = reader["UserType"].ToString();
                account.UserName= reader["UserName"].ToString();
                account.Email = reader["Email"].ToString();
                account.Contact = reader["ContactNo"].ToString();

                userList.Add(account);

            }
            reader.Close();
            connection.Close();
            return userList;
        }
 public string Save(UserAccount aUserAccount)
 {
     if (aGateway.IsUserIdExists(aUserAccount))
     {
         return "User ID is already Exixts !!";
     }
     else
     {
         if (aGateway.Save(aUserAccount)>0)
         {
             return "Successfully Inserted !";
         }
         else
         {
             return "Insertion Failed!!";
         }
     }
 }
        protected void saveButton_Click(object sender, EventArgs e)
        {
            aManager=new ManagerManager();
            if (userIdTextBox.Text==""||userNameTextBox.Text==""||typeDropDownList.SelectedItem.Text==""||userPassTextBox.Text=="")
            {
                msgLabel.Text = "please enter the value";
            }
            else
            {
                account=new UserAccount();

                account.UserId = userIdTextBox.Text;
                account.UserName = userNameTextBox.Text;
                account.UserType = typeDropDownList.SelectedItem.Text;
                account.Password = userPassTextBox.Text;

                msgLabel.Text = aManager.Save(account);

                GridView1.Visible = true;
                PopulateGridView();
                ClearTextBox();
            }
        }
        public bool IsUserIdExists(UserAccount aUserAccount)
        {
            bool isUserIdExists = false;
            SqlConnection connection = new SqlConnection(connectionString);
            string query = "Select UserID  From UserAccount Where UserID='" + aUserAccount.UserId + "'";
            SqlCommand command = new SqlCommand(query, connection);
            connection.Open();
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {

                isUserIdExists = true;
                break;
            }
            reader.Close();
            connection.Close();
            return isUserIdExists;
        }
 public int Save(UserAccount aUserAccount)
 {
     string query = string.Format(@"INSERT INTO UserAccount VALUES('{0}','{1}','{2}','{3}','{4}','{5}')", aUserAccount.UserId, aUserAccount.UserType, aUserAccount.UserName, aUserAccount.Password, aUserAccount.Email, aUserAccount.Contact);
     SqlConnection connection = new SqlConnection(connectionString);
     SqlCommand command = new SqlCommand(query, connection);
     connection.Open();
     int rowAffected = command.ExecuteNonQuery();
     connection.Close();
     return rowAffected;
 }