public async Task <Page <StudentView> > Handle(StudentsQuery query, CancellationToken cancellationToken)
        {
            var iqSql = _context.Students
                        .AsNoTracking()
                        .Where(_ => _.MentorId == query.UserId &&
                               _.Status == StudentStatus.Active);

            if (!String.IsNullOrEmpty(query.Filter))
            {
                iqSql = iqSql.Where(_ =>
                                    EF.Functions.Like(_.LastName, $"%{query.Filter}%") ||
                                    EF.Functions.Like(_.FirstName, $"%{query.Filter}%") ||
                                    EF.Functions.Like(_.SecondName, $"%{query.Filter}%"));
            }

            return(new Page <StudentView>
            {
                Limit = query.Limit,
                Offset = query.Offset,
                Total = await iqSql.CountAsync(cancellationToken),
                Items = await iqSql
                        .OrderBy(p => p.CreateDate)
                        .Skip(query.Offset)
                        .Take(query.Limit)
                        .Select(_ => new StudentView(
                                    _.Id,
                                    _.PublicId,
                                    _.FirstName,
                                    _.LastName,
                                    _.SecondName,
                                    _.Gender
                                    )).ToArrayAsync(cancellationToken)
            });
        }
Exemplo n.º 2
0
 public async Task <IQueryable <Student> > Handle(StudentsQuery request, CancellationToken cancellationToken)
 {
     return(new Student[]
     {
         new Student(
             Guid.Parse("0f419516-f867-4941-af32-5678279a6349"),
             "first",
             null,
             "last",
             DateTimeOffset.UtcNow.AddYears(-30),
             Gender.Unknown)
     }.AsQueryable());
 }
Exemplo n.º 3
0
        public async Task <ActionResult <IList <StudentsViewModel> > > Students()//todo StudentsViewModel
        {
            StudentsQuery command = new StudentsQuery();

            return(await Send(command));
        }
Exemplo n.º 4
0
            public async Task <IList <StudentsViewModel> > Handle(StudentsQuery request, CancellationToken cancellationToken)
            {
                var allStudents = await _StudentRepository.Students(cancellationToken);

                return(allStudents);
            }