add admin

This commit is contained in:
hogan
2019-01-14 18:01:01 +08:00
parent d9c0ba52fa
commit 92afa4fb6d
35 changed files with 1411 additions and 29 deletions

View File

@ -1,13 +1,40 @@
using System;
using FreeSql.Site.DAL.Helper;
using System;
namespace FreeSql.Site.DAL
{
public class Db
public static class Db
{
public static IFreeSql mysql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MySql, AppSettingsManager.Get("ConnectionStrings:DefaultDbContext"))
.Build();
public static System.Collections.Generic.Dictionary<string, IFreeSql> ConnectionPool = new System.Collections.Generic.Dictionary<string, IFreeSql>();
private static string getConnectionString(string sDatabaseType)
{
return AppSettingsManager.Get($"DbContexts:{sDatabaseType}:ConnectionString");
}
private static IFreeSql SelectDBType(string dbtype)
{
if (!ConnectionPool.ContainsKey(dbtype))
{
ConnectionPool.Add(dbtype, new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.MySql, getConnectionString(dbtype))
.Build());
}
return ConnectionPool[dbtype];
}
public static IFreeSql DB(this DataBaseType t)
{
return SelectDBType(t.ToString());
}
}
public enum DataBaseType
{
MySql,
SqlServer,
PostgreSQL,
Oracle,
Sqlite
}
}

View File

@ -0,0 +1,68 @@
//using FreeSql.Site.Entity;
using FreeSql.Site.Entity;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
namespace FreeSql.Site.DAL
{
public class DocumentCommentDAL
{
/// <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();
}
}
}

View File

@ -1,42 +1,89 @@
//using FreeSql.Site.Entity;
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 DocumentContentDAL
{
/// <summary>
/// 新增
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public long Insert(DocumentContent model)
{
return Db.mysql.Insert<DocumentContent>(model).ExecuteIdentity();
return DataBaseType.MySql.DB().Insert<DocumentContent>(model).ExecuteIdentity();
}
/// <summary>
/// 修改
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool Update(DocumentContent model)
{
return Db.mysql.Update<DocumentContent>(model.ID).ExecuteUpdated().Count > 0;
return DataBaseType.MySql.DB().Update<DocumentContent>(model.ID).ExecuteUpdated().Count > 0;
}
/// <summary>
/// 删除
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool Delete(long id)
{
return Db.mysql.Delete<DocumentContent>(id).ExecuteDeleted().Count > 0;
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 Db.mysql.Select<DocumentContent>()
return DataBaseType.MySql.DB().Select<DocumentContent>()
.Where(where).ToOne();
}
public List<DocumentContent> Query(Expression<Func<DocumentContent, bool>> where,
Expression<Func<DocumentContent, DocumentContent>> orderby = null)
/// <summary>
/// 获取一条数据
/// </summary>
/// <param name="where"></param>
/// <returns></returns>
public long Count(Expression<Func<DocumentContent, bool>> where)
{
var list = Db.mysql.Select<DocumentContent>()
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);
//设置排序
if (orderby != null) list = list.OrderBy(b => b.CreateDt);
return list.ToList();
var count = list.Count();
//设置分页操作
if (pageInfo != null && pageInfo.IsPaging)
list.Skip(pageInfo.PageIndex * pageInfo.PageSize).Limit(pageInfo.PageSize);
//执行查询
return (list.ToList(), count);
}
}
}

View File

@ -9,25 +9,57 @@ namespace FreeSql.Site.DAL
{
public class DocumentTypeDAL
{
/// <summary>
/// 新增方法
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public long Insert(DocumentType model)
{
return Db.mysql.Insert<DocumentType>(model).ExecuteIdentity();
return DataBaseType.MySql.DB().Insert<DocumentType>(model).ExecuteIdentity();
}
/// <summary>
/// 修改方法
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public bool Update(DocumentType model)
{
return Db.mysql.Update<DocumentType>(model.ID).ExecuteUpdated().Count > 0;
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 Db.mysql.Delete<DocumentType>(id).ExecuteDeleted().Count > 0;
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 = Db.mysql.Select<DocumentType>()
var list = DataBaseType.MySql.DB().Select<DocumentType>()
.Where(where);
if (orderby != null) list = list.OrderBy(b => b.CreateDt);
return list.ToList();

View File

@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace FreeSql.Site.DAL.Helper
{
public class EnumHelper
{
/// <summary>
/// 枚举类型转换为字符串
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="en"></param>
/// <returns></returns>
public static string EnumConvertToString<T>(T en)
{
//方法一
//return color.ToString();
//方法二
return Enum.GetName(en.GetType(), en);
}
public static T StringConvertToEnum<T>(string str)
{
T result = default(T);
try
{
result = (T)Enum.Parse(typeof(T), str);
}
catch (Exception ex)
{
return result;
}
return result;
}
}
}

View File

@ -0,0 +1,68 @@
//using FreeSql.Site.Entity;
using FreeSql.Site.Entity;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;
namespace FreeSql.Site.DAL
{
public class TemplateExampleDAL
{
/// <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();
}
}
}