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"); }