//Created by Prasana on 17.07.2013 /// <summary> /// Adds the student. /// </summary> /// <param name="student">The student.</param> /// <returns>RollNumber</returns> public int AddStudent(Student student) { int rollNumber = 0; object IdentityValue = 0; using (var connection = new SqlConnection(GetConnectionString())) { using (SqlCommand cmd = connection.CreateCommand()) { connection.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "[dbo].[usp_student_insert]"; cmd.Parameters.Add(new SqlParameter("@student_name", student.Name)); cmd.Parameters.Add(new SqlParameter("@standard", student.Standard)); cmd.Parameters.Add(new SqlParameter("@section", student.Section)); cmd.Parameters.Add(new SqlParameter("@gender", student.Gender)); cmd.Parameters.Add(new SqlParameter("@date_of_birth", student.DateOfBirth)); cmd.Parameters.Add(new SqlParameter("@phone_number", student.PhoneNumber)); cmd.Parameters.Add(new SqlParameter("@address", student.Address)); cmd.Parameters.Add(new SqlParameter("@created_by", 1)); IdentityValue = cmd.ExecuteScalar(); } if (IdentityValue != DBNull.Value) { rollNumber = Convert.ToInt32(IdentityValue); } } return rollNumber; }
public ActionResult AddStudent(Student student) { //StudentRepository studentRepository = new StudentRepository(); var studentRollNumber = studentRepository.AddStudent(student); if (studentRollNumber != 0) { return RedirectToAction("AddStudentMark", "Student", new { id = studentRollNumber }); } else { ViewData["Message"] = "Error in inserting"; return View(); } }
//Created by Prasanaon 18.07.2013 /// <summary> /// Creates the student. /// </summary> /// <returns>Student</returns> public static Student CreateStudent() { var student = new Student { Name = "Bheem", Standard = "VI", Section = "A", Gender = 'M', DateOfBirth = "03.02.1989", PhoneNumber = "9874586854", Address = "Salem", Created_By = 1 }; student.RollNumber = studentRepository.AddStudent(student); return student; }
//Created by Prasana on 18.07.2013 /// <summary> /// Creates the student. /// </summary> /// <returns></returns> public static Student CreateStudent() { var student = new Student { Name = "Bheem", Standard = "VI", Section = "B", Gender = 'M', DateOfBirth = "03.02.1989", PhoneNumber = "7857458745", Address = "Chennai", Created_By = 1 }; student.RollNumber = studentDataService.AddStudent(student); return student; }
//Created by Prasana on 17.07.2013 /// <summary> /// Updates the student. /// </summary> /// <param name="student">The student.</param> public void UpdateStudent(Student student) { using (var connection = new SqlConnection(GetConnectionString())) { using (SqlCommand cmd = connection.CreateCommand()) { connection.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "[dbo].[usp_student_update]"; cmd.Parameters.Add(new SqlParameter("@roll_number", student.RollNumber)); cmd.Parameters.Add(new SqlParameter("@student_name", student.Name)); cmd.Parameters.Add(new SqlParameter("@standard", student.Standard)); cmd.Parameters.Add(new SqlParameter("@section", student.Section)); cmd.Parameters.Add(new SqlParameter("@gender", student.Gender)); cmd.Parameters.Add(new SqlParameter("@date_of_birth", student.DateOfBirth)); cmd.Parameters.Add(new SqlParameter("@phone_number", student.PhoneNumber)); cmd.Parameters.Add(new SqlParameter("@address", student.Address)); cmd.Parameters.Add(new SqlParameter("@modified_by", 1)); cmd.ExecuteNonQuery(); } } }
//Created By Prasana on 17.07.2013 /// <summary> /// Gets the student by roll number. /// </summary> /// <param name="rollNumber">The roll number.</param> /// <returns>Student</returns> public Student GetStudentByRollNumber(int rollNumber) { Student student = null; using (var connection = new SqlConnection(GetConnectionString())) { using (SqlCommand cmd = connection.CreateCommand()) { connection.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "[dbo].[usp_get_student_by_roll_number]"; cmd.Parameters.Add(new SqlParameter("@roll_number", rollNumber)); using (SqlDataReader dataReader = cmd.ExecuteReader()) { if (dataReader.HasRows) { int studetRollNumberOrdinal = dataReader.GetOrdinal("Roll_Number"); int studentNameOrdinal = dataReader.GetOrdinal("student_name"); int standardOrdinal = dataReader.GetOrdinal("standard"); int sectionOrdinal = dataReader.GetOrdinal("section"); int genderOrdinal = dataReader.GetOrdinal("gender"); int dateOfBirthOrdinal = dataReader.GetOrdinal("date_of_birth"); int phoneNumberOrdinal = dataReader.GetOrdinal("phone_number"); int addressOrdinal = dataReader.GetOrdinal("address"); int modifiedByOrdinal = dataReader.GetOrdinal("modified_by"); while (dataReader.Read()) { student = new Student { RollNumber = dataReader.GetInt32(studetRollNumberOrdinal), Name = dataReader.GetString(studentNameOrdinal), Standard = dataReader.GetString(standardOrdinal), Section = dataReader.GetString(sectionOrdinal), Gender = Convert.ToChar(dataReader.GetValue(genderOrdinal)), DateOfBirth = dataReader.GetString(dateOfBirthOrdinal), PhoneNumber = dataReader.GetString(phoneNumberOrdinal), Address = dataReader.GetString(addressOrdinal), Modified_By = dataReader.GetInt32(modifiedByOrdinal) }; } } } } } return student; }
public ActionResult ViewStudent(int id) { var student = new Student {StudentMarks = new List<StudentMark>()}; student = studentRepository.GetStudentByRollNumber(id); var studentMarkGet = studentRepository.GetStudentMarkByRollNumber(id); student.StudentMarks.Add(new StudentMark { Language = studentMarkGet.Language, English = studentMarkGet.English, Maths = studentMarkGet.Maths, Science = studentMarkGet.Science, Social = studentMarkGet.Social, Total = studentMarkGet.Total, Percentage = studentMarkGet.Percentage, Result = studentMarkGet.Result }); return View(student); }
public ActionResult EditStudent(Student student) { int studentRollNumber = 0; studentRollNumber = student.RollNumber; studentRepository.UpdateStudent(student); return RedirectToAction("EditStudentMark", "Student", new { id = studentRollNumber }); }
//Created by Prasana on 18.07.2013 /// <summary> /// Adds the student. /// </summary> /// <param name="student">The student.</param> /// <returns>Student</returns> public int AddStudent(Student student) { int rollNumber = 0; rollNumber = studentDataService.AddStudent(student); return rollNumber; }
//Created by Prasana on 18.07.2013 /// <summary> /// Updates the student. /// </summary> /// <param name="student">The student.</param> public void UpdateStudent(Student student) { studentDataService.UpdateStudent(student); }