BootstrapAdmin/Bootstrap.Admin/Models/QueryLogOption.cs

70 lines
2.4 KiB
C#
Raw Normal View History

using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System;
using System.Globalization;
using System.Linq;
namespace Bootstrap.Admin.Models
{
public class QueryLogOption : PaginationOption
{
/// <summary>
///
/// </summary>
public string OperateType { get; set; }
/// <summary>
///
/// </summary>
2016-11-29 12:59:37 +08:00
public DateTime OperateTimeStart { get; set; }
/// <summary>
///
/// </summary>
2016-11-29 12:59:37 +08:00
public DateTime OperateTimeEnd { get; set; }
/// <summary>
///
/// </summary>
/// <returns></returns>
public QueryData<Log> RetrieveData()
{
var data = LogHelper.RetrieveLogs();
if (!string.IsNullOrEmpty(OperateType))
{
data = data.Where(t => t.CRUD.ToString().Contains(OperateType));
}
2016-11-29 12:59:37 +08:00
if (OperateTimeStart > DateTime.MinValue)
{
2016-11-29 12:59:37 +08:00
data = data.Where(t => t.LogTime > OperateTimeStart);
}
2016-11-29 12:59:37 +08:00
if (OperateTimeEnd > DateTime.MinValue)
{
2016-11-29 12:59:37 +08:00
data = data.Where(t => t.LogTime < OperateTimeEnd.AddDays(1));
}
var ret = new QueryData<Log>();
ret.total = data.Count();
2016-11-29 12:59:37 +08:00
switch (Sort)
{
case "CRUD":
data = Order == "asc" ? data.OrderBy(t => t.CRUD) : data.OrderByDescending(t => t.CRUD);
break;
case "UserName":
data = Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName);
break;
case "LogTime":
data = Order == "asc" ? data.OrderBy(t => t.LogTime) : data.OrderByDescending(t => t.LogTime);
break;
case "ClientIp":
data = Order == "asc" ? data.OrderBy(t => t.ClientIp) : data.OrderByDescending(t => t.ClientIp);
break;
case "RequestUrl":
data = Order == "asc" ? data.OrderBy(t => t.RequestUrl) : data.OrderByDescending(t => t.RequestUrl);
break;
default:
break;
}
ret.rows = data.Skip(Offset).Take(Limit);
return ret;
}
}
}