예제 #1
0
        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));
        }
예제 #2
0
 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;
 }
예제 #3
0
 public List<UserModel> searchUserModel(UserSearchModel search)
 {
     int active = (int)Enums.RecordStatusCode.active;
     return BuildQuery(search, active).ToList();
 }
예제 #4
0
 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);
 }
예제 #5
0
 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();
 }