public ActionResult Search([Bind(Include = "UserName, Email, UnitCode, DislayName")] UserSearchModel userModel, int? pageIndex) { int page = 0; int pageCount = 0; if (String.IsNullOrEmpty(userModel.Id) && String.IsNullOrEmpty(userModel.UserName)) { return RedirectToAction("Index"); } if (!String.IsNullOrEmpty(Convert.ToString(pageIndex))) { page = pageIndex.Value; } else page = 1; int a = 2; int totalitem = 0; UserSearchModel userSearch = new UserSearchModel(); userSearch.Id = userModel.Id; userSearch.UserName = userModel.UserName; List<UserModel> value = iUserBussiness.searchUserModel(userSearch, page, ref a , out pageCount, out totalitem); ViewBag.Page = page; ViewBag.PageCount = pageCount; ViewBag.SearchModel = userModel; Session[Constants.Application.Session.ModelSearch] = userModel; return View("Index", new PagedList<UserModel>(value, page, pageCount, totalitem)); }
private IQueryable<UserModel> BuildQuery(UserSearchModel search, int status = 1, bool fInclude = false) { string include = string.Empty; IQueryable<AspNetUser> qUser; if (fInclude) qUser = db.AspNetUsers.Include(a => a.AspNetRoles); else qUser = db.AspNetUsers; IQueryable<UserModel> query = (from u in qUser join uf in db.UserInfoes.Include(c => c.Unit) on u.Id equals uf.Id where uf.Status == status select new UserModel() { Id = u.Id, Email = u.Email, DislayName = uf.DislayName, UnitCode = uf.UnitCode, UnitName = uf.Unit == null ? uf.UnitCode : uf.Unit.UnitName, UserName = u.UserName, PhoneNumber = u.PhoneNumber, Level = uf.Level, LstRole = u.AspNetRoles.ToList() }).OrderBy(a=>a.UserName); if(search != null) { if (!string.IsNullOrWhiteSpace(search.DislayName)) query = query.Where(a => a.DislayName.Contains(search.DislayName)); if (!string.IsNullOrWhiteSpace(search.Email)) query = query.Where(a => a.Email.Contains(search.Email)); if (search.Level > 0) query = query.Where(a => a.Level == search.Level); if (!string.IsNullOrWhiteSpace(search.UnitCode)) query = query.Where(a => a.UnitCode.CompareTo(search.UnitCode)==0); if (!string.IsNullOrWhiteSpace(search.UserName)) query = query.Where(a => a.UserName.Contains(search.UserName)); if (!string.IsNullOrWhiteSpace(search.Id)) query = query.Where(a => a.Id.CompareTo(search.Id)==0); } return query; }
public List<UserModel> searchUserModel(UserSearchModel search) { int active = (int)Enums.RecordStatusCode.active; return BuildQuery(search, active).ToList(); }
public List<UserModel> searchUserModel(UserSearchModel search, int page, ref int pageSize, out int totalItemCount, out int pageCount) { int active = (int)Enums.RecordStatusCode.active; IQueryable<UserModel> query = BuildQuery(search, active); return Utils.buildPage(query, page, ref pageSize, out totalItemCount, out pageCount); }
public UserModel getById(string id, bool FInclude = false) { UserSearchModel search = new UserSearchModel() { Id = id }; int active = (int)Enums.RecordStatusCode.active; return BuildQuery(search, active, FInclude).FirstOrDefault(); }