public static StudentQueryDto ToQueryDto(this Student value) { if (value is null) { throw new ArgumentNullException(nameof(value)); } var dto = new StudentQueryDto { StudentId = value.StudentId, }; if (!(value.Person is null)) { dto.Person = new PersonQueryDto { PersonId = value.Person.PersonId, Name = value.Person.Name, BirthDate = value.Person.BirthDate }; } if (!(value.TuitionAgency is null)) { dto.TuitionAgencyId = value.TuitionAgency?.TuitionAgencyId ?? throw new Exception("TuitionAgency member null"); } if (!(value.CoursesRegistered is null)) { dto.CoursesRegistered = value.CoursesRegistered?.Select(course => course.CourseId).ToList(); } return(dto); }
public IList <Student> QueryStudents(StudentQueryDto studentQueryDto) { Func <Student, bool> func = s => !s.IsDeleted; if (!string.IsNullOrEmpty(studentQueryDto.Name)) { func += s => s.Name.Equals(studentQueryDto.Name, StringComparison.InvariantCultureIgnoreCase); } if (!string.IsNullOrEmpty(studentQueryDto.StudentNo)) { func += s => s.StudentNo.Equals(studentQueryDto.StudentNo, StringComparison.InvariantCultureIgnoreCase); } var studentsAfterFilter = Students.Where(func).ToList(); return(studentsAfterFilter); }
public ActionResult <List <Student> > GetStudentList([FromQuery] StudentQueryDto queryDto) { var students = _studentService.QueryStudents(queryDto).ToList(); return(Ok(GeneralResponse <List <Student> > .Ok(students))); }