using DbCommon.BusinessCore.DbCore; using DbCommon.Enties.DbModels; using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DbCommon.BusinessCore.BaseCore { public class CallTaskManager : DbContext { public void Init() { //If no exist create datebase //Db.DbMaintenance.CreateDatabase(); var dt = Db.Ado.GetDataTable("SELECT * FROM sysobjects WHERE NAME = 'CallTask'"); if (dt.Rows.Count == 0) { //Create tables Db.CodeFirst.InitTables(typeof(CallTask)); } } public bool DeleteOldData(int day = 1) { return CurrentDb.Delete(d => d.CallTime < DateTime.Now.AddDays(day * -1)); } public List Query(EnumTaskStatus status = EnumTaskStatus.Called) { return Db.Queryable() .Where(d => d.TaskStatus == status) .OrderBy(d => d.CallTime, SqlSugar.OrderByType.Asc) .ToList(); } public List Query(System.Linq.Expressions.Expression> expression) { return Db.Queryable() .Where(expression) .OrderBy(d => d.CallTime, SqlSugar.OrderByType.Asc) .ToList(); } public DataTable QueryDataTable() { return Db.Queryable() .Where(d => d.TaskStatus < EnumTaskStatus.Called) .OrderBy(d => d.CallTime, SqlSugar.OrderByType.Desc) .ToDataTable(); } } }