public async Task <IActionResult> GradeCreate(GradeCreateInputModel model) { if (this.ModelState.IsValid) { var serviceModel = model.To <GradeServiceModel>(); var result = await this.gradeService.CreateGradeAsync(serviceModel); var studentId = serviceModel.StudentId; var subjectId = serviceModel.SubjectId; var subject = await this.classService.GetSubjectById(subjectId); var student = await this.studentService.GetStudentByIdAsync(studentId); if (result) { return(this.RedirectToAction("GradesPerSubject", new { id = model.SubjectId, studentId = model.StudentId })); } this.ViewBag.StudentId = studentId; this.ViewBag.SubjectId = subjectId; this.ViewBag.SubjectName = subject.Subject.Name; this.ViewBag.StudentName = student.FullName; return(this.View(model)); } return(this.View(model)); }
public IActionResult AddGrade(int studentId, int subjectId, int teacherId) { var student = _studentsService.GetById <StudentViewModel>(studentId); var inputModel = new GradeCreateInputModel { Grade = new GradeInputModel { TeacherId = teacherId, StudentId = studentId, SubjectId = subjectId, }, StudentName = $"{student.FirstName} {student.LastName}" }; return(View(inputModel)); }
public async Task <IActionResult> AddGrade(GradeCreateInputModel inputModel) { if (!ModelState.IsValid) { return(View(inputModel)); } try { await _gradesService.CreateAsync(inputModel.Grade); return(RedirectToAction("ById", "Subjects", new { area = string.Empty, id = inputModel.Grade.SubjectId })); } catch (Exception e) { _logger.LogError(e, $"An exception occured during new grade record creation. Ex: {e.Message}"); return(RedirectToAction("Error", "Home")); } }