泛型-增删改查

public IQueryable<T> GetEntitys(Expression<Func<T,bool>> lambdaWhere)
{
	//context.UserInfoes.Where(lambdaWhere);
	return context.Set<T>().Where(lambdaWhere);
}
public int Add(T entity)
{
	context.Set<T>().Add(entity);
	return context.SaveChanges();
}
public int Delete(int id)
{
	//通过ID查询这条实体
	T entity = context.Set<T>().Find(id);
	context.Set<T>().Remove(entity);
	return context.SaveChanges();
}
public int Update(T entity)
{
	//设置当前实体的状态为修改
	context.Entry(entity).State = System.Data.Entity.EntityState.Modified;
	return context.SaveChanges();
}
//校验用户是否登录
public class BaseController:Controller
{
	public bool IsCheckLogin = true;
	public static UserInfo BaseUserInfo{get;set;}
	protected override void OnActionExecuting(ActionExecutingContext filterContext)
	{
		base.OnActionExecuting(filterContext);
		if(IsCheckLogin)
		{
			if(BaseUserInfo == null)
			{
				filterContext.HttpContext.Response.Redirect("/Login/Index");
			}
		}
	}
}

  

posted @ 2021-12-02 10:55  江南-烟雨  阅读(63)  评论(0编辑  收藏  举报