public ActionResult AddResultByStudent(AddResultByStudent viewModel, FormCollection form) { ViewBag.ClassList = new SelectList(db.SchoolClasses.Where(i => i.SchoolId == viewModel.SchoolId), "Id", "Name"); var subjects = db.Subjects.Where(i => i.SchoolClassId == viewModel.ClassId).ToList(); foreach (var subject in subjects) { var grade = form["Grade_" + subject.Id].ToString(); var markString = form["Mark_" + subject.Id].ToString(); double mark = 0.0; double.TryParse(markString, out mark); var result = new Result() { ClassId = viewModel.ClassId, Grade = grade, MarkPercentage = mark, SchoolId = viewModel.SchoolId, StudentId = viewModel.StudentId, SubjectId = subject.Id }; db.Results.Add(result); } db.SaveChanges(); return(View()); }
public ActionResult GetStudentwiseResult(int studentId, int classId) { var subjects = db.Subjects.Where(i => i.SchoolClassId == classId).ToList(); var viewModel = new AddResultByStudent(); viewModel.Subjects = subjects; viewModel.ClassId = classId; viewModel.StudentId = studentId; return(PartialView("_AddResultByStudent", viewModel)); }