public async Task <StudentResponseModel> PostStudent( [FromForm] StudentRequestModel model, CancellationToken cancellationToken ) { cancellationToken.ThrowIfCancellationRequested(); var command = new CreateStudentCommand( model.FirstName, model.LastName, model.MiddleName, model.Email, model.Avatar, model.GroupId ); var studentId = await _mediator.Send(command, cancellationToken); var query = new FindStudentByIdQuery(studentId); var student = await _mediator.Send(query, cancellationToken); var response = _mapper.Map <StudentResponseModel>(student); return(response); }
public async Task <StudentResponseModel> GetStudent(int studentId, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var query = new FindStudentByIdQuery(studentId); var student = await _mediator.Send(query, cancellationToken); if (student == null) { throw new NotFoundException(nameof(student), studentId); } var response = _mapper.Map <StudentResponseModel>(student); return(response); }