public async Task <IActionResult> AddMark(int studentId, int markId) { var user = await GetCurrentUserAsync(); if (user is TeacherAccount teacher) { var student = _students.GetById(studentId); if (markId > 0) { var mark = _marks.GetById(markId); var model = new AddMarkModel() { Student = student, MarkToEdit = mark }; return(View(model)); } else { var model = new AddMarkModel() { Student = student }; return(View(model)); } } return(RedirectToAction("Error", "Home")); }
public ActionResult AddMark(AddMarkModel model) { Course _course = db.Courses.Find(int.Parse(model.returnUrl.Split('=')[1])); var students = _course.Students; foreach (var item in students) { db.Marks.Add(new Mark() { Description = model.Description, CourseId = _course.Id, Date = model.Date, StudentId = item.Id }); } db.SaveChanges(); return(Redirect(model.returnUrl)); }
public async Task <IActionResult> AddMarkSubmit(AddMarkModel model, int studentId, int markId) { if (ModelState.IsValid && model.MarkValue > 0) { var user = await GetCurrentUserAsync(); if (user is TeacherAccount teacherAccount) { var mark = new Mark() { Teacher = teacherAccount, MarkType = (MarkType)model.MarkValue, Description = model.Description, MarkDate = DateTime.Now }; if (markId == 0) { _students.AddNewMark(studentId, mark); return(RedirectToAction("Index")); } else { _marks.EditMark(markId, mark); var markNew = _marks.GetById(markId); if (markNew.Assignment != null) { var assignmentId = markNew.Assignment.Id; var marks = _marks.GetForAssignmentId(assignmentId); var total = 0; foreach (var m in marks) { total += (int)m.MarkType; } _assignments.SetGraded(markNew.Assignment, total / marks.Count); } return(RedirectToAction("Index")); } } } return(RedirectToAction("Error", "Home")); }