public ActionResult _Student(int?Class_id, int?student_id, int?term_id) { checkLogin(); _StudentViewModel SVM = new _StudentViewModel(); //get class num List <CLASS_STUDENT_LIST> ClassStudentMap = new List <CLASS_STUDENT_LIST>(); if (Class_id > 0 && term_id > 0) { Dictionary <string, string> DS = new Dictionary <string, string>() { { "QE_CLASS", Class_id.ToString() }, { "ACTIVE", "1" } }; ClassStudentMap = DBS.Query <CLASS_STUDENT_LIST>(DS); } SVM.ClassStudentMap = ClassStudentMap; //get student list SVM.studentList = Class_id != null && term_id != null?StudentService.GetActiveStudentsByClass((int)Class_id) : new List <STUDENT>(); //get student chosen SVM.selectedStudent = student_id != null && student_id > 0 && SVM.studentList.Exists(s => s.ID == (int)student_id) ? SVM.studentList.Where(s => s.ID == (int)student_id).First() : new STUDENT(); try { SVM.selectedStudentNum = ClassStudentMap.Where(c => c.STUDENT == (int)student_id).FirstOrDefault().CLASS_NUM; } catch { } SVM.selectedClass = (int)Class_id; SVM.selectedTerm = (int)term_id; return(View("_Student", SVM)); }
public ActionResult _Student(_StudentViewModel SVM) { checkLogin(); // fields checking if (!ModelState.IsValid) { return(View("_Student", SVM)); } //edit or create bool result = false; if (SVM.selectedStudent.ID > 0) {//ediit SVM.selectedStudent.MODIFY_BY = CP.userID; SVM.selectedStudent.MODIFY_DATE = DateTime.Now; result = DBS.updateRecord(SVM.selectedStudent); } else {//create SVM.selectedStudent.ACTIVE = true; SVM.selectedStudent.ADD_BY = CP.userID; SVM.selectedStudent.ADD_DATE = DateTime.Now; SVM.selectedStudent.ID = DBS.addRecordReturnID(SVM.selectedStudent); CLASS_STUDENT_LIST newMap = new CLASS_STUDENT_LIST(SVM.selectedClass, SVM.selectedStudent.ID, SVM.selectedStudentNum, CP.userID, DateTime.Now, 0, Constant.DEF_DATETIME, true); int newMap_id = DBS.addRecordReturnID(newMap); //add new map linking up student and class if (SVM.selectedStudent.ID > 0 && newMap_id > 0) { result = true; } } ModelState.Clear(); if (result) { TempData[Constant.msg_success] = Constant.ChangeSucceed; } else { TempData[Constant.msg_error] = Constant.ChangeFailed; } return(_Student(SVM.selectedClass, SVM.selectedStudent.ID, SVM.selectedTerm)); }