This commit is contained in:
454313500@qq.com
2021-03-20 15:02:23 +08:00
parent 59a42ae48f
commit 2e5b991db0
7 changed files with 95 additions and 88 deletions

View File

@@ -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<StudentController> _logger;
private IstudentBll _studentBll;
public StudentController(ILogger<StudentController> logger, IstudentBll studentBll)
{
_studentBll = studentBll;
_logger = logger;
}
[HttpGet]
public IActionResult Test()
{
var data = _studentBll.GetAllEntities().ToList();
return Content(Common.JsonFactory.JsonToString(data));
}
}
}

View File

@@ -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<WeatherForecastController> _logger;
private IstudentBll _studentBll;
public WeatherForecastController(ILogger<WeatherForecastController> logger, IstudentBll studentBll)
{
_studentBll = studentBll;
_logger = logger;
}
[HttpGet]
public IEnumerable<WeatherForecast> 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));
}
}
}

View File

@@ -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; }
}
}

View File

@@ -15,11 +15,10 @@ namespace CC.Yi.BLL
{ {
CurrentDal = cd; CurrentDal = cd;
} }
//public abstract void SetCurrentDal(); public IQueryable<T> GetAllEntities()
//public BaseBll()//基类的构造方法 {
//{ return CurrentDal.GetAllEntities();
// SetCurrentDal();//该方法由子类去实现 }
//}
public IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda) public IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda)
{ {

View File

@@ -19,7 +19,13 @@ namespace CC.Yi.DAL
return Db.Set<T>().Where(whereLambda).AsQueryable(); return Db.Set<T>().Where(whereLambda).AsQueryable();
} }
public int GetCount(Expression<Func<T, bool>> whereLambda) //统计数量 public IQueryable<T> GetAllEntities()
{
return Db.Set<T>().AsQueryable();
}
public int GetCount(Expression<Func<T, bool>> whereLambda)
{ {
return Db.Set<T>().Where(whereLambda).Count(); return Db.Set<T>().Where(whereLambda).Count();
} }

View File

@@ -7,23 +7,53 @@ namespace CC.Yi.IBLL
{ {
public interface IBaseBll<T> where T : class, new() public interface IBaseBll<T> where T : class, new()
{ {
#region
//得到全部实体
#endregion
IQueryable<T> GetAllEntities();
#region
//通过表达式得到实体
#endregion
IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda); IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda);
int GetCount(Expression<Func<T, bool>> whereLambda);//统计数量 #region
//通过表达式得到实体,分页版本
#endregion
IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc);
#region
//通过表达式统计数量
#endregion
int GetCount(Expression<Func<T, bool>> whereLambda);
#region #region
//分组 //通过表达式分组
#endregion #endregion
IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda); IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda);
IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc); #region
//添加实体
#endregion
T Add(T entity); T Add(T entity);
#region
//更新实体
#endregion
bool Update(T entity); bool Update(T entity);
#region
//删除实体
#endregion
bool Delete(T entity); bool Delete(T entity);
#region
//通过id删除实体
#endregion
bool Delete(int id); bool Delete(int id);
#region
//通过id列表删除多个实体
#endregion
int DeleteList(List<int> ids); int DeleteList(List<int> ids);
} }
} }

View File

@@ -6,44 +6,48 @@ namespace CC.Yi.IDAL
{ {
public interface IBaseDal<T> where T : class, new() public interface IBaseDal<T> where T : class, new()
{ {
#region
//得到全部实体
#endregion
IQueryable<T> GetAllEntities();
#region #region
//通过表达式得到实体 //通过表达式得到实体
#endregion #endregion
IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda); IQueryable<T> GetEntities(Expression<Func<T, bool>> whereLambda);
#region #region
//统计数量 //通过表达式得到实体,分页版本
#endregion
int GetCount(Expression<Func<T, bool>> whereLambda);//统计数量
#region
//分组
#endregion
IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda);
#region
//通过得到实体,分页版本
#endregion #endregion
IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc); IQueryable<T> GetPageEntities<S>(int pageSize, int pageIndex, out int total, Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> orderByLambda, bool isAsc);
#region #region
//添加实体 //通过表达式统计数量
#endregion
int GetCount(Expression<Func<T, bool>> whereLambda);
#region
//通过表达式分组
#endregion
IQueryable<IGrouping<S, T>> GetGroup<S>(Expression<Func<T, bool>> whereLambda, Expression<Func<T, S>> groupByLambda);
#region
//添加单个实体
#endregion #endregion
T Add(T entity); T Add(T entity);
#region #region
//更新实体 //更新单个实体
#endregion #endregion
bool Update(T entity); bool Update(T entity);
#region #region
//删除实体 //删除单个实体
#endregion #endregion
bool Delete(T entity); bool Delete(T entity);
#region #region
//通过id进行删除实体 //通过id删除实体
#endregion #endregion
bool Detete(int id); bool Detete(int id);
} }