public dynamic GetAllTeacher() { Query = "SELECT * FROM Teacher"; Command = new SqlCommand(Query, Connection); Connection.Open(); Reader = Command.ExecuteReader(); List <SaveTeacher> aSaveTeachers = new List <SaveTeacher>(); while (Reader.Read()) { SaveTeacher aSaveTeacher = new SaveTeacher(); aSaveTeacher.Id = (int)Reader["Id"]; aSaveTeacher.Name = Reader["TeacherName"].ToString(); aSaveTeacher.Address = Reader["Address"].ToString(); aSaveTeacher.ContactNo = (string)Reader["ContactNo"]; aSaveTeacher.DepartmentId = (int)Reader["DepartmentId"]; aSaveTeacher.Designation = Reader["Designation"].ToString(); aSaveTeacher.CraditToBeTaken = (decimal)Reader["CreditToBeTaken"]; aSaveTeacher.CraditToRemain = (decimal)Reader["RemainCredit"]; aSaveTeacher.Email = (string)Reader["Email"]; aSaveTeachers.Add(aSaveTeacher); } Connection.Close(); return(aSaveTeachers); }
public ActionResult Saveteacher(SaveTeacher saveTeacher) { ViewBag.saveReport = aSaveTeacherManager.SaveTeacher(saveTeacher); ViewBag.Department = aSaveTeacherManager.TakeAllDeparment(); return(View()); }
public dynamic GetTeacher(int id) { Query = "SELECT * FROM Teacher WHERE DepartmentId = @id"; Command = new SqlCommand(Query, Connection); Command.Parameters.Add("id", SqlDbType.VarChar); Command.Parameters["id"].Value = id; Connection.Open(); Reader = Command.ExecuteReader(); List <SaveTeacher> aSaveTeachers = new List <SaveTeacher>(); if (Reader.HasRows) { SaveTeacher aSaveTeacher = new SaveTeacher(); aSaveTeacher.Id = 0; aSaveTeacher.Name = "Not Found"; aSaveTeachers.Add(aSaveTeacher); } else { while (Reader.Read()) { SaveTeacher aSaveTeacher = new SaveTeacher(); aSaveTeacher.Id = (int)Reader["Id"]; aSaveTeacher.Name = (string)Reader["Name"]; aSaveTeachers.Add(aSaveTeacher); } } Connection.Close(); return(aSaveTeachers); }
public List <SaveTeacher> GetAllteacherDetais(int id) { SqlConnection connection = new SqlConnection(); connection.ConnectionString = connectionString; SqlCommand command = new SqlCommand(); command.Connection = connection; command.CommandText = "SELECT * FROM SaveTeacher WHERE Id=" + id; connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <SaveTeacher> teachers = new List <SaveTeacher>(); while (reader.Read()) { SaveTeacher teacher = new SaveTeacher { Id = (int)reader["Id"], Name = reader["Name"].ToString(), Credit = (double)reader["Credit"], RemainingCredit = (double)reader["RemainingCredit"] }; teachers.Add(teacher); } reader.Close(); connection.Close(); return(teachers); }
public ActionResult Index(SaveTeacher aTeacher) { ViewBag.Message = _saveTeacherManager.Save(aTeacher); ViewBag.Departments = _departmentManager.GetAllDepartment(); ViewBag.Designations = _designationTeacherManager.GetAllDesignation(); return(View()); }
public bool Check(SaveTeacher aTeacher) { var connection = new SqlConnection(connectionString); var command = new SqlCommand(); command.CommandText = "SELECT * FROM SaveTeacher WHERE Email='" + aTeacher.Email + "'"; command.Connection = connection; connection.Open(); SqlDataReader reader = command.ExecuteReader(); return(reader.HasRows); }
public string Save(SaveTeacher aTeacher) { if (_saveTeacherGateway.Check(aTeacher)) { return("Your email already exists"); } if (aTeacher.Credit < 0) { return("Credit must be a positive number"); } string result = _saveTeacherGateway.Save(aTeacher); return(result); }
public int Save(SaveTeacher saveTeacher) { string query = "Insert into SaveTeacher Values(@teacherName,@address,@email,@contact,@designationId,@deptId,@credit)"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@teacherName", saveTeacher.TeacherName); command.Parameters.AddWithValue("@address", saveTeacher.Address); command.Parameters.AddWithValue("@email", saveTeacher.Email); command.Parameters.AddWithValue("@contact", saveTeacher.Contact); command.Parameters.AddWithValue("@designationId", saveTeacher.DesignationId); command.Parameters.AddWithValue("@deptId", saveTeacher.DeptId); command.Parameters.AddWithValue("@credit", saveTeacher.Credit); connection.Open(); int rowAffect = command.ExecuteNonQuery(); connection.Close(); return(rowAffect); }
public string Save(SaveTeacher aTeacher) { SqlConnection con = new SqlConnection(connectionString); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "INSERT INTO SaveTeacher (Name, Address, Email, ContactNo, DesignationId, DepartmentId, Credit, RemainingCredit) VALUES ('" + aTeacher.Name + "','" + aTeacher.Address + "','" + aTeacher.Email + "','" + aTeacher.ContactNo + "'" + ",'" + aTeacher.DesignationId + "','" + aTeacher.DepartmentId + "','" + aTeacher.Credit + "','" + aTeacher.Credit + "')"; cmd.CommandType = CommandType.Text; cmd.Connection = con; con.Open(); int rowAffected = cmd.ExecuteNonQuery(); con.Close(); if (rowAffected > 0) { return("New Teacher inserted"); } return("Teacher not inserted"); }
public SaveTeacher GetTeacherCreditById(int teacherId) { string query = "Select Credit from SaveTeacher where TeacherId = @teacherId"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@teacherId", teacherId); connection.Open(); reader = command.ExecuteReader(); SaveTeacher saveTeacher = null; if (reader.HasRows) { saveTeacher = new SaveTeacher(); saveTeacher.Credit = Convert.ToDouble(reader["Credit"]); } reader.Close(); connection.Close(); return(saveTeacher); }
public int SaveTeacher(SaveTeacher saveTeacher) { Query = "INSERT INTO Teacher VALUES(@name, @email, @contactNo, @address, @designation, @departmentId, @CraditToBeTaken, @reaminToBeTaken)"; Command = new SqlCommand(Query, Connection); Command.Parameters.Add("name", SqlDbType.VarChar); Command.Parameters["name"].Value = saveTeacher.Name; Command.Parameters.Add("email", SqlDbType.VarChar); Command.Parameters["email"].Value = saveTeacher.Email; Command.Parameters.Add("contactNo", SqlDbType.VarChar); Command.Parameters["contactNo"].Value = saveTeacher.ContactNo; Command.Parameters.Add("address", SqlDbType.VarChar); Command.Parameters["address"].Value = saveTeacher.Address; Command.Parameters.Add("designation", SqlDbType.VarChar); Command.Parameters["designation"].Value = saveTeacher.Designation; Command.Parameters.Add("departmentId", SqlDbType.Int); Command.Parameters["departmentId"].Value = saveTeacher.DepartmentId; Command.Parameters.Add("CraditToBeTaken", SqlDbType.Decimal); Command.Parameters["CraditToBeTaken"].Value = saveTeacher.CraditToBeTaken; Command.Parameters.Add("reaminToBeTaken", SqlDbType.Decimal); Command.Parameters["reaminToBeTaken"].Value = saveTeacher.CraditToBeTaken; Connection.Open(); int rowAffeted = Command.ExecuteNonQuery(); Connection.Close(); return(rowAffeted); }
public string SaveTeacher(SaveTeacher saveTeacher) { //if (saveTeacher.ContactNo.Length != 11) //{ // return "Contact No must be 11 digit"; //} if (aTeacherSaveGateway.EmailExists(saveTeacher.Email)) { return("Email already exists.."); } int rowAffected = aTeacherSaveGateway.SaveTeacher(saveTeacher); if (rowAffected > 0) { return("Saved Successfuly"); } else { return("Save failed"); } }
public List <SaveTeacher> GetTeachersById(int deptId) { string query = "select TeacherId,TeacherName SaveTeacher where DeptId = @deptId"; command = new SqlCommand(query, connection); command.Parameters.AddWithValue("@deptId", deptId); connection.Open(); reader = command.ExecuteReader(); List <SaveTeacher> saveTeachersList = new List <SaveTeacher>(); while (reader.Read()) { SaveTeacher saveTeacher = new SaveTeacher(); saveTeacher.DeptId = Convert.ToInt32(reader["TeacherId"]); saveTeacher.TeacherName = reader["TeacherName"].ToString(); saveTeachersList.Add(saveTeacher); } reader.Close(); connection.Close(); return(saveTeachersList); }
//Get all teacher public List <SaveTeacher> GetTeachers() { string query = "select * from SaveTeacher"; command = new SqlCommand(query, connection); List <SaveTeacher> teacherList = new List <SaveTeacher>(); SaveTeacher teacher = null; connection.Open(); reader = command.ExecuteReader(); while (reader.Read()) { teacher = new SaveTeacher(); teacher.TeacherId = Convert.ToInt32(reader["TeacherId"]); teacher.TeacherName = reader["TeacherName"].ToString(); teacher.DeptId = Convert.ToInt32(reader["DeptId"]); teacher.Credit = Convert.ToDouble(reader["Credit"]); teacherList.Add(teacher); } reader.Close(); connection.Close(); return(teacherList); }