12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- 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<int> 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<List<ActionsModel>> 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<ActionsModel>(selectSql, new { KeyWord = "%" + keyWord + "%", StartTime = startTime, EndTime = endTime })).ToList();
- }
- }
- public async Task<int> 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; }
- }
- }
- }
- }
|