public ActionResult Edit(int id, ExamUpload model) { DBmodel db = new DBmodel(); Exam2 exam = db.Exam2.Find(id); if (ModelState.IsValid) { string oldName = exam.FileName; exam.FileName = model.FileName; int grade2 = model.grade_id; int subject2 = model.subject_id; var subject = db.subjects.Where(m => m.subject_id == subject2).Select(u => new { subject = u.subject1 }).Single(); var grade = db.GradeLists.Where(m => m.ID == grade2).Select(u => new { grade = u.Grade }).Single(); //file.FilePath = fullPath; exam.Grade = grade.grade; exam.Subject = subject.subject; db.Entry(exam).State = EntityState.Modified; db.SaveChanges(); int ExamID = model.ExamID; Exam2 teacher = db.Exam2.Find(id); teacher.ExamID = model.ExamID; db.Entry(teacher).State = EntityState.Modified; db.SaveChanges(); ChangeFileName(ExamID, model.FileName, oldName); return(RedirectToAction("ViewList")); } else { List <grade> gradeList = db.grades.ToList(); ViewBag.grList = new SelectList(gradeList, "grade_id", "grade1"); List <subject> subjectList = db.subjects.ToList(); ViewBag.subList = new SelectList(subjectList, "subject_id", "subject1"); return(View(model)); } }
public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } DBmodel db = new DBmodel(); Exam2 file = db.Exam2.Find(id); if (file == null) { return(HttpNotFound()); } return(View(file)); }
public void ChangeFileName(int Exam_ID, string FileName, string oldName) { DBmodel db = new DBmodel(); Exam2 file = db.Exam2.Find(Exam_ID); var directory = new DirectoryInfo(Server.MapPath("~/App_Data/File")); string getFile = directory.FullName + "\\" + oldName; System.IO.File.Move(getFile, directory.FullName + "\\" + FileName); string path = file.FilePath; path = "C:\\Users\\Halo\\source\\repos\\Exam__\\Exam__\\App_Data\\File" + FileName; file.FilePath = path; db.Entry(file).State = EntityState.Modified; db.SaveChanges(); }
public ActionResult DeleteSucces(int id) { DBmodel db = new DBmodel(); Exam2 file = db.Exam2.Find(id); Exam2 teacher = db.Exam2.Find(id); db.Exam2.Remove(teacher); db.SaveChanges(); var directory = new DirectoryInfo(Server.MapPath("~/App_Data/File")); string getFile = directory.FullName + "\\" + file.FileName; System.IO.File.Delete(getFile); //db.Exam2.Remove(file); db.SaveChanges(); return(RedirectToAction("ViewList")); }
public ActionResult Index(HttpPostedFileBase file, ExamUpload ex) { if (!ModelState.IsValid) { return(new JsonResult { Data = "File not upload" }); } else { SipminiEntities2 DB = new SipminiEntities2(); Exam2 log = new Exam2(); var subject = DB.subjects.Where(m => m.subject_id == ex.subject_id).Select(u => new { subject = u.subject1 }).Single(); var grade = DB.grades.Where(m => m.grade_id == ex.grade_id).Select(u => new { grade = u.grade1 }).Single(); string path = Server.MapPath("~/App_Data/File"); string fileName = Path.GetFileName(file.FileName); string fullPath = Path.Combine(path, fileName); log.FileName = fileName; log.FilePath = fullPath; log.Grade = grade.grade; log.Subject = subject.subject; log.TeacherName = "ASDF"; DB.Exam2.Add(log); DB.SaveChanges(); file.SaveAs(fullPath); return(new JsonResult { Data = "File uploaded" }); } }
public ActionResult Edit(int?id) { DBmodel db = new DBmodel(); Exam2 file = db.Exam2.Find(id); ExamUpload model = new ExamUpload(); model.ExamID = file.ExamID; model.subject1 = file.Subject; model.grade1 = file.Grade; model.TeacherName = file.TeacherName; model.FileName = file.FileName; model.FilePath = file.FilePath; List <subject> subjectList = db.subjects.ToList(); ViewBag.subList = new SelectList(subjectList, "subject_id", "subject1"); List <grade> gradeList = db.grades.ToList(); ViewBag.grList = new SelectList(gradeList, "grade_id", "grade1"); return(View(model)); }
public ActionResult Grade(OnlineExam exam) { if (exam.Questions.Count == 0) { // RedirectToAction("Index"); return(View("Error")); } else { var grade = new ExamService().Grade(exam); Question theQuestion = work.QuestionRepository.GetByID(exam.Questions[0].QuestionID); OnlineExam theOnlineExam = work.OnlineExamRepository.GetByID(theQuestion.OnlineExamID); //get user who has just finished the exam Int32 UserName = Convert.ToInt32(User.Identity.Name); List <PrimarySchoolStudent> theStudents = work.PrimarySchoolStudentRepository.Get(a => a.UserID == UserName).ToList(); PrimarySchoolStudent theStudent = theStudents[0]; if (theOnlineExam.ExamType == "PractiseRecord") { string theUserID = Convert.ToString(theStudent.UserID); List <PractiseSave> thePractice = work.PractiseSaveRepository.Get(a => a.Term.Equals(theOnlineExam.Term) && a.Code.Equals(theOnlineExam.ExamCode) && a.StudentID.Equals(theUserID)).ToList(); //Check if there is not an exam code equal to this one if (thePractice.Count == 0) { PractiseSave theStudentScore = new PractiseSave(); double e = ((grade.Score / grade.TotalPoints) * 100); theStudentScore.Score = Convert.ToDecimal(e); theStudentScore.Level = theStudent.PresentLevel; theStudentScore.StudentID = Convert.ToString(theStudent.UserID); theStudentScore.Subject = theOnlineExam.Course; theStudentScore.Term = theOnlineExam.Term; theStudentScore.Code = theOnlineExam.ExamCode; theStudentScore.LevelType = theStudent.LevelType; // theStudentScore. work.PractiseSaveRepository.Insert(theStudentScore); work.Save(); } } if (theOnlineExam.ExamType == "Exam" || theOnlineExam.ExamType == "TEST 1" || theOnlineExam.ExamType == "TEST 2") { //if student has no repeat if (theStudent.RepeatTimes == 0) { List <Exam> theExam0 = work.ExamRepository.Get(a => a.StudentCode == theStudent.UserID && a.Level.Equals(theStudent.PresentLevel) && a.SubjectName.Equals(theOnlineExam.Course) && a.Term.Equals(theOnlineExam.Term)).ToList(); // if (theOnlineExam.ExamType == "Exam") { if (theExam0.Count > 0) { // if(theExam0) Exam theStudentScore = theExam0[0]; if (theStudentScore.SubjectExam == 0) { double e = ((grade.Score / grade.TotalPoints) * 100) * 0.6; theStudentScore.SubjectExam = Convert.ToDecimal(e); work2.ExamRepository.Update(theStudentScore); work2.Save(); } } else { Exam theStudentScore = new Exam(); theStudentScore.Term = theOnlineExam.Term; theStudentScore.SubjectName = theOnlineExam.Course; theStudentScore.Level = theStudent.PresentLevel; theStudentScore.StudentCode = theStudent.UserID; double e = ((grade.Score / grade.TotalPoints) * 100) * 0.6; theStudentScore.SubjectExam = Convert.ToDecimal(e); work2.ExamRepository.Insert(theStudentScore); work2.Save(); } } if (theOnlineExam.ExamType == "TEST 1") { if (theExam0.Count > 0) { Exam theStudentScore = theExam0[0]; if (theStudentScore.FirstCA == 0) { double t2 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; theStudentScore.FirstCA = Convert.ToDecimal(t2); work2.ExamRepository.Update(theStudentScore); work2.Save(); } } else { double t1 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; Exam theExam = new Exam(); theExam.FirstCA = Convert.ToDecimal(t1); theExam.Term = theOnlineExam.Term; theExam.SubjectName = theOnlineExam.Course; theExam.Level = theStudent.PresentLevel; theExam.StudentCode = theStudent.UserID; // theStudentScore.FirstCA = work2.ExamRepository.Insert(theExam); work2.Save(); } } if (theOnlineExam.ExamType == "TEST 2") { if (theExam0.Count > 0) { Exam theStudentScore = theExam0[0]; if (theStudentScore.SecondCA == 0) { double t2 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; theStudentScore.SecondCA = Convert.ToDecimal(t2); work2.ExamRepository.Update(theStudentScore); work2.Save(); } } else { if (theOnlineExam.ExamType == "TEST 2") { double t1 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; Exam theExam = new Exam(); theExam.SecondCA = Convert.ToDecimal(t1); theExam.Term = theOnlineExam.Term; theExam.SubjectName = theOnlineExam.Course; theExam.Level = theStudent.PresentLevel; theExam.StudentCode = theStudent.UserID; // theStudentScore.FirstCA = work2.ExamRepository.Insert(theExam); work2.Save(); //Exam theStudentScore = theExam0[0]; //double t2 = ((grade.Score / grade.TotalPoints) * 100) * 0.3; //theStudentScore.SecondCA = Convert.ToDecimal(t2); //work2.ExamRepository.Update(theStudentScore); //work2.Save(); } } } } //check for repeat 1 if (theStudent.RepeatTimes == 1) { List <Exam1> theExam1 = work.Exam1Repository.Get(a => a.StudentCode == theStudent.UserID && a.Level.Equals(theStudent.PresentLevel) && a.SubjectName.Equals(theOnlineExam.Course) && a.Term.Equals(theOnlineExam.Term)).ToList(); // if (theOnlineExam.ExamType == "Exam") { if (theExam1.Count > 0) { Exam1 theStudentScore = theExam1[0]; if (theStudentScore.SubjectExam == 0) { double e = ((grade.Score / grade.TotalPoints) * 100) * 0.6; theStudentScore.SubjectExam = Convert.ToDecimal(e); work2.Exam1Repository.Update(theStudentScore); work2.Save(); } } else { if (theOnlineExam.ExamType == "Exam") { Exam1 theStudentScore = new Exam1(); theStudentScore.Term = theOnlineExam.Term; theStudentScore.SubjectName = theOnlineExam.Course; theStudentScore.Level = theStudent.PresentLevel; theStudentScore.StudentCode = theStudent.UserID; double e = ((grade.Score / grade.TotalPoints) * 100) * 0.6; theStudentScore.SubjectExam = Convert.ToDecimal(e); work2.Exam1Repository.Insert(theStudentScore); work2.Save(); //Exam1 theStudentScore = new Exam1(); //theStudentScore.SecondCA = 0.00M; //double e = ((grade.Score / grade.TotalPoints) * 100) * 0.5; //// theStudentScore.SubjectExam = e; //theStudentScore.SubjectExam = Convert.ToDecimal(e); //work2.Exam1Repository.Insert(theStudentScore); //work2.Save(); } } } if (theOnlineExam.ExamType == "TEST 1") { if (theExam1.Count > 0) { Exam1 theStudentScore = theExam1[0]; if (theStudentScore.FirstCA == 0) { double t2 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; theStudentScore.FirstCA = Convert.ToDecimal(t2); work2.Exam1Repository.Update(theStudentScore); work2.Save(); } } else { double t1 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; Exam1 theExamlocal1 = new Exam1(); theExamlocal1.FirstCA = Convert.ToDecimal(t1); theExamlocal1.Term = theOnlineExam.Term; theExamlocal1.SubjectName = theOnlineExam.Course; theExamlocal1.Level = theStudent.PresentLevel; theExamlocal1.StudentCode = theStudent.UserID; // theStudentScore.FirstCA = work2.Exam1Repository.Insert(theExamlocal1); work2.Save(); } } if (theExam1.Count > 0) { if (theOnlineExam.ExamType == "TEST 2") { Exam1 theStudentScore = theExam1[0]; if (theStudentScore.SecondCA == 0) { double t2 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; theStudentScore.SecondCA = Convert.ToDecimal(t2); work2.Exam1Repository.Update(theStudentScore); work2.Save(); } } } else { if (theOnlineExam.ExamType == "TEST 2") { double t1 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; Exam1 theExam = new Exam1(); theExam.SecondCA = Convert.ToDecimal(t1); theExam.Term = theOnlineExam.Term; theExam.SubjectName = theOnlineExam.Course; theExam.Level = theStudent.PresentLevel; theExam.StudentCode = theStudent.UserID; // theStudentScore.FirstCA = work2.Exam1Repository.Insert(theExam); work2.Save(); } } } //check for repeat 2 if (theStudent.RepeatTimes == 2) { List <Exam2> theExam2 = work.Exam2Repository.Get(a => a.StudentCode == theStudent.UserID && a.Level.Equals(theStudent.PresentLevel) && a.SubjectName.Equals(theOnlineExam.Course) && a.Term.Equals(theOnlineExam.Term)).ToList(); // if (theOnlineExam.ExamType == "Exam") { if (theExam2.Count > 0) { Exam2 theStudentScore = theExam2[0]; if (theStudentScore.SubjectExam == 0) { double e = ((grade.Score / grade.TotalPoints) * 100) * 0.6; theStudentScore.SubjectExam = Convert.ToDecimal(e); work2.Exam2Repository.Update(theStudentScore); work2.Save(); } } else { if (theOnlineExam.ExamType == "Exam") { Exam2 theStudentScore = new Exam2(); theStudentScore.Term = theOnlineExam.Term; theStudentScore.SubjectName = theOnlineExam.Course; theStudentScore.Level = theStudent.PresentLevel; theStudentScore.StudentCode = theStudent.UserID; double e = ((grade.Score / grade.TotalPoints) * 100) * 0.6; theStudentScore.SubjectExam = Convert.ToDecimal(e); work2.Exam2Repository.Insert(theStudentScore); work2.Save(); //Exam2 theStudentScore = new Exam2(); //theStudentScore.SecondCA = 0.00M; //double e = ((grade.Score / grade.TotalPoints) * 100) * 0.5; //// theStudentScore.SubjectExam = e; //theStudentScore.SubjectExam = Convert.ToDecimal(e); //work2.Exam2Repository.Insert(theStudentScore); //work2.Save(); } } } if (theOnlineExam.ExamType == "TEST 1") { if (theExam2.Count == 0) { double t1 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; Exam2 theExamlocal2 = new Exam2(); theExamlocal2.FirstCA = Convert.ToDecimal(t1); theExamlocal2.Term = theOnlineExam.Term; theExamlocal2.SubjectName = theOnlineExam.Course; theExamlocal2.Level = theStudent.PresentLevel; theExamlocal2.StudentCode = theStudent.UserID; // theStudentScore.FirstCA = work2.Exam2Repository.Insert(theExamlocal2); work2.Save(); } else { Exam2 theStudentScore = theExam2[0]; if (theStudentScore.FirstCA == 0) { double t2 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; theStudentScore.FirstCA = Convert.ToDecimal(t2); work2.Exam2Repository.Update(theStudentScore); work2.Save(); } } } if (theOnlineExam.ExamType == "TEST 2") { if (theExam2.Count > 0) { Exam2 theStudentScore = theExam2[0]; if (theStudentScore.SecondCA == 0) { double t2 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; theStudentScore.SecondCA = Convert.ToDecimal(t2); work2.Exam2Repository.Update(theStudentScore); work2.Save(); } } else { if (theOnlineExam.ExamType == "TEST 2") { double t1 = ((grade.Score / grade.TotalPoints) * 100) * 0.2; Exam2 theExam = new Exam2(); theExam.SecondCA = Convert.ToDecimal(t1); theExam.Term = theOnlineExam.Term; theExam.SubjectName = theOnlineExam.Course; theExam.Level = theStudent.PresentLevel; theExam.StudentCode = theStudent.UserID; // theStudentScore.FirstCA = work2.Exam2Repository.Insert(theExam); work2.Save(); } } } } } return(View(grade)); } //return View(); }