diff --git a/CC.Yi.API/Controllers/StudentController.cs b/CC.Yi.API/Controllers/StudentController.cs new file mode 100644 index 00000000..5411f596 --- /dev/null +++ b/CC.Yi.API/Controllers/StudentController.cs @@ -0,0 +1,30 @@ +using CC.Yi.IBLL; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace CC.Yi.API.Controllers +{ + [ApiController] + [Route("[controller]/[action]")] + public class StudentController : ControllerBase + { + private readonly ILogger _logger; + private IstudentBll _studentBll; + public StudentController(ILogger logger, IstudentBll studentBll) + { + _studentBll = studentBll; + _logger = logger; + } + + [HttpGet] + public IActionResult Test() + { + var data = _studentBll.GetAllEntities().ToList(); + return Content(Common.JsonFactory.JsonToString(data)); + } + } +} diff --git a/CC.Yi.API/Controllers/WeatherForecastController.cs b/CC.Yi.API/Controllers/WeatherForecastController.cs deleted file mode 100644 index 6ba2ecff..00000000 --- a/CC.Yi.API/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,47 +0,0 @@ -using CC.Yi.IBLL; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace CC.Yi.API.Controllers -{ - [ApiController] - [Route("[controller]/[action]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - private IstudentBll _studentBll; - public WeatherForecastController(ILogger logger, IstudentBll studentBll) - { - _studentBll = studentBll; - _logger = logger; - } - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } - [HttpGet] - public IActionResult Test() - { - var data= _studentBll.GetEntities(n => n.id >= 0).ToList(); - return Content(Common.JsonFactory.JsonToString(data)); - } - } -} diff --git a/CC.Yi.API/WeatherForecast.cs b/CC.Yi.API/WeatherForecast.cs deleted file mode 100644 index 9a3c14cf..00000000 --- a/CC.Yi.API/WeatherForecast.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace CC.Yi.API -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } - } -} diff --git a/CC.Yi.BLL/BaseBll.cs b/CC.Yi.BLL/BaseBll.cs index 6ebbd6f4..5e7a1a4f 100644 --- a/CC.Yi.BLL/BaseBll.cs +++ b/CC.Yi.BLL/BaseBll.cs @@ -15,11 +15,10 @@ namespace CC.Yi.BLL { CurrentDal = cd; } - //public abstract void SetCurrentDal(); - //public BaseBll()//基类的构造方法 - //{ - // SetCurrentDal();//该方法由子类去实现 - //} + public IQueryable GetAllEntities() + { + return CurrentDal.GetAllEntities(); + } public IQueryable GetEntities(Expression> whereLambda) { diff --git a/CC.Yi.DAL/BaseDal.cs b/CC.Yi.DAL/BaseDal.cs index fc85f109..70e00edd 100644 --- a/CC.Yi.DAL/BaseDal.cs +++ b/CC.Yi.DAL/BaseDal.cs @@ -19,7 +19,13 @@ namespace CC.Yi.DAL return Db.Set().Where(whereLambda).AsQueryable(); } - public int GetCount(Expression> whereLambda) //统计数量 + public IQueryable GetAllEntities() + { + return Db.Set().AsQueryable(); + } + + + public int GetCount(Expression> whereLambda) { return Db.Set().Where(whereLambda).Count(); } diff --git a/CC.Yi.IBLL/IBaseBll.cs b/CC.Yi.IBLL/IBaseBll.cs index adc03e26..dae45507 100644 --- a/CC.Yi.IBLL/IBaseBll.cs +++ b/CC.Yi.IBLL/IBaseBll.cs @@ -7,23 +7,53 @@ namespace CC.Yi.IBLL { public interface IBaseBll where T : class, new() { + #region + //得到全部实体 + #endregion + IQueryable GetAllEntities(); + #region + //通过表达式得到实体 + #endregion IQueryable GetEntities(Expression> whereLambda); - int GetCount(Expression> whereLambda);//统计数量 + #region + //通过表达式得到实体,分页版本 + #endregion + IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc); + + #region + //通过表达式统计数量 + #endregion + int GetCount(Expression> whereLambda); #region - //分组 + //通过表达式分组 #endregion IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda); - IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc); - + #region + //添加实体 + #endregion T Add(T entity); + #region + //更新实体 + #endregion bool Update(T entity); + #region + //删除实体 + #endregion bool Delete(T entity); + + #region + //通过id删除实体 + #endregion bool Delete(int id); + + #region + //通过id列表删除多个实体 + #endregion int DeleteList(List ids); } } diff --git a/CC.Yi.IDAL/IBaseDal.cs b/CC.Yi.IDAL/IBaseDal.cs index 09719777..a7b2d0cd 100644 --- a/CC.Yi.IDAL/IBaseDal.cs +++ b/CC.Yi.IDAL/IBaseDal.cs @@ -6,44 +6,48 @@ namespace CC.Yi.IDAL { public interface IBaseDal where T : class, new() { + #region + //得到全部实体 + #endregion + IQueryable GetAllEntities(); + #region //通过表达式得到实体 #endregion IQueryable GetEntities(Expression> whereLambda); #region - //统计数量 - #endregion - int GetCount(Expression> whereLambda);//统计数量 - - #region - //分组 - #endregion - IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda); - - - #region - //通过得到实体,分页版本 + //通过表达式得到实体,分页版本 #endregion IQueryable GetPageEntities(int pageSize, int pageIndex, out int total, Expression> whereLambda, Expression> orderByLambda, bool isAsc); #region - //添加实体 + //通过表达式统计数量 + #endregion + int GetCount(Expression> whereLambda); + + #region + //通过表达式分组 + #endregion + IQueryable> GetGroup(Expression> whereLambda, Expression> groupByLambda); + + #region + //添加单个实体 #endregion T Add(T entity); #region - //更新实体 + //更新单个实体 #endregion bool Update(T entity); #region - //删除实体 + //删除单个实体 #endregion bool Delete(T entity); #region - //通过id进行删除实体 + //通过id删除实体 #endregion bool Detete(int id); }