public async Task <PagedResult <UserViewModel> > GetUserPaging(GetUserPagingRequest request) { var query = _userManager.Users; if (!string.IsNullOrEmpty(request.KeyWord)) { query = query.Where(x => x.UserName.Contains(request.KeyWord) || x.PhoneNumber.Contains(request.KeyWord)); } //3. Paging int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new UserViewModel() { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, PhoneNumber = x.PhoneNumber, }).ToListAsync(); //4. Select and projection var pagedResult = new PagedResult <UserViewModel>() { TotalRecord = totalRow, Items = data }; return(pagedResult); }
public async Task <IActionResult> Index(string keyword, Status?status, int pageIndex = 1, int pageSize = 3) { if (!ModelState.IsValid) { return(View(ModelState)); } var request = new GetUserPagingRequest() { Keyword = keyword, PageIndex = pageIndex, PageSize = pageSize, Status = status }; ViewBag.Keyword = keyword; ViewBag.Statuss = Enum.GetValues(typeof(Status)).Cast <Status>() .Select(x => new SelectListItem() { Text = x.ToString(), Value = ((int)x).ToString(), Selected = status.HasValue && status.ToString() == x.ToString() }).ToList(); if (TempData["Result"] != null) { ViewBag.SuccessMsg = TempData["Result"]; } var data = await _userApiClient.GetUserPaging(request); return(View(data.ResultObj)); }
public async Task <PagedResult <UserViewModel> > GetUserPaging(GetUserPagingRequest request) { var query = userManager.Users; if (!string.IsNullOrEmpty(request.Keyword)) { query = query.Where(x => x.UserName.Contains(request.Keyword) || x.PhoneNumber.Contains(request.Keyword)); } int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize).Take(request.PageSize) .Select(x => new UserViewModel() { Id = x.Id, Address = x.Address, Company = x.Company, DoB = x.DoB, Facebook = x.Facebook, FullName = x.FullName, Gender = x.Gender, ImagePath = x.ImagePath, IsDelete = x.IsDelete }).ToListAsync(); var PagedResult = new PagedResult <UserViewModel>() { TotalRecord = totalRow, Items = data }; return(PagedResult); }
public async Task <ApiResult <PagedResult <UserVM> > > GetUsersPaging(GetUserPagingRequest request) { var query = _userManager.Users; if (!string.IsNullOrEmpty(request.Keyword)) { query = query.Where(x => x.UserName.Contains(request.Keyword) || x.PhoneNumber.Contains(request.Keyword)); } var totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize).Take(request.PageSize) .Select(x => new UserVM() { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, DoB = x.DoB, UserName = x.UserName, Email = x.Email }).ToListAsync(); ; var pagedResult = new PagedResult <UserVM> { PageIndex = request.PageIndex, PageSize = request.PageSize, Items = data, TotalRecords = totalRow }; return(new ApiSuccessResult <PagedResult <UserVM> >(pagedResult)); }
public async Task <ApiResult <PagedResult <UserVm> > > GetUsersPaging(GetUserPagingRequest request) { var query = await GetAllUserAsync(request); int totalRow = query.Count(); var data = query.Skip((request.PageIndex - 1) * request.PageSize) .Take(request.PageSize) .Select(x => x) .ToList(); var pageResult = new PagedResult <UserVm>() { TotalRecords = totalRow, PageIndex = request.PageIndex, PageSize = request.PageSize, Items = data }; if (data is null) { return(new ApiErrorResult <PagedResult <UserVm> >("No records found")); } return(new ApiSuccessResult <PagedResult <UserVm> >(pageResult)); }
private async Task <List <UserVm> > GetAllUserAsync(GetUserPagingRequest filter) { List <User> users = await _repository.UserRepo.FindByCondition(x => x.Status != UserStatus.Disable) .ToListAsync(); List <UserVm> userRequests = _mapper.Map <List <User>, List <UserVm> >(users); if (!string.IsNullOrEmpty(filter.Email)) { userRequests = userRequests.Where(x => x.Email.Contains(filter.Email)).ToList(); } if (!string.IsNullOrEmpty(filter.Name)) { userRequests = userRequests.Where(x => x.FirstName.Contains(filter.Name) || x.LastName.Contains(filter.Name)).ToList(); } if (filter.Limit != null) { userRequests = userRequests.OrderByDescending(x => x.Id) .Skip(filter.Limit.Value * (filter.Offset.Value - 1)) .Take(filter.Limit.Value).ToList(); } if (filter.OrderBy != null) { userRequests = userRequests.OrderBy(x => x.GetType().GetProperty(filter.OrderBy).GetValue(x, null)).ToList(); } return(userRequests); }
public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 5) { var request = new GetUserPagingRequest() { Keyword = keyword, PageIndex = pageIndex, PageSize = pageSize }; var data = await _userApiClient.GetUsersPagings(request); ViewBag.Keyword = keyword; return(View(data.ResultObj)); //if (TempData["showuser"] != null) //{ // var st = TempData["showuser"] as string; // string[] arrListStr = st.Split('~'); // ViewBag.SuccessMsg = "ShowUser"; // ViewBag.AddUser = new UserNameVm() // { // Code = arrListStr[0], // UserName = arrListStr[1], // Password = arrListStr[2] // }; //} }
// lấy ra UserPaging và appsettings.Development của AdminApp sửa public async Task <ApiResult <PagedResult <UserVm> > > GetUsersPagings(GetUserPagingRequest request) // dùng thằng này cho UserController của GetAllPaging { var data = await GetAsync <ApiResult <PagedResult <UserVm> > >($"/api/users/paging?pageIndex=" + $"{request.PageIndex}&pageSize={request.PageSize}&keyword={request.KeyWord}"); // đường dẫ lấy bên UserController của Api nó sẽ theo request trả về return(data); }
public async Task <ApiResult <PagedResult <UserVm> > > GetUsersPaging(GetUserPagingRequest request) { var query = _userManager.Users; if (!string.IsNullOrEmpty(request.KeyWord)) { query = query.Where(x => x.UserName.Contains(request.KeyWord) || x.PhoneNumber.Contains(request.KeyWord)); } int totalRow = await query.CountAsync(); var data = await query.Skip((request.PageIndex - 1) *request.PageSize) .Take(request.PageSize) .Select(x => new UserVm() { Email = x.Email, PhoneNumber = x.PhoneNumber, UserName = x.UserName, FirstName = x.FirstName, Id = x.Id, LastName = x.LastName }).ToListAsync(); //4. Select and projection var pagedResult = new PagedResult <UserVm>() { TotalRecords = totalRow, PageIndex = request.PageIndex, PageSize = request.PageSize, Items = data }; return(new ApiSuccessResult <PagedResult <UserVm> >(pagedResult)); }
//ĐÂY LÀ TÌM KIẾM VƠI KEYWORD BÊN Default đã thự hiện cộng key word nếu thấy để gữ lại đối tượng khi tìm thấy mà nó vẫn sử dụng được phân trang ,chỉ khi reset nó mới ko cộng keyword sang Default mà xem nhe public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 6) // gán mặc định nếu không có giá trị nào ,pageSize được tính rồi nhe tính cho phân trang { //phải add 1 view là viewName Index ,Template List ,Model class UserVm , use Layout chúng có sẵn tải về //từ Token này ta phải ra một cái Request var request = new GetUserPagingRequest() { PageIndex = pageIndex, PageSize = pageSize, KeyWord = keyword }; var data = await _userApiClient.GetUsersPagings(request); // để giữ lại giá trị hiển thị tren ô tìm kiếm ta dùng viewBag chuyền về cho view if (keyword != null) { ViewBag.keyword = keyword;// tự động view sẽ nhận được } if (TempData["result"] != null) { //bên này đã nhận được TempData đấy // ta sẽ show nó bên view ViewBag.SuccessMsg = TempData["result"]; } return(View(data.ResultObj)); }
public async Task <APIResult <PageResult <UserViewModel> > > GetUserPaging(GetUserPagingRequest request) { var query = _userManager.Users; if (!string.IsNullOrEmpty(request.keyword)) { query = query.Where(x => x.UserName.Contains(request.keyword) || x.Email.Contains(request.keyword)); } int totalRow = await query.CountAsync(); var data = await query.Skip((request.pageIndex - 1) *request.pageSize) .Take(request.pageSize) .Select(x => new UserViewModel() { ID = x.Id, Username = x.UserName, Password = x.PasswordHash, PhoneNumber = x.PhoneNumber, Email = x.Email }).ToListAsync(); var pageResult = new PageResult <UserViewModel>() { TotalRecord = totalRow, PageIndex = request.pageIndex, PageSize = request.pageSize, Items = data }; return(new APISuccessedResult <PageResult <UserViewModel> >(pageResult)); }
public async Task <ApiResult <PagedResult <UserViewModel> > > GetAllPaging(GetUserPagingRequest request) { var query = _userManager.Users; if (!string.IsNullOrEmpty(request.Keyword)) { query = query.Where(x => x.FirstName.Contains(request.Keyword) || x.PhoneNumber.Contains(request.Keyword)); } int totalRow = await query.CountAsync(); //nếu pageIndex = 2 thì sẽ lược bỏ (2-1)*pageSize(=10)=10 bản ghi đầu var data = await query.Skip((request.pageIndex - 1) *request.pageSize) .Take(request.pageSize) .Select(x => new UserViewModel() { FirstName = x.FirstName, Email = x.Email, Id = x.Id, PhoneNumber = x.PhoneNumber, LastName = x.LastName, DayOfBirth = x.DayOfBirth, }).ToListAsync(); var pagedResullt = new PagedResult <UserViewModel>() { TotalRecords = totalRow, pageSize = request.pageSize, pageIndex = request.pageIndex, Items = data, }; return(new ApiSuccessResult <PagedResult <UserViewModel> >(pagedResullt)); }
public async Task <ApiResult <PagedResult <UserVm> > > GetUsersPagings(GetUserPagingRequest request) { var data = await GetAsync <ApiResult <PagedResult <UserVm> > >( $"/api/users/paging?pageIndex={request.PageIndex}" + $"&pageSize={request.PageSize}" + $"&keyword={request.Keyword}"); return(data); }
public async Task <PagedResult <WorkingscheduleViewModel> > GetAll(GetUserPagingRequest request) { var result = await GetAsync <PagedResult <WorkingscheduleViewModel> >( "/api/products/listWorkingSchedule?pageIndex=" + $"{request.PageIndex}&pageSize={request.PageSize}" + $"&keyword={request.Keyword}"); return(result); }
public async Task <IActionResult> GetAllPaging([FromQuery] GetUserPagingRequest request) { if (ModelState.IsValid == false) { return(BadRequest()); } var user = await _userService.GetUserPaging(request); return(Ok(user)); }
public async Task <IActionResult> GetAllUserPaging([FromQuery] GetUserPagingRequest request) { var result = await _userService.GetUsersPaging(request); if (!result.IsSuccessed) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 1) { var request = new GetUserPagingRequest() { Keyword = keyword, PageIndex = pageIndex, PageSize = pageSize }; var data = await _userApiClient.GetUsersPagings(request); return(View(data.ResultObj)); }
public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 5) { var sessions = HttpContext.Session.GetString("Token"); var request = new GetUserPagingRequest() { Keyword = keyword, pageIndex = pageIndex, pageSize = pageSize }; var data = await _userApiClient.GetUsersPagings(request); return(View(data.ResultObj)); }
public async Task <IActionResult> GetUserpaging([FromQuery] GetUserPagingRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = await _userService.GetUsersPaging(request); if (user == null) { return(BadRequest()); } return(Ok(user)); }
public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 10) { var session = HttpContext.Session.GetString("Token"); var request = new GetUserPagingRequest() { BearerToken = session, Keyword = keyword, PageIndex = pageIndex, PageSize = pageSize }; var data = await userApiClient.GetUserPadings(request); return(View(data)); }
public IActionResult Index(GetUserPagingRequest request) { var data = (ObjectResult)_usersController.GetAllUserPaging(request).Result; var users = (ApiResult <PagedResult <UserVm> >)data.Value; if (users is null) { return(View()); } ViewBag.Role = users.Message; return(View(users.ResultObj)); }
public async Task <IActionResult> IndexWS(string keyword, int pageIndex = 1, int pageSize = 3) { var request = new GetUserPagingRequest() { Keyword = keyword, PageIndex = pageIndex, PageSize = pageSize }; ViewBag.Keyword = keyword; var categories = await _productApiClient.GetAll(request); return(View(categories)); }
public async Task <PagedResult <UserVm> > GetUsersPagings(GetUserPagingRequest request) { var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", request.BearerToken); var response = await client.GetAsync($"/api/users/paging?pageIndex=" + $"{request.PageIndex}&pageSize={request.PageSize}&keyword={request.Keyword}"); var body = await response.Content.ReadAsStringAsync(); var users = JsonConvert.DeserializeObject <PagedResult <UserVm> >(body); return(users); }
public async Task <APIResult <PageResult <UserViewModel> > > GetUserPaging(GetUserPagingRequest request) { var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); var session = _httpContextAccessor.HttpContext.Session.GetString("Token"); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", session); var reponse = await client.GetAsync($"/api/User/paging?pageIndex={request.pageIndex}&pageSize={request.pageSize}&keyword={request.keyword}"); var body = await reponse.Content.ReadAsStringAsync(); var user = JsonConvert.DeserializeObject <APIResult <PageResult <UserViewModel> > >(body); return(user); }
public async Task <PagedResult <UserViewModel> > GetUserPadings(GetUserPagingRequest request) { var client = httpClientFactory.CreateClient(); client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", request.BearerToken); client.BaseAddress = new Uri("https://localhost:44373/api/"); var response = await client.GetAsync($"User/paging?Keyword={request.Keyword}&PageIndex={request.PageIndex}" + $"&PageSize={request.PageSize}&BearerToken={request.BearerToken}"); var body = await response.Content.ReadAsStringAsync(); var users = JsonConvert.DeserializeObject <PagedResult <UserViewModel> >(body); return(users); }
public async Task <ApiResult <PageResult <UserViewModel> > > GetUserPaging(GetUserPagingRequest request) { //1.Query var query = _userManager.Users; if (!string.IsNullOrEmpty(request.Keyword)) { query = query.Where(x => x.UserName.Contains(request.Keyword) || x.PhoneNumber.Contains(request.Keyword) || x.FirstName.Contains(request.Keyword) || x.LastName.Contains(request.Keyword) || x.Email.Contains(request.Keyword) || x.Dob.ToString().Contains(request.Keyword)); } if (request.Status != null) { query = query.Where(x => x.Status == request.Status); } //3.Paging int totalRow = await query.CountAsync(); var data = query.Skip((request.PageIndex - 1) * request.PageSize) .Take(request.PageSize) .Select(x => new UserViewModel() { Id = x.Id, FirstName = x.FirstName, LastName = x.LastName, UserName = x.UserName, Dob = x.Dob, Email = x.Email, PhoneNumber = x.PhoneNumber, Status = x.Status }).ToListAsync(); //4.Select and Projection var pageResult = new PageResult <UserViewModel>() { TotalRecord = totalRow, Item = await data, PageSize = request.PageSize, PageIndex = request.PageIndex }; return(new ApiSuccessResult <PageResult <UserViewModel> >(pageResult)); }
public async Task <IActionResult> Index(string keyword, int pageIndex = 1, int pageSize = 10) { var request = new GetUserPagingRequest() { Keyword = keyword, PageIndex = pageIndex, PageSize = pageSize }; var data = await _userApiClient.GetUsersPagings(request); ViewBag.Keyword = keyword; if (TempData["result"] != null) { ViewBag.SuccessMsg = TempData["result"]; } return(View(data.ResultObj)); }
public async Task <ApiResult <PagedResult <UserVm> > > GetUsersPagings(GetUserPagingRequest request) { var sessions = _httpContextAccessor.HttpContext.Session.GetString("Token"); var client = _httpClientFactory.CreateClient(); client.BaseAddress = new Uri(_configuration["BaseAddress"]); //gán vào header tên là Bearer để authorization. Vì header này mà server mới biết là user nào đang request client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions); var response = await client.GetAsync($"/api/users/paging?Keyword={request.Keyword}" + $"&pageIndex={request.pageIndex}&pageSize={request.pageSize}"); var body = await response.Content.ReadAsStringAsync(); var user = JsonConvert.DeserializeObject <ApiSuccessResult <PagedResult <UserVm> > >(body); return(user); }
public async Task <ApiResult <PagedResult <UserVm> > > GetUsersPagings(GetUserPagingRequest request) { var client = _httpClientFactory.CreateClient(); var sessions = _httpContextAccessor.HttpContext.Session.GetString("Token"); client.BaseAddress = new Uri(_configuration[SystemConstants.AppSettings.BaseAddress]); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", sessions); var response = await client.GetAsync($"/api/user/paging?pageIndex=" + $"{request.PageIndex}&pageSize={request.PageSize}&keyword={request.Keyword}"); var body = await response.Content.ReadAsStringAsync(); var users = JsonConvert.DeserializeObject <ApiSuccessResult <PagedResult <UserVm> > >(body); return(users); }
public async Task <ActionResult> Index(string keywork, int pageIndex = 1, int pageSize = 5) { //var sessions = HttpContext.Session.GetString("Token"); var request = new GetUserPagingRequest() { Keyword = keywork, PageIndex = pageIndex, PageSize = pageSize }; var data = await _userApiClient.GetUsersPagings(request); ViewBag.Keywork = keywork; if (TempData["result"] != null) { ViewBag.SuccessMsg = TempData["result"]; } return(View(data.ResultObj)); }