public void PostAddAssignment(Assignment assignment) { int c = 0; string sql = null; int? mark = 0; SystemContext context = HttpContext.RequestServices.GetService(typeof(Exam_Management_System.Models.SystemContext)) as SystemContext; int academic_id = context.GetAcademic().Id; int student_id = context.GetStudentId(assignment.Rollno, academic_id); using (MySqlConnection conn = context.GetConnection()) { conn.Open(); string check = $"Select count(*),mark from assignment where studentrollno_id={student_id} and subject_id={assignment.Subject_id}"; using (MySqlCommand command = new MySqlCommand(check, conn)) { c = Convert.ToInt32(command.ExecuteScalar()); } if (c == 0) { sql = $"Insert Into assignment (studentrollno_id,subject_id,mark,academic_id) Values ('{student_id}','{assignment.Subject_id}','{assignment.Mark}','{academic_id}')"; } else { string aa = $"Select mark from assignment where studentrollno_id={student_id} and subject_id={assignment.Subject_id}"; using (MySqlCommand command = new MySqlCommand(aa, conn)) { var reader = command.ExecuteReader(); while (reader.Read()) { mark = Convert.ToInt32(reader["mark"]); } } sql = $"Update assignment set mark={mark + assignment.Mark} where studentrollno_id={student_id} and subject_id={assignment.Subject_id}"; } using (MySqlCommand command = new MySqlCommand(sql, conn)) { command.ExecuteNonQuery(); //conn.Close(); } int total_mark = context.GetTotalMark(assignment.Rollno_id, context.GetAcademic().Id); string sql1 = $"Update result set total_mark='{total_mark}' where studentrollno_id={assignment.Rollno_id}"; using (MySqlCommand command = new MySqlCommand(sql1, conn)) { command.ExecuteNonQuery(); conn.Close(); } } }
public void PostOldStudent(Student student) { SystemContext context = HttpContext.RequestServices.GetService(typeof(Exam_Management_System.Models.SystemContext)) as SystemContext; int academic = context.GetAcademicSecond().Id; int student_id = context.GetStudentId(student.Rollno, academic); int mark = context.GetMark(student_id); using (MySqlConnection conn = context.GetConnection()) { conn.Open(); string sql1 = $"Insert Into old_student (student_year_id,address,phone,father_phone,mother_phone,email,academic_id,major_id,student_id,mark) Values ('{student.Year_id}','{student.Address}','{student.Phone}','{student.Father_phone}','{student.Mother_phone}','{student.Email}','{student.Academic_id}','{student.Major_id}','{student_id}','{mark}')"; using (MySqlCommand command1 = new MySqlCommand(sql1, conn)) { command1.ExecuteNonQuery(); } } // return Redirect("/Student/AddOldStudent"); }
public string PostAddMark(Mark mark) { SystemContext context = HttpContext.RequestServices.GetService(typeof(Exam_Management_System.Models.SystemContext)) as SystemContext; int academic_id = context.GetAcademic().Id; int student_id = context.GetStudentId(mark.Rollno, academic_id); using (MySqlConnection conn = context.GetConnection()) { conn.Open(); string sql = null; if (mark.Exam_id == 1) { if (context.CheckMidMark(student_id, mark.Subject_id, academic_id) == 0) { sql = $"Insert Into mark_mid (studentrollno_id,mark,subject_id,academic_id) Values ('{student_id}','{mark.S_mark}','{mark.Subject_id}','{academic_id}')"; using (MySqlCommand command = new MySqlCommand(sql, conn)) { command.ExecuteNonQuery(); conn.Close(); } } else { return("NO"); } } else { if (context.CheckFinalMark(student_id, mark.Subject_id, academic_id) == 0) { sql = $"Insert Into mark_final (studentrollno_id,mark,subject_id,academic_id) Values ('{student_id}','{mark.S_mark}','{mark.Subject_id}','{academic_id}')"; using (MySqlCommand command = new MySqlCommand(sql, conn)) { command.ExecuteNonQuery(); //conn.Close(); } int mid_mark = context.GetMid_Mark(student_id, academic_id); int assignment = context.GetAss_Mark(student_id, academic_id); int pass = context.GetPass(student_id, academic_id, mark.Subject_id, mark.S_mark); // int credit = context.GetCredit(student_id, academic_id, mark.S_mark, mark.Subject_id); int final_mark = context.GetFinal_Mark(student_id, academic_id); int totalMark = context.GetTotalMark(student_id, academic_id); if (context.CheckResult(student_id, academic_id) == 0) { sql = $"Insert Into result (studentrollno_id,mid_mark,final_mark,assigment_mark,pass,academic_id,total_mark) Values ('{student_id}','{mid_mark}','{final_mark}','{assignment}','{pass}','{academic_id}','{totalMark}')"; } else { sql = $"UPDATE result SET final_mark={final_mark},pass={pass},attendence_mark={context.tt},total_mark={totalMark} where studentrollno_id={student_id} and academic_id={academic_id}"; } using (MySqlCommand command = new MySqlCommand(sql, conn)) { command.ExecuteNonQuery(); conn.Close(); } } else { return("NO"); } } } return("OK"); }