コード例 #1
0
        public async Task <IActionResult> Get()
        {
            var request  = new GetStudentsRequest();
            var response = await _mediator.Send(request);

            return(Ok(response));
        }
コード例 #2
0
        public async Task <List <StudentListModel> > GetStudentsAsync()
        {
            var channel = new Channel(channelTarget, ChannelCredentials.Insecure);

            try
            {
                var client  = new StudentsGrpcService.StudentsGrpcServiceClient(channel);
                var request = new GetStudentsRequest();

                var response = await client.GetStudentsAsync(request);

                var students = response.Students.Select(s => new StudentListModel()
                {
                    Id          = new Guid(s.Id),
                    Address     = s.Address,
                    Name        = s.Name,
                    YearOfBirth = s.YearOfBirth
                }).ToList();


                return(students);
            }
            finally
            {
                await channel.ShutdownAsync();
            }
        }
        public override Task <GetStudentsResponse> GetStudents(GetStudentsRequest request, ServerCallContext context)
        {
            var students = StudentsService.GetStudents().Select(s => new StudentMessage()
            {
                Name        = s.Name,
                Address     = s.Address,
                Id          = s.Id.ToString(),
                YearOfBirth = s.YearOfBirth
            }).ToList();


            var response = new GetStudentsResponse();

            response.Students.AddRange(students);

            return(Task.FromResult(response));
        }
コード例 #4
0
        public async Task <IReadOnlyList <StudentDto> > GetStudents([FromQuery] GetStudentsRequest request)
        {
            var students = await _studentService.GetStudents(request.Filter, request.Pagination);

            return(students);
        }
コード例 #5
0
        public async Task <List <StudentDto> > Handle(GetStudentsRequest request, CancellationToken cancellationToken)
        {
            var students = _studentRepository.GetAll();

            return(students as List <StudentDto>);
        }