BootstrapAdmin/Bootstrap.Admin/Query/QueryExceptionOption.cs

60 lines
2.0 KiB
C#
Raw Normal View History

2018-06-07 00:45:47 +08:00
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System;
using System.Linq;
namespace Bootstrap.Admin.Query
{
/// <summary>
///
/// </summary>
2018-06-07 00:45:47 +08:00
public class QueryExceptionOption : PaginationOption
{
/// <summary>
///
/// </summary>
public DateTime StartTime { get; set; }
/// <summary>
///
/// </summary>
public DateTime EndTime { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
2018-10-30 13:07:29 +08:00
public QueryData<object> RetrieveData()
2018-06-07 00:45:47 +08:00
{
2018-10-19 23:09:52 +08:00
var data = ExceptionsHelper.RetrieveExceptions();
2018-06-07 00:45:47 +08:00
if (StartTime > DateTime.MinValue)
{
data = data.Where(t => t.LogTime > StartTime);
}
if (EndTime > DateTime.MinValue)
{
data = data.Where(t => t.LogTime < EndTime.AddDays(1));
}
2018-10-30 13:07:29 +08:00
var ret = new QueryData<object>();
2018-06-07 00:45:47 +08:00
ret.total = data.Count();
switch (Sort)
{
case "ErrorPage":
data = Order == "asc" ? data.OrderBy(t => t.ErrorPage) : data.OrderByDescending(t => t.ErrorPage);
break;
case "UserID":
data = Order == "asc" ? data.OrderBy(t => t.UserId) : data.OrderByDescending(t => t.UserId);
break;
case "UserIp":
data = Order == "asc" ? data.OrderBy(t => t.UserIp) : data.OrderByDescending(t => t.UserIp);
break;
case "LogTime":
data = Order == "asc" ? data.OrderBy(t => t.LogTime) : data.OrderByDescending(t => t.LogTime);
break;
default:
break;
}
2018-10-30 13:07:29 +08:00
ret.rows = data.Skip(Offset).Take(Limit).Select(ex => new { ex.UserId, ex.UserIp, ex.LogTime, ex.Message, ex.ErrorPage, ex.ExceptionType });
2018-06-07 00:45:47 +08:00
return ret;
}
}
}