示例#1
0
        public ActionResult Index(LogFilter filter)
        {
            // INIT
            DBEntities context = COREobject.i.Context;

            filter.Fill(context);

            int perPage = 20;
            int page    = Request.Form.AllKeys.Contains("page") ? Convert.ToInt32(Request.Form["page"]) - 1 : 0;

            page = page >= 0 ? page : 0;



            var allItems = context.LogItems.Where(
                i =>
                i.ParentLogItemId == null &&
                (filter.LevelId == -1 || i.LogLevel == filter.LevelId) &&
                (filter.UserName == "All" || i.UserName == filter.UserName) &&
                (filter.Server == "All" || i.Server == filter.Server) &&
                (filter.SourceId == -1 || i.Source == filter.SourceId) &&
                (filter.ApplicationName == "All" || i.Application == filter.ApplicationName) &&
                (filter.BlockName == "All" || i.BlockName == filter.BlockName) &&
                (filter.ActionName == "All" || i.ActionName == filter.ActionName) &&
                (i.Timestamp > filter.TimeSince && i.Timestamp < filter.TimeTo) &&
                (string.IsNullOrEmpty(filter.Message) || i.Message.ToLower().Contains(filter.Message.ToLower()))
                ).OrderByDescending(i => i.Timestamp).Take(100).Select(i =>
                                                                       new {
                Id          = i.Id,
                Timestamp   = i.Timestamp,
                LogLevel    = i.LogLevel,
                UserName    = i.UserName,
                Server      = i.Server,
                Source      = i.Source,
                Application = i.Application,
                BlockName   = i.BlockName,
                ActionName  = i.ActionName,
                Message     = i.Message
            }
                                                                       );


            ViewData["perPage"] = perPage;
            ViewData["page"]    = page + 1;
            ViewData["total"]   = allItems.Count();

            filter.ResultItems = allItems.Skip(page * perPage).Take(perPage).ToList().Select(i =>
                                                                                             new LogItem
            {
                Id          = i.Id,
                Timestamp   = i.Timestamp,
                LogLevel    = i.LogLevel,
                UserName    = i.UserName,
                Server      = i.Server,
                Source      = i.Source,
                Application = i.Application,
                BlockName   = i.BlockName,
                ActionName  = i.ActionName,
                Message     = i.Message
            }).ToList();

            return(View(filter));
        }