public ActionResult ViewGrades(int id) { var userId = User.Identity.GetUserId(); var selectedCourseId = id; var context = HttpContext.GetOwinContext().Get <ApplicationDbContext>(); var courseAssignments = context.Assignments.Where(x => x.Course.CourseId == selectedCourseId).ToList(); var studentGrades = context.SubmissionGrades.Include(x => x.User).Include(x => x.Assignment).Include("Assignment.Course") .Where(x => x.User.Id == userId && x.Assignment.Course.CourseId == selectedCourseId).ToList(); var studentGradesViewModel = new StudentGradesViewModel() { StudentGrades = studentGrades, CourseAssignments = courseAssignments }; //to calculate total get a sum off all score and divide by sum of all assignmnet.course.points var gradeTotal = studentGrades.Where(x => x.Grade != null).Sum(x => x.Grade); var pointsTotal = studentGrades.Where(x => x.Grade != null).Sum(x => x.Assignment.Points); var total = gradeTotal / pointsTotal; var formattedTotal = string.Format("{0:P2}", total); ViewBag.Total = formattedTotal; return(View(studentGradesViewModel)); }
public void AddStudentGrades(StudentGradesViewModel studentGradesViewModel) { unitOfWork.StudentCourse.Add(new StudentCourse { StudentId = studentGradesViewModel.StudentId, CourseId = studentGradesViewModel.CourseId, Attestation_first = studentGradesViewModel.Attestation_first, Attestation_second = studentGradesViewModel.Attestation_second, Exam = studentGradesViewModel.Exam }); }
// Recall that the @Html.TextBoxFor returns the data collected, stored in a field of the view model class type // Also recall that interactions with the View are handled by the HttpPost attribute - passing in a view model // as the parameter allows the action method to make use of the data stored in the vm that is returned. // However, the compiler calls the default constructor when creating an instance of the vm object to be passed in, // so ensure that whichever fields are required within the vm have a default constructor. // Post data to the server side, to be processed by the database. public ActionResult AddCourse(StudentGradesViewModel vm) { StudentGradeDAL studentGradeDAL = new StudentGradeDAL(); // Poll for clicks from btnCreate // Request tracks any requests made from the current View // .Form[string name] specifies the NAME of the form control to track requests from. // If the button matching the specified name is clicked, its value gets returned. If no click // event occurs, btnAdd will return null. Thus, when it is idle, the else block runs. if (Request.Form["btnCreate"] != null) { // The following is incorrect. Why create a new Grade with the same values as the current Grade??? //studentGradeDAL.GradeBook.Add(new Grade(vm.Grade.CourseTitle, vm.Grade.Passed)); // This checks if any errors exist on the server side (basically any attributes like [RegularExpression] that // are not satisfied) if (ModelState.IsValid) { // The Grade object is created and populated based on the entries in the form - just add to Gradebook. studentGradeDAL.GradeBook.Add(vm.Grade); // Without this, any changes will not be reflected in the database. studentGradeDAL.SaveChanges(); // RedirectToAction redirects away from the current webpage. Parameters are the name of the // action method to redirect to, followed by the name of the Controller the action method // belongs to, both represented as strings. return(RedirectToAction("ResultsStatement", "Day2Demo")); } // If the above check fails, the same View is returned. B nnecause the error messages are specified in Grade.cs, as // well as instructed to show in AddCourse.cshtml, they will display on the screen this time round. return(View()); } else if (Request.Form["btnCancel"] != null) { return(RedirectToAction("ResultsStatement", "Day2Demo")); } else { // Return the same view if no buttons are pressed. return(View()); } }
// GET: Grades public ActionResult Index() { var userID = User.Identity.GetUserId(); if (User.IsInRole("Admin")) { var grades = gradeService.GetAllGrades(); return(View(grades.ToList())); } else if (User.IsInRole("Teacher")) { var subjectStudentsGroup = db.SubjectStudentGroupTeacher.Where(x => x.TeacherID == userID).Select(x => new TeacherGradesViewModel() { Subject = x.Subject, StudentsGroup = x.StudentsGroup }).Distinct().ToList(); return(View("~\\Views\\Grades\\IndexTeacher.cshtml", subjectStudentsGroup)); } else if (User.IsInRole("Student")) { var myStudentGrupuID = db.MyUsers.Where(x => x.Owner == userID).Select(x => x.StudentsGroupId).FirstOrDefault(); var grades = Helper.ToIEnumerable <Grade>(gradeService.GradesForStudent(userID)); var subjects = db.SubjectStudentGroupTeacher.Where(x => x.StudentsGroupId == myStudentGrupuID).Select(x => x.Subject).ToList(); StudentGradesViewModel studentViewModel = new StudentGradesViewModel() { Grades = grades, Subjects = subjects }; return(View("~\\Views\\Grades\\IndexStudent.cshtml", studentViewModel)); } return(View()); }
// GET: Day2Demo public ActionResult ResultsStatement() { // Instantiating an object of the View Model StudentGradesViewModel studentGradesViewModel = new StudentGradesViewModel(); // Creating a student object - this is the Model that will be used within the View Model Student crazyHoe = new Student("Crazy Hoe", 3, "MMSC - Magical Mysterious Science College"); // Populate the View Model's student field with the instance of Student created above. studentGradesViewModel.Student = crazyHoe; //// Hard-code the elements of the View Model's gradebook field //studentGradesViewModel.GradeBook.Add(new Grade("DADA330/Defense Against the Dark Arts", true)); //studentGradesViewModel.GradeBook.Add(new Grade("CLHC120/Fine Wines of the World", true)); //studentGradesViewModel.GradeBook.Add(new Grade("WHEE420/Diabetes Synthesis and Dissolution", false)); //studentGradesViewModel.GradeBook.Add(new Grade("MATH520/Thesis in Stupidity", false)); //studentGradesViewModel.GradeBook.Add(new Grade("IGME106/mAgIc mAKeR sTuDIo", true)); //studentGradesViewModel.GradeBook.Add(new Grade("FREE333/Free Real Estate", true)); // Instantiate the DAL wherever it is needed - in this case, to read from and print to the screen. StudentGradeDAL studentGradeDAL = new StudentGradeDAL(); // .ToList creates and returns a list from the specified gradebook entry. Assign Gradebook within the // DAL to this list. studentGradesViewModel.GradeBook = studentGradeDAL.GradeBook.ToList(); // Changing display ResultColour of Grade Passed string // This is done in the controller because it has direct access to the GradeBook List of Grade objects. foreach (Grade grade in studentGradesViewModel.GradeBook) { grade.ResultColor = grade.Passed.ToLower() == "pass" ? "color:Green" : "color:Red"; } // Pass the View Model object into the View upon returning it, so all its class fields can be utilised. // As always, not specifying string viewName will cause VS to look for a View whose name matches that // of the method name - in this case ResultsStatement. return(View(studentGradesViewModel)); }
public IActionResult StudentGrades(Guid?studentUID) { ViewBagMethod(); Guid sUID; if (studentUID == null) { sUID = CurrentUser.PersonUID ?? Guid.Empty; } else { sUID = studentUID ?? Guid.Empty; } var list = _examResultsService.GetByPersonUID(sUID); StudentGradesViewModel viewModel = new StudentGradesViewModel(); viewModel.ExamResults = list; if (list.Count > 0) { viewModel.Student = list.FirstOrDefault().PersonU.PersonU; } return(View(viewModel)); }
public void AddGrade(StudentGradesViewModel vm, int selectedStudent) { _unitOfWork.SchoolGrades.AddGrade(vm.NewGrade, vm.Teacher.Id, vm.Subject.Id, selectedStudent); _unitOfWork.Complete(); }
public ActionResult Find(StudentGradesViewModel m) { if (m.From == null || m.To == null) { return(Content("Некорректные значения даты")); } List <StudentGeneralViewModel> gmodel = new List <StudentGeneralViewModel>(); List <Grade> grades = new List <Grade>(); List <Course> courses = new List <Course>(); if (m.CourseId == null) { /*Определяем набор курсов для ученика, путем сравнения *курсов из таблиц ClassCourses и Courses для получения * доп информации о курсе, т.к в первой тб. имеется только его id*/ var class_courses = data_storage.ClassCourses.Where(c => c.ClassId.Equals(UserSession.Uinform.Student.ClassId)); if (class_courses == null) { return(HttpNotFound()); } var school_courses = data_storage.Courses.Where(c => c.SchoolId.Equals(UserSession.Uinform.Student.SchoolId)).ToArray(); //Долгая и некрасивая операция foreach (var cc in class_courses) { foreach (var sc in school_courses) { if (cc.CourseId.Equals(sc.CourseId)) { courses.Add(new Course() { CourseId = sc.CourseId, CourseName = sc.CourseName, SchoolId = sc.SchoolId, SubjectId = sc.SubjectId, TeacherId = sc.TeacherId }); } } } } else { int id = Convert.ToInt32(m.CourseId); courses = data_storage.Courses.Where(c => c.CourseId.Equals(id)).ToList(); } foreach (var course in courses) { gmodel.Add(new StudentGeneralViewModel() { CourseName = course.CourseName, Grades = data_storage.Grades.Where(c => c.StudentId.Equals(UserSession.Uinform.Student.StudentId) && c.CourseId.Equals(course.CourseId) && c.Date >= m.From && c.Date <= m.To).ToList() }); } ViewBag.from = m.From; ViewBag.to = m.To; return(View(gmodel)); }