You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.1 KiB
68 lines
2.1 KiB
|
|
using Dapper;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TaskManager.Controllers;
|
|
using TaskManager.Entity;
|
|
using TaskManager.EntityFramework;
|
|
|
|
namespace TaskManager.Controllers
|
|
{
|
|
public class LogController:ControllerBase
|
|
{
|
|
private readonly JobDbContext _dbContext;
|
|
public LogController(JobDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
public async Task<List<TaskLog>> GetAll()
|
|
{
|
|
var log = await _dbContext.TaskLogs.ToListAsync();
|
|
return log;
|
|
}
|
|
[HttpGet("AddError")]
|
|
public async Task<bool> AddError(string message,string taskname)
|
|
{
|
|
_dbContext.TaskLogs.Add(new TaskLog() { Info = message, Type = "错误",TaskName=taskname ,CreationTime=DateTime.Now});
|
|
var result =await _dbContext.SaveChangesAsync();
|
|
if (result > 0)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
[HttpGet("AddInfo")]
|
|
public async Task<bool> AddInfo(string message, string taskname)
|
|
{
|
|
_dbContext.TaskLogs.Add(new TaskLog() { Info = message, Type = "记录", TaskName = taskname, CreationTime = DateTime.Now });
|
|
var result = await _dbContext.SaveChangesAsync();
|
|
if (result > 0)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
}
|
|
//private readonly IServiceProvider _serviceProvider;
|
|
//public LogController(IServiceProvider serviceProvider)
|
|
//{
|
|
// _serviceProvider = serviceProvider;
|
|
//}
|
|
//public async Task<IEnumerable<Logs>> GetLogs()
|
|
//{
|
|
// var dbcontext= _serviceProvider.GetRequiredService<JobDbContext>();
|
|
// var connection=dbcontext.Database.GetDbConnection();
|
|
// connection.Query<Logs>("select top 10 * from logs");
|
|
//}
|
|
|
|
|
|
|
|
}
|
|
|