//-> GetList public async Task<GetListDTO<UserViewDTO>> GetList(UserFindDTO findDTO) { /* //--seem like search sql not dynamic -> should write one helper function or interface to do dynamic search IQueryable<tblUser> records = from x in db.tblUsers where x.deleted == null && (string.IsNullOrEmpty(findDTO.userName) ? 1 == 1 : x.userName.Contains(findDTO.userName)) && (string.IsNullOrEmpty(findDTO.firstName) ? 1 == 1 : x.firstName.Contains(findDTO.firstName)) && (string.IsNullOrEmpty(findDTO.lastName) ? 1 == 1 : x.userName.Contains(findDTO.lastName)) orderby x.firstName ascending select x; return await Listing(findDTO.currentPage, records); */ /* IQueryable<tblUser> records = from x in db.tblUsers where x.deleted == null && (string.IsNullOrEmpty(findDTO.userName) ? 1 == 1 : x.userName.Contains(findDTO.userName)) && (string.IsNullOrEmpty(findDTO.firstName) ? 1 == 1 : x.firstName.Contains(findDTO.firstName)) && (string.IsNullOrEmpty(findDTO.lastName) ? 1 == 1 : x.userName.Contains(findDTO.lastName)) select x; return await Listing(findDTO.currentPage, records.AsQueryable().OrderBy($"{findDTO.orderBy} {findDTO.orderDirection}")); */ IQueryable<tblUser> query = db.tblUsers.Where(x => x.deleted == null); if (!string.IsNullOrEmpty(findDTO.userName)) query = query.Where(x => x.userName.StartsWith(findDTO.userName)); if (!string.IsNullOrEmpty(findDTO.firstName)) query = query.Where(x => x.firstName.StartsWith(findDTO.firstName)); if (!string.IsNullOrEmpty(findDTO.lastName)) query = query.Where(x => x.lastName.StartsWith(findDTO.lastName)); query = query.AsQueryable().OrderBy($"{findDTO.orderBy} {findDTO.orderDirection}"); return await ListingHandler(findDTO.currentPage, query); }
public JsonResult Find(UserFindDTO param) { var query = UserManager.Users.AsQueryable(); if (!string.IsNullOrEmpty(param.Email)) { query = query.Where(t => t.Email.StartsWith(param.Email)); } int total = query.Count(); if (param.SortBy == "email" && param.SortDir == "asc") { query = query.OrderBy(t => t.Email); } else if (param.SortBy == "email" && param.SortDir == "desc") { query = query.OrderByDescending(t => t.Email); } else { query = query.OrderBy(t => t.Email); } int pages = (int)Math.Ceiling((double)total / param.PageSize); int skip = (param.PageNumber - 1) * param.PageSize; var data = query.Skip(skip).Take(param.PageSize) .Select(t => new UserLiteDTO { Id = t.Id, Email = t.Email }).ToList(); var dto = new PageListDTO <IEnumerable <UserLiteDTO> >() { Total = total, Data = data }; return(Json(dto, JsonRequestBehavior.AllowGet)); }
public async Task <ActionResult> Paging(UserFindDTO findDTO) { return(PartialView(await handler.GetList(findDTO))); }