public PagedList <UserViewModel> ListUser(UserRequestListViewModel userRequestListViewModel) { var query = _repository.GetAll().Include(x => x.UserInRoles).ThenInclude(user => user.AppRole) .Where(x => ((string.IsNullOrEmpty(userRequestListViewModel.keyword)) || (x.Email.Contains(userRequestListViewModel.keyword)) || (x.Name.Contains(userRequestListViewModel.keyword)))) .Select(x => new UserViewModel(x)).ToList(); var userViewModelProperties = GetAllPropertyNameOfUserViewModel(); var requestPropertyName = !string.IsNullOrEmpty(userRequestListViewModel.SortName) ? userRequestListViewModel.SortName.ToLower() : string.Empty; string matchedPropertyName = string.Empty; foreach (var userViewModelProperty in userViewModelProperties) { var lowerTypeViewModelProperty = userViewModelProperty.ToLower(); if (lowerTypeViewModelProperty.Equals(requestPropertyName)) { matchedPropertyName = userViewModelProperty; break; } } if (string.IsNullOrEmpty(matchedPropertyName)) { matchedPropertyName = "Name"; } var type = typeof(UserViewModel); var sortProperty = type.GetProperty(matchedPropertyName); query = userRequestListViewModel.IsDesc ? query.OrderByDescending(x => sortProperty.GetValue(x, null)).ToList(): query.OrderBy(x => sortProperty.GetValue(x, null)).ToList(); return(new PagedList <UserViewModel>(query, userRequestListViewModel.offset ?? CommonConstants.Config.DEFAULT_SKIP, userRequestListViewModel.limit ?? CommonConstants.Config.DEFAULT_TAKE)); }
public PagedList <ProductCategoryViewModel> GetList(UserRequestListViewModel userRequestListViewModel) { var query = _productCategoryRepository.GetAll().Where(x => ((string.IsNullOrEmpty(userRequestListViewModel.keyword)) || (x.Name.Contains(userRequestListViewModel.keyword)))) .OrderByDescending(x => x.DateCreated) .Select(x => new ProductCategoryViewModel(x)).ToList(); var productCategoryViewModelProperties = GetAllPropertyNameOfProductCategoryViewModel(); var requestPropertyName = !string.IsNullOrEmpty(userRequestListViewModel.SortName) ? userRequestListViewModel.SortName.ToLower() : string.Empty; string matchedPropertyName = string.Empty; foreach (var productCategoryViewModelProperty in productCategoryViewModelProperties) { var lowerTypeViewModelProperty = productCategoryViewModelProperty.ToLower(); if (lowerTypeViewModelProperty.Equals(requestPropertyName)) { matchedPropertyName = productCategoryViewModelProperty; break; } } if (string.IsNullOrEmpty(matchedPropertyName)) { matchedPropertyName = "Name"; } var type = typeof(ProductViewModel); var sortProperty = type.GetProperty(matchedPropertyName); query = userRequestListViewModel.IsDesc ? query.OrderByDescending(x => sortProperty.GetValue(x, null)).ToList() : query.OrderBy(x => sortProperty.GetValue(x, null)).ToList(); return(new PagedList <ProductCategoryViewModel>(query, userRequestListViewModel.offset ?? CommonConstants.Config.DEFAULT_SKIP, userRequestListViewModel.limit ?? CommonConstants.Config.DEFAULT_TAKE)); }
public async Task <PagedList <UserViewModel> > ListUserAsync(UserRequestListViewModel userRequestListViewModel) { var list = await GetAll() .Where(x => (!userRequestListViewModel.IsActive.HasValue || x.RecordActive == userRequestListViewModel.IsActive) && (string.IsNullOrEmpty(userRequestListViewModel.Query) || (x.Name.Contains(userRequestListViewModel.Query) || (x.Email.Contains(userRequestListViewModel.Query) )))) .Select(x => new UserViewModel(x)).ToListAsync(); var userViewModelProperties = GetAllPropertyNameOfUserViewModel(); var requestPropertyName = !string.IsNullOrEmpty(userRequestListViewModel.SortName) ? userRequestListViewModel.SortName.ToLower() : string.Empty; string matchedPropertyName = userViewModelProperties.FirstOrDefault(x => x.ToLower() == requestPropertyName); if (string.IsNullOrEmpty(matchedPropertyName)) { matchedPropertyName = "Name"; } var type = typeof(UserViewModel); var sortProperty = type.GetProperty(matchedPropertyName); list = userRequestListViewModel.IsDesc ? list.OrderByDescending(x => sortProperty.GetValue(x, null)).ToList() : list.OrderBy(x => sortProperty.GetValue(x, null)).ToList(); return(new PagedList <UserViewModel>(list, userRequestListViewModel.Skip ?? CommonConstants.Config.DEFAULT_SKIP, userRequestListViewModel.Take ?? CommonConstants.Config.DEFAULT_TAKE)); }
public PagedList <RoleViewModel> ListRole(UserRequestListViewModel userRequestListViewModel) { var query = _repository.GetAll().Include(x => x.UserInRoles).ThenInclude(user => user.AppRole) .Where(x => ((string.IsNullOrEmpty(userRequestListViewModel.keyword)) || (x.name.Contains(userRequestListViewModel.keyword)))) .Select(x => new RoleViewModel(x)).ToList(); return(new PagedList <RoleViewModel>(query, userRequestListViewModel.offset ?? CommonConstants.Config.DEFAULT_SKIP, userRequestListViewModel.limit ?? CommonConstants.Config.DEFAULT_TAKE)); }
public async Task <IActionResult> Get(UserRequestListViewModel userRequestListViewModel) { var users = await _userService.ListUserAsync(userRequestListViewModel); return(Ok(users)); }
public IActionResult GetList(UserRequestListViewModel userRequestListViewModel) { var model = _userService.ListUser(userRequestListViewModel); return(Ok(model)); }
public IActionResult GetList(UserRequestListViewModel userRequestListViewModel) { var model = _productCategoryService.GetList(userRequestListViewModel); return(Ok(model)); }