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")); }