2019-03-16 20:24:33 +08:00
|
|
|
|
using Longbow.Data;
|
2019-04-08 16:01:40 +08:00
|
|
|
|
using Longbow.Web;
|
2019-03-16 20:24:33 +08:00
|
|
|
|
using Longbow.Web.Mvc;
|
2019-04-08 16:01:40 +08:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2019-03-16 20:24:33 +08:00
|
|
|
|
using PetaPoco;
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace Bootstrap.DataAccess
|
|
|
|
|
{
|
|
|
|
|
public static class TraceHelper
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存访问历史记录
|
|
|
|
|
/// </summary>
|
2019-04-08 16:01:40 +08:00
|
|
|
|
/// <param name="context"></param>
|
|
|
|
|
/// <param name="v"></param>
|
|
|
|
|
public static void Save(HttpContext context, OnlineUser v)
|
|
|
|
|
{
|
|
|
|
|
if (context.User.Identity.IsAuthenticated)
|
|
|
|
|
{
|
|
|
|
|
var user = UserHelper.RetrieveUserByUserName(context.User.Identity.Name);
|
|
|
|
|
v.UserName = user.UserName;
|
|
|
|
|
v.DisplayName = user.DisplayName;
|
|
|
|
|
DbContextManager.Create<Trace>().Save(new Trace
|
|
|
|
|
{
|
|
|
|
|
Ip = v.Ip,
|
|
|
|
|
RequestUrl = v.RequestUrl,
|
|
|
|
|
LogTime = v.LastAccessTime,
|
|
|
|
|
City = v.Location,
|
|
|
|
|
Browser = v.Browser,
|
|
|
|
|
OS = v.OS,
|
2019-04-27 20:39:24 +08:00
|
|
|
|
UserName = v.UserName,
|
|
|
|
|
UserAgent = v.UserAgent
|
2019-04-08 16:01:40 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-03-16 20:24:33 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获得指定IP历史访问记录
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="po"></param>
|
|
|
|
|
/// <param name="startTime"></param>
|
|
|
|
|
/// <param name="endTime"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static Page<Trace> Retrieves(PaginationOption po, DateTime? startTime, DateTime? endTime) => DbContextManager.Create<Trace>().Retrieves(po, startTime, endTime);
|
|
|
|
|
}
|
|
|
|
|
}
|