using CC.Yi.IBLL; using CC.Yi.IDAL; using CC.Yi.Model; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; namespace CC.Yi.BLL { public class BaseBll : IBaseBll where T : class, new() { public IBaseDal CurrentDal; public DbContext Db; public BaseBll(IBaseDal cd, DataContext _Db) { CurrentDal = cd; Db = _Db; } public async Task GetEntityById(int id) { return await CurrentDal.GetEntityById(id); } public IQueryable GetAllEntities() { return CurrentDal.GetAllEntities(); } public IQueryable GetEntities(Expression> whereLambda) { return CurrentDal.GetEntities(whereLambda); } public int GetCount(Expression> whereLambda) //统计数量 { return CurrentDal.GetCount(whereLambda); } public IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda) //分组 { return CurrentDal.GetGroup(whereLambda, groupByLambda); } public IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc) { return CurrentDal.GetPageEntities(pageSize, pageIndex, out total, whereLambda, orderByLambda, isAsc); } public T Add(T entity) { T entityData= CurrentDal.Add(entity); Db.SaveChanges(); return entityData; } public bool Add(IEnumerable entities) { CurrentDal.AddRange(entities); return Db.SaveChanges() > 0; } public bool Update(T entity) { CurrentDal.Update(entity); return Db.SaveChanges() > 0; } public bool Update(T entity, params string[] propertyNames) { CurrentDal.Update(entity,propertyNames); return Db.SaveChanges() > 0; } public bool Delete(T entity) { CurrentDal.Delete(entity); return Db.SaveChanges() > 0; } public bool Delete(int id) { CurrentDal.Detete(id); return Db.SaveChanges() > 0; } public bool Delete(IEnumerable ids) { foreach (var id in ids) { CurrentDal.Detete(id); } return Db.SaveChanges()>0; } public bool Delete(Expression> where) { IQueryable entities = CurrentDal.GetEntities(where); if (entities != null) { CurrentDal.DeteteRange(entities); return Db.SaveChanges()>0; } return false; } } }