Example #1
0
        public async Task <AdminLogSearchResult> GetModelListAsync(string keyword, long?permissionTypeId, DateTime?startTime, DateTime?endTime, int pageIndex, int pageSize)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                AdminLogSearchResult result = new AdminLogSearchResult();
                var adminLogs = dbc.GetAll <AdminLogEntity>().AsNoTracking();
                if (!string.IsNullOrEmpty(keyword))
                {
                    adminLogs = adminLogs.Where(a => a.Admin.Mobile.Contains(keyword));
                }
                if (permissionTypeId != null)
                {
                    adminLogs = adminLogs.Where(a => a.PermissionType.Id == permissionTypeId);
                }
                if (startTime != null)
                {
                    adminLogs = adminLogs.Where(a => a.CreateTime >= startTime);
                }
                if (endTime != null)
                {
                    adminLogs = adminLogs.Where(a => SqlFunctions.DateDiff("day", endTime, a.CreateTime) <= 0);
                }
                result.PageCount = (int)Math.Ceiling((await adminLogs.LongCountAsync()) * 1.0f / pageSize);
                var adminLogsResult = await adminLogs.Include(a => a.Admin).Include(a => a.PermissionType).OrderByDescending(a => a.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();

                result.AdminLogs = adminLogsResult.Select(a => ToDTO(a)).ToArray();
                return(result);
            }
        }
Example #2
0
 public AdminLogSearchResult GetPage(DateTime?startTime, DateTime?endTime, string keyWord, int currentIndex, int pageSize)
 {
     using (MyDbContext dbc = new MyDbContext())
     {
         CommonService <AdminLogEntity> cs     = new CommonService <AdminLogEntity>(dbc);
         AdminLogSearchResult           result = new AdminLogSearchResult();
         var logs = cs.GetAll();
         if (startTime != null)
         {
             logs = logs.Where(l => l.CreateDateTime > startTime);
         }
         if (endTime != null)
         {
             logs = logs.Where(l => l.CreateDateTime < endTime);
         }
         if (!string.IsNullOrEmpty(keyWord))
         {
             logs = logs.Where(l => l.Message.Contains(keyWord));
         }
         result.TotalCount = logs.LongCount();
         result.AdminLogs  = logs.Include(l => l.AdminUser).OrderByDescending(l => l.CreateDateTime).Skip(currentIndex).Take(pageSize).ToList().
                             Select(l => new AdminLogDTO {
             AdminUserId = l.AdminUserId, AdminUserName = l.AdminUser.Name, AdminUserPhoneNum = l.AdminUser.Mobile, CreateDateTime = l.CreateDateTime, Id = l.Id, IpAddress = l.IpAddress, Message = l.Message
         }).ToArray();
         return(result);
     }
 }
Example #3
0
        public ActionResult Logs(DateTime?startTime, DateTime?endTime, string keyWord, int pageIndex)
        {
            AdminLogSearchResult result = logService.GetPage(startTime, endTime, keyWord, (pageIndex - 1) * 20, 20);
            AdminLogsViewModel   model  = new AdminLogsViewModel();

            model.Logs = result.AdminLogs;
            //分页
            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
            }));
        }
Example #4
0
        public async Task <AdminLogSearchResult> GetModelListAsync(string mobile, long?permissionTypeId, DateTime?startTime, DateTime?endTime, int pageIndex, int pageSize)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                AdminLogSearchResult result = new AdminLogSearchResult();
                var adminLogs = dbc.GetAll <AdminLogEntity>();
                if (!string.IsNullOrEmpty(mobile))
                {
                    adminLogs = adminLogs.Where(a => a.Admin.Mobile.Contains(mobile));
                }
                if (permissionTypeId != null)
                {
                    adminLogs = adminLogs.Where(a => a.PermissionType.Id == permissionTypeId);
                }
                if (startTime != null)
                {
                    adminLogs = adminLogs.Where(a => a.CreateTime >= startTime);
                }
                if (endTime != null)
                {
                    adminLogs = adminLogs.Where(a => a.CreateTime.Year <= endTime.Value.Year && a.CreateTime.Month <= endTime.Value.Month && a.CreateTime.Day <= endTime.Value.Day);
                }
                result.TotalCount = await adminLogs.LongCountAsync();

                var adminLogsResult = await adminLogs.OrderByDescending(a => a.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();

                result.AdminLogs = adminLogsResult.Select(a => ToDTO(a)).ToArray();
                return(result);
            }
        }
Example #5
0
        public async Task <AdminLogSearchResult> GetModelListAsync(string keyword, DateTime?startTime, DateTime?endTime, int pageIndex, int pageSize)
        {
            using (MyDbContext dbc = new MyDbContext())
            {
                AdminLogSearchResult result = new AdminLogSearchResult();
                var entities = dbc.GetAll <AdminLogEntity>().AsNoTracking();
                if (!string.IsNullOrEmpty(keyword))
                {
                    entities = entities.Where(a => a.AdminMobile.Contains(keyword));
                }
                if (startTime != null)
                {
                    entities = entities.Where(a => a.CreateTime >= startTime);
                }
                if (endTime != null)
                {
                    entities = entities.Where(a => a.CreateTime <= endTime);
                }
                result.PageCount = (int)Math.Ceiling((await entities.LongCountAsync()) * 1.0f / pageSize);
                var res = await entities.OrderByDescending(a => a.CreateTime).Skip((pageIndex - 1) * pageSize).Take(pageSize).ToListAsync();

                result.List = res.Select(a => ToDTO(a)).ToArray();
                return(result);
            }
        }
Example #6
0
        public ActionResult Logs()
        {
            AdminLogSearchResult result = logService.GetPage(null, null, null, 0, 20);
            AdminLogsViewModel   model  = new AdminLogsViewModel();

            model.Logs = result.AdminLogs;
            //分页
            Pagination pager = new Pagination();

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

            if (result.TotalCount <= 20)
            {
                model.Page = "";
            }
            else
            {
                model.Page = pager.GetPagerHtml();
            }
            return(View(model));
        }
Example #7
0
        public PartialViewResult LogList(string message, DateTime?startTime, DateTime?endTime, int pageIndex = 1)
        {
            LogListViewModel     model  = new LogListViewModel();
            AdminLogSearchResult result = adminLogService.GetPageList(message, startTime, endTime, null, pageIndex, pageSize);

            model.AdminLogs = result.AdminLogs;

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

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

            if (result.TotalCount <= pageSize)
            {
                model.Page = "";
            }
            else
            {
                model.Page = pager.GetPagerHtml();
            }
            return(PartialView("LogListPaging", model));
        }