Exemplo n.º 1
0
 public AdminUserSearchResult GetPage(DateTime?startTime, DateTime?endTime, string keyWord, int currentIndex, int pageSize)
 {
     using (MyDbContext dbc = new MyDbContext())
     {
         CommonService <AdminUserEntity> cs     = new CommonService <AdminUserEntity>(dbc);
         AdminUserSearchResult           result = new AdminUserSearchResult();
         var adminUsers = cs.GetAll();
         if (startTime != null)
         {
             adminUsers = adminUsers.Where(a => a.CreateDateTime > startTime);
         }
         if (endTime != null)
         {
             adminUsers = adminUsers.Where(a => a.CreateDateTime < endTime);
         }
         if (!string.IsNullOrEmpty(keyWord))
         {
             adminUsers = adminUsers.Where(a => a.Name.Contains(keyWord));
         }
         result.TotalCount = adminUsers.LongCount();
         result.AdminUsers = adminUsers.Include(a => a.Roles).OrderByDescending(a => a.CreateDateTime).Skip(currentIndex).Take(pageSize).ToList().
                             Select(a => new AdminUserDTO {
             CreateDateTime = a.CreateDateTime, Email = a.Email, Gender = a.Gender, Id = a.Id, LastLoginErrorDateTime = a.LastLoginErrorTime, LoginErrorTimes = a.LoginErrorTimes, Mobile = a.Mobile, Name = a.Name, Roles = a.Roles.Where(r => r.IsDeleted == false).ToList().Select(r => ToRoleDTO(r)).ToArray()
         }).ToArray();
         return(result);
     }
 }
Exemplo n.º 2
0
        public ActionResult list(DateTime?startTime, DateTime?endTime, string keyWord, int pageIndex)
        {
            AdminUserSearchResult result = adminService.GetPage(startTime, endTime, keyWord, (pageIndex - 1) * 20, 20);
            AdminUserViewModel    model  = new AdminUserViewModel();

            string[] roleCities = new[] { "南宁市", "柳州市", "桂林市", "梧州市", "北海市", "防城港市", "钦州市", "玉林市", "贵港市", "百色市", "河池市", "贺州市", "来宾市", "崇左市", "厅机关处室、直属单位" };

            List <AdminUserListDTO> AdminUsers = new List <AdminUserListDTO>();

            foreach (var list in result.AdminUsers)
            {
                AdminUserListDTO dto = new AdminUserListDTO();
                dto.CreateDateTime         = list.CreateDateTime;
                dto.Email                  = list.Email;
                dto.Gender                 = list.Gender;
                dto.Id                     = list.Id;
                dto.LastLoginErrorDateTime = list.LastLoginErrorDateTime;
                dto.Mobile                 = list.Mobile;
                dto.Name                   = list.Name;
                if (roleCities.Contains(list.Roles.First().Name.Split('-')[0]))
                {
                    dto.RoleName = "市级管理员";
                }
                else
                {
                    dto.RoleName = list.Roles.First().Name.Split('-')[0];
                }
                if (adminService.GetById(list.LoginErrorTimes) == null)
                {
                    dto.Creator = "admin";
                }
                else
                {
                    dto.Creator = adminService.GetById(list.LoginErrorTimes).Name;
                }
                AdminUsers.Add(dto);
            }
            model.AdminUsers = AdminUsers;

            //分页
            Pagination pager = new Pagination();

            pager.PageIndex  = pageIndex;
            pager.PageSize   = 20;
            pager.TotalCount = result.TotalCount;

            if (result.TotalCount <= 20)
            {
                model.Page = "";
            }
            else
            {
                model.Page = pager.GetPagerHtml();
            }
            return(Json(new AjaxResult {
                Status = "1", Data = model
            }));
        }