public IActionResult Get(PlantListRequestDto request) { if (!_plantPropertyMappingService.ValidMappingExists(request.SortBy)) { return(BadRequest("property mapping doesn't exist")); } var sgId = User.Identity.Name; var query = _repository.FindBy <Plant>(p => !p.IsDeleted && p.Users.Any(up => up.User.UserName == sgId)); if (!string.IsNullOrWhiteSpace(request.Search)) { query = query.Where(p => p.Name.Contains(request.Search) || p.GaiaCode.Contains(request.Search)); } var result = query.ApplySort(request.SortBy, request.IsDescending, _plantPropertyMappingService.PropertyMappings) .ToPagedList <Plant>(request.PageNumber, request.PageSize); var plants = Mapper.Map <PagedList <Plant>, PagedList <PlantListDto> >(result); return(Ok(plants)); }
public IActionResult Get(int?pageNumber, int?pageSize, string sortBy, bool isDescending) { if (!_userPropertyMappingService.ValidMappingExists(sortBy)) { return(BadRequest("property mapping doesn't exist")); } var sgid = User.Identity.Name; var myPlantIds = _repository.FindBy <UserPlant>(up => up.User.UserName == sgid).Select(up => up.PlantId); var result = _repository.FindBy <UserPlant>(up => myPlantIds.Contains(up.PlantId)) .Select(up => up.User) .Distinct() .ApplySort(sortBy, isDescending, _userPropertyMappingService.PropertyMappings) .ToPagedList(pageNumber, pageSize); var users = Mapper.Map <PagedList <User>, PagedList <UserListDto> >(result); return(Ok(users)); }