demo20230512/Areas/admin/Controllers/LogController.cs
2023-05-12 10:20:28 +08:00

45 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Weee.DAL;
using PagedList;
namespace Weee.Areas.Admin.Controllers
{
public class LogController : AdminControllerBase
{
public LogController(WeeeDataContext db)
: base(db)
{
}
// GET: Admin/Log
public ActionResult Index(int? page, string searchString = "")
{
//.ActionLogs.OrderByDescending(x=>x.ID).Skip(10*(page??0)).Take(10).ToList()
var query = db.ActionLogs.AsQueryable();
if (searchString != "")
query = query.Where(x => x.Action.Contains(searchString)||
x.Controller.Contains(searchString)||
x.ExecuteResult.Contains(searchString)||
x.IP.Contains(searchString)||
x.Name.Contains(searchString));
var itemlist = query.OrderByDescending(x => x.ID).ToPagedList(page??1,10);
ViewBag.OnePage = itemlist;
ViewBag.SearchString = searchString;
return View(itemlist);
}
public FileResult dnlg()
{
string fileName = $@"{DateTime.Today.ToString("yyyy-MM-dd")}.log";
byte[] fileBytes = System.IO.File.ReadAllBytes($@"C:\webFilesRoot\Logs\{fileName}");
FileResult ret = File(fileBytes, System.Net.Mime.MediaTypeNames.Application.Octet, fileName);
return ret;
}
}
}