public IActionResult GetStudents([FromQuery] StudentQueryParameters studentResourceParameters) { if (!typeChecker.CheckIfTypeHasPoperties(studentResourceParameters.Fields, typeof(StudentDto))) { return(BadRequest()); } // Get data from repository (including sorting and filtering) var studentsFromRepo = studentsRepo.GetStudents(studentResourceParameters); // Map from Students enitty to StudentsDto IEnumerable <StudentDto> students = Mapper.Map <IEnumerable <StudentDto> >(studentsFromRepo); // Perform data shaping and return value return(Ok(students.ShapeData(studentResourceParameters.Fields))); }
public async Task <Unit> Handle(UpdateStudentProfileRequest request, CancellationToken cancellationToken) { var queryParams = new StudentQueryParameters { Id = _executionContextService.GetCurrentUserId(), IsReadOnly = false, }; var student = await _unitOfWork.GetSingle(queryParams); _mapper.Map(request.Data, student); await _unitOfWork.Update(student); await _unitOfWork.Commit(); return(default);
public PagedList <Students> GetStudents(StudentQueryParameters stParam) { var collection = context.Students.AsQueryable(); if (!string.IsNullOrWhiteSpace(stParam.Id) && int.TryParse(stParam.Id, out var intId)) { collection = collection.Where(st => st.StudentId == intId); } if (!string.IsNullOrWhiteSpace(stParam.LastName)) { collection = collection.Where(st => st.LastName.Contains(stParam.LastName, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrWhiteSpace(stParam.FirstName)) { collection = collection.Where(st => st.FirstName.Contains(stParam.FirstName, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrWhiteSpace(stParam.PhoneNumber)) { collection = collection.Where(st => st.PhoneNumber.Contains(stParam.PhoneNumber, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrWhiteSpace(stParam.Email)) { collection = collection.Where(st => st.Email.Contains(stParam.Email, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrWhiteSpace(stParam.City)) { collection = collection.Where(st => st.City.Contains(stParam.City, StringComparison.OrdinalIgnoreCase)); } if (!string.IsNullOrWhiteSpace(stParam.Adress)) { collection = collection.Where(st => st.Adress.Contains(stParam.Adress, StringComparison.OrdinalIgnoreCase)); } collection = ReflectionHelper.PerformSorting <Students>(stParam.OrderBy, collection); return(PagedList <Students> .Create(collection, stParam.PageNumber, stParam.PageSize)); }
public async Task <IReadOnlyCollection <StudentGroupedGroupDto> > Handle(GetStudentsGroupsRequest request, CancellationToken cancellationToken) { var queryParameters = new StudentQueryParameters { IsUniq = true, }; var result = await _unitOfWork.GetAll(queryParameters, student => new { student.Id, student.Group, }); return(result .GroupBy(e => e.Group, arg => arg.Id) .Select(group => new StudentGroupedGroupDto { GroupName = group.Key, StudentsIds = group.ToArray(), }).ToArray()); }
public Task <IQueryable <StudentProfileDto> > Handle(GetStudentProfileRequest request, CancellationToken cancellationToken) { var queryParameters = new StudentQueryParameters(_executionContextService.GetCurrentUserId()); return(Task.FromResult(_queryProvider.Queryable(queryParameters).Select(StudentProfileDto.Selector))); }