using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Threading.Tasks; using Dapper; using GCAS.Model; namespace GCAS.Code { public class ActionsRepository { public async Task Insert(ActionsModel entity) { string insertSql = "INSERT INTO actions (operator,time,info,rolename)VALUES(@Operator,@Time,@Info,@RoleName)"; using (IDbConnection conn = DataBaseConfig.GetSqlConnection()) { return await conn.ExecuteAsync(insertSql, entity); } } public async Task> GetList(string keyWord, DateTime? startTime, DateTime? endTime) { string selectSql = "SELECT * FROM actions where 1=1 "; if (!string.IsNullOrEmpty(keyWord)) { selectSql += " and (actions.info like @KeyWord or operator like @KeyWord ) "; } if (startTime != null && endTime != null) { selectSql += " and time>@StartTime and time<@EndTime "; } selectSql += " order by id desc"; using (IDbConnection conn = DataBaseConfig.GetSqlConnection()) { return (await conn.QueryAsync(selectSql, new { KeyWord = "%" + keyWord + "%", StartTime = startTime, EndTime = endTime })).ToList(); } } public async Task Recover() { string sql = @"TRUNCATE TABLE actions;TRUNCATE TABLE record;"; using (IDbConnection conn = DataBaseConfig.GetSqlConnection()) { try { await Task.Run(() => conn.Execute(sql)); return 1; } catch { return 0; } } } } }