using Bootstrap.Admin.Query; using Bootstrap.DataAccess; using Longbow.Web; using Longbow.Web.Mvc; using Microsoft.AspNetCore.Mvc; using System.Net; namespace Bootstrap.Admin.Controllers.Api { /// /// /// [Route("api/[controller]")] [ApiController] public class LogsController : ControllerBase { /// /// /// /// /// [HttpGet] public QueryData Get([FromQuery]QueryLogOption value) { return value.RetrieveData(); } /// /// /// /// /// /// [HttpPost] public bool Post([FromServices]IOnlineUsers onlineUserSvr, [FromBody]Log value) { var agent = new UserAgent(Request.Headers["User-Agent"]); value.Ip = (HttpContext.Connection.RemoteIpAddress ?? IPAddress.IPv6Loopback).ToString(); value.Browser = $"{agent.Browser.Name} {agent.Browser.Version}"; value.OS = $"{agent.OS.Name} {agent.OS.Version}"; value.City = onlineUserSvr.RetrieveLocaleByIp(value.Ip); value.UserName = User.Identity.Name; return LogHelper.Save(value); } } }