//reterving information of login user public IEnumerable <user_info> getuserdetail(string username, string password, string usertype) { string decryptedpassword = Encryptpassword(password); open(); string query = "select * from user_info where username ='******' and password = '******' and usertype = '" + usertype + "'"; List <user_info> userdetail = new List <user_info>(); SqlCommand cmd = new SqlCommand(query, con); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { if (usertype == "teacher") { var userdetails = new user_info { id = dr.GetInt32(0), firstName = dr.GetString(2), lastName = dr.GetString(3), username = dr.GetString(1), schoolid = dr.GetInt32(8), courseid = dr.GetInt32(9) }; userdetail.Add(userdetails); } else { var userdetails = new user_info { id = dr.GetInt32(0), firstName = dr.GetString(2), lastName = dr.GetString(3), username = dr.GetString(1), schoolid = dr.GetInt32(8) }; userdetail.Add(userdetails); } } } return(userdetail); close(); }
public int editTeacher(user_info teacherdetail) { open(); SqlCommand cmd = new SqlCommand("IUD_teacher", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Action", "Update"); cmd.Parameters.AddWithValue("@id", teacherdetail.id); cmd.Parameters.AddWithValue("@firstname", teacherdetail.firstName); cmd.Parameters.AddWithValue("@lastname", teacherdetail.lastName); cmd.Parameters.AddWithValue("@schoolid", teacherdetail.schoolid); var res = 0; try { res = cmd.ExecuteNonQuery(); } catch (Exception Ex) { string s = Ex.Message; return(0); } return(res); close(); }
//displahing teacher public IEnumerable <user_info> displayteacher(int schoolid, bool edit, int id) { open(); string query; if (edit != true) { query = "select * from user_info where usertype='teacher' and schoolid=" + schoolid; } else { query = "select * from user_info where usertype='teacher' and schoolid=" + schoolid + " and id=" + id; } List <user_info> lstTeachers = new List <user_info>(); SqlCommand cmd = new SqlCommand(query, con); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { var teacher = new user_info { id = dr.GetInt32(0), firstName = dr.GetString(2), lastName = dr.GetString(3), password = dr.GetString(4), username = dr.GetString(1), schoolid = dr.GetInt32(8) }; lstTeachers.Add(teacher); } } return(lstTeachers); close(); }
//adding teacher public int Insertuser(user_info teacherdetail, string usertype) { string password = Encryptpassword(teacherdetail.password); open(); SqlCommand cmd = new SqlCommand("IUD_teacher", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Action", "INSERT"); cmd.Parameters.AddWithValue("@firstname", teacherdetail.firstName); cmd.Parameters.AddWithValue("@lastname", teacherdetail.lastName); cmd.Parameters.AddWithValue("@username", teacherdetail.username); cmd.Parameters.AddWithValue("@password", password); switch (usertype) { case "teacher": cmd.Parameters.AddWithValue("@usertype", "Teacher"); cmd.Parameters.AddWithValue("@course", teacherdetail.courseid); break; case "schooladmin": cmd.Parameters.AddWithValue("@usertype", "Schooladmin"); cmd.Parameters.AddWithValue("@course", 0); break; case "student": cmd.Parameters.AddWithValue("@usertype", "Student"); cmd.Parameters.AddWithValue("@course", 0); break; } cmd.Parameters.AddWithValue("@schoolid", teacherdetail.schoolid); int res = 0; try { res = cmd.ExecuteNonQuery(); } catch (Exception ex) { string s = ex.Message; throw; } return(res); close(); }
//adding student public int insertStudent(user_info studentdetail) { open(); SqlCommand cmd = new SqlCommand("IUD_teacher", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Action", "INSERT"); cmd.Parameters.AddWithValue("@firstname", studentdetail.firstName); cmd.Parameters.AddWithValue("@lastname", studentdetail.lastName); cmd.Parameters.AddWithValue("@username", studentdetail.username); cmd.Parameters.AddWithValue("@password", studentdetail.password); cmd.Parameters.AddWithValue("@usertype", "Student"); cmd.Parameters.AddWithValue("@schoolid", studentdetail.schoolid); int res = 0; res = cmd.ExecuteNonQuery(); return(res); close(); }
//displaying student public IEnumerable <user_info> displaystudent(int schoolid) { open(); string query = "select * from user_info where usertype='student' and schoolid='" + schoolid + "'"; List <user_info> lstStudent = new List <user_info>(); SqlCommand cmd = new SqlCommand(query, con); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { var student = new user_info { id = dr.GetInt32(0), firstName = dr.GetString(2), lastName = dr.GetString(3), username = dr.GetString(1), schoolid = dr.GetInt32(8) }; lstStudent.Add(student); } } return(lstStudent); close(); }