public async Task UpdateStudentAsync(Guid studentId, Guid classId, UpsertStudentDto studentDto) { var result = await _executor.ExecuteAsync(new UpdateStudentCommand(classId, studentId, studentDto)); if (!await _context.CommitAsync()) { throw new Exception("Updating an student failed on save."); } if (result.Success) { await _hubContext.Clients.All.InvokeAsync("refresh"); } }
public async Task <Guid> AddStudentAsync(Guid classId, UpsertStudentDto studentDto) { var student = await _executor.ExecuteAsync(new AddStudentCommand(classId, studentDto)); if (!await _context.CommitAsync()) { throw new Exception("Creating an student failed on save."); } if (student.StudentId != null) { await _hubContext.Clients.All.InvokeAsync("refresh"); } return(student.StudentId); }
public async Task <IActionResult> CreateStudent(Guid classId, [FromBody] UpsertStudentDto studentDto) { if (studentDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status422UnprocessableEntity)); } var id = await _studentsService.AddStudentAsync(classId, studentDto); return(Ok(id)); }
public async Task <IActionResult> UpdateStudent(Guid classId, Guid studentId, [FromBody] UpsertStudentDto studentDto) { if (studentDto == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(StatusCode(StatusCodes.Status422UnprocessableEntity)); } await _studentsService.UpdateStudentAsync(studentId, classId, studentDto); return(NoContent()); }
public AddStudentCommand(Guid classId, UpsertStudentDto dto) { _classId = classId; _dto = dto; }
public UpdateStudentCommand(Guid classId, Guid studentId, UpsertStudentDto dto) { _classId = classId; _studentId = studentId; _dto = dto; }