mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 12:28:15 +08:00
新增文档分类列表树
This commit is contained in:
80
Examples/website/FreeSql.Site.DAL/BaseDAL.cs
Normal file
80
Examples/website/FreeSql.Site.DAL/BaseDAL.cs
Normal file
@ -0,0 +1,80 @@
|
||||
//using FreeSql.Site.Entity;
|
||||
using FreeSql.Site.Entity;
|
||||
using FreeSql.Site.Entity.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Text;
|
||||
|
||||
namespace FreeSql.Site.DAL
|
||||
{
|
||||
public class BaseDAL<T> where T : BaseEntity
|
||||
{
|
||||
/// <summary>
|
||||
/// 新增方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public virtual long Insert(T model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Insert<T>(model).ExecuteIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Update(T model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Update<T>(model.ID).ExecuteUpdated().Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除方法
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public virtual bool Delete(long id)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Delete<T>(id).ExecuteDeleted().Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条数据
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public virtual T GetByOne(Expression<Func<T, bool>> where)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Select<T>()
|
||||
.Where(where).ToOne();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <returns></returns>
|
||||
public virtual (List<T> list, long count) Query(Expression<Func<T, bool>> where,
|
||||
Expression<Func<T, T>> orderby = null, PageInfo pageInfo = null)
|
||||
{
|
||||
//设置查询条件
|
||||
var list = DataBaseType.MySql.DB().Select<T>()
|
||||
.Where(where);
|
||||
|
||||
BaseEntity baseEntity = new BaseEntity();
|
||||
//设置排序
|
||||
if (orderby != null) list = list.OrderBy(nameof(baseEntity.CreateDt) + " desc ");
|
||||
|
||||
var count = list.Count();
|
||||
//设置分页操作
|
||||
if (pageInfo != null && pageInfo.IsPaging)
|
||||
list.Skip(pageInfo.PageIndex * pageInfo.PageSize).Limit(pageInfo.PageSize);
|
||||
|
||||
//执行查询
|
||||
return (list.ToList(), count);
|
||||
}
|
||||
}
|
||||
}
|
@ -7,62 +7,8 @@ using System.Text;
|
||||
|
||||
namespace FreeSql.Site.DAL
|
||||
{
|
||||
public class DocumentCommentDAL
|
||||
public class DocumentCommentDAL : BaseDAL<DocumentComment>
|
||||
{
|
||||
/// <summary>
|
||||
/// 新增方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public long Insert(DocumentComment model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Insert<DocumentComment>(model).ExecuteIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(DocumentComment model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Update<DocumentComment>(model.ID).ExecuteUpdated().Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除方法
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(long id)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Delete<DocumentComment>(id).ExecuteDeleted().Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条数据
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public DocumentComment GetByOne(Expression<Func<DocumentComment, bool>> where)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Select<DocumentComment>()
|
||||
.Where(where).ToOne();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <returns></returns>
|
||||
public List<DocumentComment> Query(Expression<Func<DocumentComment, bool>> where,
|
||||
Expression<Func<DocumentComment, DocumentComment>> orderby = null)
|
||||
{
|
||||
var list = DataBaseType.MySql.DB().Select<DocumentComment>()
|
||||
.Where(where);
|
||||
if (orderby != null) list = list.OrderBy(b => b.CreateDt);
|
||||
return list.ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,85 +6,85 @@ using System.Linq.Expressions;
|
||||
|
||||
namespace FreeSql.Site.DAL
|
||||
{
|
||||
public class DocumentContentDAL
|
||||
public class DocumentContentDAL : BaseDAL<DocumentContent>
|
||||
{
|
||||
/// <summary>
|
||||
/// 新增
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public long Insert(DocumentContent model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Insert<DocumentContent>(model).ExecuteIdentity();
|
||||
}
|
||||
///// <summary>
|
||||
///// 新增
|
||||
///// </summary>
|
||||
///// <param name="model"></param>
|
||||
///// <returns></returns>
|
||||
//public long Insert(DocumentContent model)
|
||||
//{
|
||||
// return DataBaseType.MySql.DB().Insert<DocumentContent>(model).ExecuteIdentity();
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 修改
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(DocumentContent model)
|
||||
{
|
||||
var runsql = DataBaseType.MySql.DB().Update<DocumentContent>().SetSource(model);
|
||||
return runsql.ExecuteAffrows() > 0;
|
||||
}
|
||||
///// <summary>
|
||||
///// 修改
|
||||
///// </summary>
|
||||
///// <param name="model"></param>
|
||||
///// <returns></returns>
|
||||
//public bool Update(DocumentContent model)
|
||||
//{
|
||||
// var runsql = DataBaseType.MySql.DB().Update<DocumentContent>().SetSource(model);
|
||||
// return runsql.ExecuteAffrows() > 0;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 删除
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(long id)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Delete<DocumentContent>(id).ExecuteDeleted().Count > 0;
|
||||
}
|
||||
///// <summary>
|
||||
///// 删除
|
||||
///// </summary>
|
||||
///// <param name="id"></param>
|
||||
///// <returns></returns>
|
||||
//public bool Delete(long id)
|
||||
//{
|
||||
// return DataBaseType.MySql.DB().Delete<DocumentContent>(id).ExecuteDeleted().Count > 0;
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条数据
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public DocumentContent GetByOne(Expression<Func<DocumentContent, bool>> where)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Select<DocumentContent>()
|
||||
.Where(where).ToOne();
|
||||
}
|
||||
///// <summary>
|
||||
///// 获取一条数据
|
||||
///// </summary>
|
||||
///// <param name="where"></param>
|
||||
///// <returns></returns>
|
||||
//public DocumentContent GetByOne(Expression<Func<DocumentContent, bool>> where)
|
||||
//{
|
||||
// return DataBaseType.MySql.DB().Select<DocumentContent>()
|
||||
// .Where(where).ToOne();
|
||||
//}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条数据
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public long Count(Expression<Func<DocumentContent, bool>> where)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Select<DocumentContent>()
|
||||
.Where(where).Count();
|
||||
}
|
||||
///// <summary>
|
||||
///// 获取一条数据
|
||||
///// </summary>
|
||||
///// <param name="where"></param>
|
||||
///// <returns></returns>
|
||||
//public long Count(Expression<Func<DocumentContent, bool>> where)
|
||||
//{
|
||||
// return DataBaseType.MySql.DB().Select<DocumentContent>()
|
||||
// .Where(where).Count();
|
||||
//}
|
||||
|
||||
/// <summary>
|
||||
/// 查询功能
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <returns></returns>
|
||||
public (List<DocumentContent> list, long count) Query(Expression<Func<DocumentContent, bool>> where,
|
||||
Expression<Func<DocumentContent, DocumentContent>> orderby = null, PageInfo pageInfo = null)
|
||||
{
|
||||
//设置查询条件
|
||||
var list = DataBaseType.MySql.DB().Select<DocumentContent>()
|
||||
.Where(where);
|
||||
///// <summary>
|
||||
///// 查询功能
|
||||
///// </summary>
|
||||
///// <param name="where"></param>
|
||||
///// <param name="orderby"></param>
|
||||
///// <returns></returns>
|
||||
//public (List<DocumentContent> list, long count) Query(Expression<Func<DocumentContent, bool>> where,
|
||||
// Expression<Func<DocumentContent, DocumentContent>> orderby = null, PageInfo pageInfo = null)
|
||||
//{
|
||||
// //设置查询条件
|
||||
// var list = DataBaseType.MySql.DB().Select<DocumentContent>()
|
||||
// .Where(where);
|
||||
|
||||
//设置排序
|
||||
if (orderby != null) list = list.OrderBy(b => b.CreateDt);
|
||||
// //设置排序
|
||||
// if (orderby != null) list = list.OrderBy(b => b.CreateDt);
|
||||
|
||||
var count = list.Count();
|
||||
//设置分页操作
|
||||
if (pageInfo != null && pageInfo.IsPaging)
|
||||
list.Skip(pageInfo.PageIndex * pageInfo.PageSize).Limit(pageInfo.PageSize);
|
||||
// var count = list.Count();
|
||||
// //设置分页操作
|
||||
// if (pageInfo != null && pageInfo.IsPaging)
|
||||
// list.Skip(pageInfo.PageIndex * pageInfo.PageSize).Limit(pageInfo.PageSize);
|
||||
|
||||
//执行查询
|
||||
return (list.ToList(), count);
|
||||
}
|
||||
// //执行查询
|
||||
// return (list.ToList(), count);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
//using FreeSql.Site.Entity;
|
||||
using FreeSql.Site.Entity;
|
||||
using FreeSql.Site.Entity.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
@ -7,62 +8,8 @@ using System.Text;
|
||||
|
||||
namespace FreeSql.Site.DAL
|
||||
{
|
||||
public class DocumentTypeDAL
|
||||
public class DocumentTypeDAL : BaseDAL<DocumentType>
|
||||
{
|
||||
/// <summary>
|
||||
/// 新增方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public long Insert(DocumentType model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Insert<DocumentType>(model).ExecuteIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(DocumentType model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Update<DocumentType>(model.ID).ExecuteUpdated().Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除方法
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(long id)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Delete<DocumentType>(id).ExecuteDeleted().Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条数据
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public DocumentType GetByOne(Expression<Func<DocumentType, bool>> where)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Select<DocumentType>()
|
||||
.Where(where).ToOne();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <returns></returns>
|
||||
public List<DocumentType> Query(Expression<Func<DocumentType, bool>> where,
|
||||
Expression<Func<DocumentType, DocumentType>> orderby = null)
|
||||
{
|
||||
var list = DataBaseType.MySql.DB().Select<DocumentType>()
|
||||
.Where(where);
|
||||
if (orderby != null) list = list.OrderBy(b => b.CreateDt);
|
||||
return list.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,62 +7,8 @@ using System.Text;
|
||||
|
||||
namespace FreeSql.Site.DAL
|
||||
{
|
||||
public class TemplateExampleDAL
|
||||
public class TemplateExampleDAL : BaseDAL<TemplateExample>
|
||||
{
|
||||
/// <summary>
|
||||
/// 新增方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public long Insert(TemplateExample model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Insert<TemplateExample>(model).ExecuteIdentity();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 修改方法
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <returns></returns>
|
||||
public bool Update(TemplateExample model)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Update<TemplateExample>(model.ID).ExecuteUpdated().Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除方法
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public bool Delete(long id)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Delete<TemplateExample>(id).ExecuteDeleted().Count > 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取一条数据
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <returns></returns>
|
||||
public TemplateExample GetByOne(Expression<Func<TemplateExample, bool>> where)
|
||||
{
|
||||
return DataBaseType.MySql.DB().Select<TemplateExample>()
|
||||
.Where(where).ToOne();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询方法
|
||||
/// </summary>
|
||||
/// <param name="where"></param>
|
||||
/// <param name="orderby"></param>
|
||||
/// <returns></returns>
|
||||
public List<TemplateExample> Query(Expression<Func<TemplateExample, bool>> where,
|
||||
Expression<Func<TemplateExample, TemplateExample>> orderby = null)
|
||||
{
|
||||
var list = DataBaseType.MySql.DB().Select<TemplateExample>()
|
||||
.Where(where);
|
||||
if (orderby != null) list = list.OrderBy(b => b.CreateDt);
|
||||
return list.ToList();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user