public List<AdminModel> GetAdminInformationByLastIdentity() { List<AdminModel> adminModels = new List<AdminModel>(); // int lastIdentity = GetLastIdentityOfAddedStudent(); string query = String.Format("SpGetAddedAdminInformation"); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString)) { using (SqlCommand command = new SqlCommand(query, connection)) { connection.Open(); SqlDataReader rdr = command.ExecuteReader(); while (rdr.Read()) { AdminModel adminModel = new AdminModel(); adminModel.Name = rdr[0].ToString(); adminModel.Phone = rdr[1].ToString(); adminModel.Email = rdr[2].ToString(); if (HttpContext.Current.Session["adminPassword"] != null) { adminModel.OnlyPassword = HttpContext.Current.Session["adminPassword"].ToString(); } adminModels.Add(adminModel); } connection.Close(); } } return adminModels; }
protected void saveAdminButton_Click(object sender, EventArgs e) { AdminModel adminModel = new AdminModel(); adminModel.Name = adminNameTextBox.Text; adminModel.Phone = phoneTextBox.Text; adminModel.Email = emailTextBox.Text; adminModel.AdminId = GetAdminId(adminModel.Email); adminModel.Salt = GenerateSalt(adminModel.AdminId); string passwordAdmin = GeneratePassword(); Session["adminPassword"] = passwordAdmin; adminModel.Password = GenerateHashValue(passwordAdmin, adminModel.Salt); adminModel.Type = 1; if (adminNameTextBox.Text.Length > 3 && adminNameTextBox.Text.Length < 40 && phoneTextBox.Text.Length < 20 && emailTextBox.Text.Length < 50) { if (adminBll.IsAdminExist(adminModel)) { failStatusLabel.InnerText = "Admin already exist"; successStatusLabel.InnerText = ""; } else { if (adminBll.SaveAdminInformation(adminModel) > 0) { Response.Redirect("CreatedAdmin.aspx"); //successStatusLabel.InnerText = "Admin information saved"; //failStatusLabel.InnerText = ""; } else { failStatusLabel.InnerText = "Not saved"; successStatusLabel.InnerText = ""; } } } else { failStatusLabel.InnerText = "Please enter the correct value"; } }
public List<AdminModel> GetAllAdmin() { List<AdminModel> adminModels = new List<AdminModel>(); string query = String.Format(@"select name,phone,email from tblAdmin"); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString)) { using (SqlCommand command = new SqlCommand(query, connection)) { connection.Open(); SqlDataReader rdr = command.ExecuteReader(); while (rdr.Read()) { AdminModel adminModel = new AdminModel(); adminModel.Name = rdr[0].ToString(); adminModel.Phone = rdr[1].ToString(); adminModel.Email = rdr[2].ToString(); adminModels.Add(adminModel); } connection.Close(); } } return adminModels; }
public int SaveAdminInformation(AdminModel adminModel) { int rowsInserted = 0; string query = String.Format(@"insert into tblAdmin values(@name,@phone,@email, @adminId, @salt, @password, @type)"); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString)) { using (SqlCommand command = new SqlCommand(query, connection)) { command.Parameters.Clear(); command.Parameters.AddWithValue("@name", adminModel.Name); command.Parameters.AddWithValue("@phone", adminModel.Phone); command.Parameters.AddWithValue("@email", adminModel.Email); command.Parameters.AddWithValue("@adminId", adminModel.AdminId); command.Parameters.AddWithValue("@salt", adminModel.Salt); command.Parameters.AddWithValue("@password", adminModel.Password); command.Parameters.AddWithValue("@type", adminModel.Type); connection.Open(); rowsInserted = command.ExecuteNonQuery(); connection.Close(); } } return rowsInserted; }
public bool IsAdminExist(AdminModel adminModel) { bool isAdminExist = false; string query = String.Format(@"select * from tblAdmin where name=@name and phone=@phone and email=@email"); using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings[1].ConnectionString)) { using (SqlCommand command = new SqlCommand(query,connection)) { command.Parameters.Clear(); command.Parameters.AddWithValue("@name", adminModel.Name); command.Parameters.AddWithValue("@phone", adminModel.Phone); command.Parameters.AddWithValue("@email", adminModel.Email); connection.Open(); SqlDataReader rdr = command.ExecuteReader(); while (rdr.Read()) { isAdminExist = true; } connection.Close(); } } return isAdminExist; }
public int SaveAdminInformation(AdminModel adminModel) { return adminDal.SaveAdminInformation(adminModel); }
public bool IsAdminExist(AdminModel adminModel) { return adminDal.IsAdminExist(adminModel); }