BootstrapAdmin/Bootstrap.Admin/Controllers/Api/LogsController.cs

50 lines
1.3 KiB
C#
Raw Normal View History

2018-06-07 00:45:47 +08:00
using Bootstrap.Admin.Query;
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
namespace Bootstrap.Admin.Controllers.Api
{
/// <summary>
///
/// </summary>
[Route("api/[controller]")]
[ApiController]
public class LogsController : ControllerBase
2018-06-07 00:45:47 +08:00
{
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<Log> Get([FromQuery]QueryLogOption value)
2018-06-07 00:45:47 +08:00
{
return value.RetrieveData();
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
2018-10-30 13:07:29 +08:00
public Log Get(string id)
2018-06-07 00:45:47 +08:00
{
return LogHelper.Retrieves().FirstOrDefault(t => t.Id == id);
2018-06-07 00:45:47 +08:00
}
/// <summary>
///
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
2018-06-07 00:45:47 +08:00
[HttpPost]
2018-06-07 14:39:45 +08:00
public bool Post([FromBody]Log value)
2018-06-07 00:45:47 +08:00
{
2018-06-07 14:39:45 +08:00
value.ClientAgent = Request.Headers["User-Agent"];
value.ClientIp = HttpContext.Connection.RemoteIpAddress.ToString();
2018-06-07 00:45:47 +08:00
value.UserName = User.Identity.Name;
return LogHelper.Save(value);
2018-06-07 00:45:47 +08:00
}
}
}