增加功能:增加MongoDB支持

This commit is contained in:
Argo-MacBookPro 2018-10-30 13:07:29 +08:00
parent f3a77f2671
commit 55bb4b5f98
49 changed files with 579 additions and 229 deletions

View File

@ -27,6 +27,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess.MongoDB\Bootstrap.DataAccess.MongoDB.csproj" />
<ProjectReference Include="..\Bootstrap.DataAccess.SQLite\Bootstrap.DataAccess.SQLite.csproj" />
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
</ItemGroup>

View File

@ -39,7 +39,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="value"></param>
[HttpDelete]
[Authorize(Roles = "Administrators")]
public bool Delete([FromBody]IEnumerable<int> value)
public bool Delete([FromBody]IEnumerable<string> value)
{
return DictHelper.DeleteDict(value);
}

View File

@ -22,7 +22,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<Exceptions> Get(QueryExceptionOption value)
public QueryData<Object> Get(QueryExceptionOption value)
{
return value.RetrieveData();
}

View File

@ -29,7 +29,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
public Group Get(int id)
public Group Get(string id)
{
return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.Id == id);
}
@ -47,7 +47,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// </summary>
/// <param name="value"></param>
[HttpDelete]
public bool Delete([FromBody]IEnumerable<int> value)
public bool Delete([FromBody]IEnumerable<string> value)
{
return GroupHelper.DeleteGroup(value);
}
@ -58,7 +58,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="type"></param>
/// <returns></returns>
[HttpPost("{id}")]
public IEnumerable<Group> Post(int id, [FromQuery]string type)
public IEnumerable<Group> Post(string id, [FromQuery]string type)
{
var ret = new List<Group>();
switch (type)
@ -82,7 +82,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="type"></param>
/// <returns></returns>
[HttpPut("{id}")]
public bool Put(int id, [FromBody]IEnumerable<int> groupIds, [FromQuery]string type)
public bool Put(string id, [FromBody]IEnumerable<string> groupIds, [FromQuery]string type)
{
var ret = false;
switch (type)

View File

@ -28,7 +28,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="id"></param>
/// <returns></returns>
[HttpGet("{id}")]
public Log Get(int id)
public Log Get(string id)
{
return LogHelper.RetrieveLogs().FirstOrDefault(t => t.Id == id);
}

View File

@ -38,7 +38,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// </summary>
/// <param name="value"></param>
[HttpDelete]
public bool Delete([FromBody]IEnumerable<int> value)
public bool Delete([FromBody]IEnumerable<string> value)
{
return MenuHelper.DeleteMenu(value);
}
@ -49,7 +49,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="type"></param>
/// <returns></returns>
[HttpPost("{id}")]
public IEnumerable<BootstrapMenu> Post(int id, [FromQuery]string type)
public IEnumerable<BootstrapMenu> Post(string id, [FromQuery]string type)
{
var ret = new List<BootstrapMenu>();
switch (type)
@ -72,7 +72,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="value">菜单ID集合</param>
/// <returns></returns>
[HttpPut("{id}")]
public bool Put(int id, [FromBody]IEnumerable<int> value)
public bool Put(string id, [FromBody]IEnumerable<string> value)
{
return MenuHelper.SaveMenusByRoleId(id, value);
}

View File

@ -31,7 +31,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="type">类型</param>
/// <returns></returns>
[HttpPost("{id}")]
public IEnumerable<Role> Post(int id, [FromQuery]string type)
public IEnumerable<Role> Post(string id, [FromQuery]string type)
{
var ret = new List<Role>();
switch (type)
@ -58,7 +58,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="type"></param>
/// <returns></returns>
[HttpPut("{id}")]
public bool Put(int id, [FromBody]IEnumerable<int> roleIds, [FromQuery]string type)
public bool Put(string id, [FromBody]IEnumerable<string> roleIds, [FromQuery]string type)
{
var ret = false;
switch (type)
@ -91,7 +91,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// </summary>
/// <param name="value"></param>
[HttpDelete]
public bool Delete([FromBody]IEnumerable<int> value)
public bool Delete([FromBody]IEnumerable<string> value)
{
return RoleHelper.DeleteRole(value);
}

View File

@ -54,7 +54,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="type"></param>
/// <returns></returns>
[HttpPost("{id}")]
public IEnumerable<User> Post(int id, [FromQuery]string type)
public IEnumerable<User> Post(string id, [FromQuery]string type)
{
var ret = new List<User>();
switch (type)
@ -78,7 +78,7 @@ namespace Bootstrap.Admin.Controllers.Api
public bool Post([FromBody]User value)
{
var ret = false;
if (value.Id == 0)
if (string.IsNullOrEmpty(value.Id))
{
value.Description = string.Format("管理员{0}创建用户", User.Identity.Name);
value.ApprovedBy = User.Identity.Name;
@ -98,7 +98,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// <param name="type"></param>
/// <returns></returns>
[HttpPut("{id}")]
public bool Put(int id, [FromBody]IEnumerable<int> userIds, [FromQuery]string type)
public bool Put(string id, [FromBody]IEnumerable<string> userIds, [FromQuery]string type)
{
var ret = false;
switch (type)
@ -119,7 +119,7 @@ namespace Bootstrap.Admin.Controllers.Api
/// </summary>
/// <param name="value"></param>
[HttpDelete]
public bool Delete([FromBody]IEnumerable<int> value)
public bool Delete([FromBody]IEnumerable<string> value)
{
return UserHelper.DeleteUser(value);
}

View File

@ -22,7 +22,7 @@ namespace Bootstrap.Admin.Query
///
/// </summary>
/// <returns></returns>
public QueryData<Exceptions> RetrieveData()
public QueryData<object> RetrieveData()
{
var data = ExceptionsHelper.RetrieveExceptions();
if (StartTime > DateTime.MinValue)
@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Query
{
data = data.Where(t => t.LogTime < EndTime.AddDays(1));
}
var ret = new QueryData<Exceptions>();
var ret = new QueryData<object>();
ret.total = data.Count();
switch (Sort)
{
@ -52,7 +52,7 @@ namespace Bootstrap.Admin.Query
default:
break;
}
ret.rows = data.Skip(Offset).Take(Limit);
ret.rows = data.Skip(Offset).Take(Limit).Select(ex => new { ex.UserId, ex.UserIp, ex.LogTime, ex.Message, ex.ErrorPage, ex.ExceptionType });
return ret;
}
}

View File

@ -21,12 +21,19 @@
"Widget": "Bootstrap.DataAccess"
},
{
"Enabled": true,
"Enabled": false,
"Widget": "Bootstrap.DataAccess.SQLite",
"DBProviderFactory": "Microsoft.Data.Sqlite.SqliteFactory, Microsoft.Data.Sqlite",
"ConnectionStrings": {
"ba": "Data Source=BootstrapAdmin.db;"
}
},
{
"Enabled": true,
"Widget": "Bootstrap.DataAccess.MongoDB",
"ConnectionStrings": {
"ba": "mongodb://10.211.55.2:27017;Data Source=BootstrapAdmin"
}
}
],
"SwaggerPathBase": "/BA",

View File

@ -6,7 +6,7 @@
var $errorDetail = $('#errorDetail');
var $errorDetailTitle = $('#myDetailModalLabel');
$('table').smartTable({
$('.card-body table').smartTable({
url: Exceptions.url,
sortName: 'LogTime',
sortOrder: 'desc',

View File

@ -1,7 +1,7 @@
$(function () {
var url = 'api/Logs/';
$('table').smartTable({
$('.card-body table').smartTable({
url: url,
sortName: 'LogTime',
sortOrder: 'desc',

View File

@ -26,7 +26,7 @@ namespace Bootstrap.Client.DataAccess
{
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0 && m.ApplicationCode == ConfigurationManager.AppSettings["AppId"]);
DbHelper.ActiveMenu(null, menus, activeUrl);
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
DbHelper.CascadeMenus(menus, root);
return root;
}

View File

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\Keys\Longbow.Utility.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<None Include="..\Keys\Longbow.Utility.snk" Link="Longbow.Utility.snk" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.7.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,23 @@
using Bootstrap.Security;
using MongoDB.Driver;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public class Dict : DataAccess.Dict
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IEnumerable<BootstrapDict> RetrieveDicts()
{
var dicts = MongoDbAccessManager.DBAccess.GetCollection<Dict>("Dicts");
return dicts.Find(FilterDefinition<Dict>.Empty).ToList();
}
}
}

View File

@ -0,0 +1,22 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public class Exceptions : DataAccess.Exceptions
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Exceptions> RetrieveExceptions()
{
var msg = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.Exceptions>("Exceptions");
return msg.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
}
}
}

View File

@ -0,0 +1,21 @@
using MongoDB.Driver;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public class Group : DataAccess.Group
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Group> RetrieveGroups()
{
var groups = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.Group>("Groups");
return groups.Find(FilterDefinition<DataAccess.Group>.Empty).ToList();
}
}
}

View File

@ -0,0 +1,22 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public class Log : DataAccess.Log
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Log> RetrieveLogs()
{
var log = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.Log>("Logs");
return log.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList();
}
}
}

View File

@ -0,0 +1,23 @@
using Bootstrap.Security;
using MongoDB.Driver;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public class Menu : DataAccess.Menu
{
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName)
{
var menus = MongoDbAccessManager.DBAccess.GetCollection<BootstrapMenu>("Navigations");
return menus.Find(FilterDefinition<BootstrapMenu>.Empty).ToList();
}
}
}

View File

@ -0,0 +1,15 @@
using MongoDB.Driver;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
public class Message : DataAccess.Message
{
protected override IEnumerable<DataAccess.Message> RetrieveMessages(string userName)
{
//TODO: 完善其他字段信息
var msg = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.Message>("Messages");
return msg.Find(message => message.To == userName || message.From == userName).ToList();
}
}
}

View File

@ -0,0 +1,143 @@
using Bootstrap.Security;
using Longbow.Data;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;
using MongoDB.Bson.Serialization.Serializers;
using MongoDB.Driver;
using System;
using System.Linq;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public static class MongoDbAccessManager
{
private static IMongoDatabase _db = null;
private static bool _register = false;
/// <summary>
///
/// </summary>
public static IMongoDatabase DBAccess
{
get
{
if (_db == null)
{
if (!_register)
{
_register = true;
DbAdapterManager.RegisterConfigChangeCallback(InitDb);
}
InitDb();
}
return _db;
}
}
private static void InitDb()
{
var connectString = DbAdapterManager.GetConnectionString("ba");
if (string.IsNullOrEmpty(connectString)) throw new InvalidOperationException("Please set the BA default value in configuration file.");
var seq = connectString.Split(";", StringSplitOptions.RemoveEmptyEntries);
if (seq.Length != 2) throw new InvalidOperationException("");
var client = new MongoClient(seq[0]);
_db = client.GetDatabase(seq[1].Split("=", StringSplitOptions.RemoveEmptyEntries).LastOrDefault());
BsonSerializer.RegisterSerializer(new DateTimeSerializer(DateTimeKind.Local));
if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapDict)))
{
BsonClassMap.RegisterClassMap<BootstrapDict>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapUser)))
{
BsonClassMap.RegisterClassMap<BootstrapUser>(md =>
{
md.AutoMap();
md.SetIgnoreExtraElements(true);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.User)))
{
BsonClassMap.RegisterClassMap<DataAccess.User>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(BootstrapMenu)))
{
BsonClassMap.RegisterClassMap<BootstrapMenu>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Group)))
{
BsonClassMap.RegisterClassMap<DataAccess.Group>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
md.UnmapMember(group => group.Checked);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Role)))
{
BsonClassMap.RegisterClassMap<DataAccess.Role>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
md.UnmapMember(role => role.Checked);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Task)))
{
BsonClassMap.RegisterClassMap<DataAccess.Task>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Message)))
{
BsonClassMap.RegisterClassMap<DataAccess.Message>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Exceptions)))
{
BsonClassMap.RegisterClassMap<DataAccess.Exceptions>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
});
}
if (!BsonClassMap.IsClassMapRegistered(typeof(DataAccess.Log)))
{
BsonClassMap.RegisterClassMap<DataAccess.Log>(md =>
{
md.AutoMap();
md.IdMemberMap.SetSerializer(new StringSerializer(BsonType.ObjectId));
md.IdMemberMap.SetIgnoreIfDefault(true);
});
}
}
}
}

View File

@ -0,0 +1,37 @@
using MongoDB.Driver;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public class Role : DataAccess.Role
{
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<string> RetrieveRolesByUserName(string userName)
{
return new List<string>() { "Administrators" };
}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public override IEnumerable<string> RetrieveRolesByUrl(string url) => new List<string>() { "Administrators" };
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Role> RetrieveRoles()
{
var roles = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.Role>("Roles");
return roles.Find(FilterDefinition<DataAccess.Role>.Empty).ToList();
}
}
}

View File

@ -0,0 +1,21 @@
using MongoDB.Driver;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public class Task : DataAccess.Task
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Task> RetrieveTasks()
{
var users = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.Task>("Tasks");
return users.Find(FilterDefinition<DataAccess.Task>.Empty).SortByDescending(task => task.AssignTime).ToList();
}
}
}

View File

@ -0,0 +1,48 @@
using Bootstrap.Security;
using Longbow.Security.Cryptography;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
namespace Bootstrap.DataAccess.MongoDB
{
/// <summary>
///
/// </summary>
public class User : DataAccess.User
{
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override BootstrapUser RetrieveUserByUserName(string userName)
{
var users = MongoDbAccessManager.DBAccess.GetCollection<BootstrapUser>("Users");
return users.Find(user => user.UserName == userName).FirstOrDefault();
}
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <returns></returns>
public override bool Authenticate(string userName, string password)
{
if (string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password)) return false;
var users = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.User>("Users");
var u = users.Find(user => user.UserName == userName).FirstOrDefault();
return !string.IsNullOrEmpty(u.PassSalt) && u.Password == LgbCryptography.ComputeHash(password, u.PassSalt);
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.User> RetrieveNewUsers()
{
var users = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.User>("Users");
return users.Find(user => user.ApprovedTime == DateTime.MinValue).SortByDescending(user => user.RegisterTime).ToList();
}
}
}

View File

@ -75,7 +75,7 @@ namespace Bootstrap.DataAccess.SQLite
{
exceptions.Add(new DataAccess.Exceptions()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
AppDomainName = (string)reader[1],
ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],

View File

@ -17,7 +17,7 @@ namespace Bootstrap.DataAccess.SQLite
/// 删除群组信息
/// </summary>
/// <param name="ids"></param>
public override bool DeleteGroup(IEnumerable<int> value)
public override bool DeleteGroup(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByUserId(int userId, IEnumerable<int> groupIds)
public override bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
{
var ret = false;
@ -76,7 +76,7 @@ namespace Bootstrap.DataAccess.SQLite
});
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<int>() { userId });
CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<string>() { userId });
ret = true;
}
catch (Exception ex)
@ -93,7 +93,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByRoleId(int roleId, IEnumerable<int> groupIds)
public override bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
@ -113,7 +113,7 @@ namespace Bootstrap.DataAccess.SQLite
});
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<int>() { roleId });
CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<string>() { roleId });
ret = true;
}
catch (Exception ex)

View File

@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess.SQLite
/// </summary>
/// <param name="tId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Log> RetrieveLogs(string tId = null)
public override IEnumerable<DataAccess.Log> RetrieveLogs()
{
string sql = "select * from Logs where LogTime > datetime('now', 'localtime', '-7 day')";
List<DataAccess.Log> logs = new List<DataAccess.Log>();
@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess.SQLite
{
logs.Add(new DataAccess.Log()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
CRUD = (string)reader[1],
UserName = (string)reader[2],
LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),

View File

@ -16,7 +16,7 @@ namespace Bootstrap.DataAccess.SQLite
/// 删除菜单信息
/// </summary>
/// <param name="value"></param>
public override bool DeleteMenu(IEnumerable<int> value)
public override bool DeleteMenu(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
@ -51,7 +51,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="roleId"></param>
/// <param name="menuIds"></param>
/// <returns></returns>
public override bool SaveMenusByRoleId(int roleId, IEnumerable<int> menuIds)
public override bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
@ -71,7 +71,7 @@ namespace Bootstrap.DataAccess.SQLite
});
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<int>() { roleId });
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<string>() { roleId });
ret = true;
}
catch (Exception ex)

View File

@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess.SQLite
{
messages.Add(new DataAccess.Message()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
Title = (string)reader[1],
Content = (string)reader[2],
From = (string)reader[3],

View File

@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByUserId(int userId, IEnumerable<int> roleIds)
public override bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds)
{
var ret = false;
//判断用户是否选定角色
@ -39,7 +39,7 @@ namespace Bootstrap.DataAccess.SQLite
});
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(userIds: new List<int>() { userId }, roleIds: roleIds);
CacheCleanUtility.ClearCache(userIds: new List<string>() { userId }, roleIds: roleIds);
ret = true;
}
catch (Exception ex)
@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess.SQLite
/// 删除角色表
/// </summary>
/// <param name="value"></param>
public override bool DeleteRole(IEnumerable<int> value)
public override bool DeleteRole(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
@ -94,7 +94,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="menuId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SavaRolesByMenuId(int menuId, IEnumerable<int> roleIds)
public override bool SavaRolesByMenuId(string menuId, IEnumerable<string> roleIds)
{
var ret = false;
//判断用户是否选定角色
@ -115,7 +115,7 @@ namespace Bootstrap.DataAccess.SQLite
});
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<int>() { menuId });
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<string>() { menuId });
ret = true;
}
catch (Exception ex)
@ -132,7 +132,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="groupId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByGroupId(int groupId, IEnumerable<int> roleIds)
public override bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
{
var ret = false;
//构造表格
@ -154,7 +154,7 @@ namespace Bootstrap.DataAccess.SQLite
});
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<int>() { groupId });
CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<string>() { groupId });
ret = true;
}
catch (Exception ex)

View File

@ -23,7 +23,7 @@ namespace Bootstrap.DataAccess.SQLite
{
tasks.Add(new DataAccess.Task()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
TaskName = (string)reader[1],
AssignName = (string)reader[2],
UserName = (string)reader[3],

View File

@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess.SQLite
/// 删除用户
/// </summary>
/// <param name="value"></param>
public override bool DeleteUser(IEnumerable<int> value)
public override bool DeleteUser(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
@ -58,7 +58,7 @@ namespace Bootstrap.DataAccess.SQLite
public override bool SaveUser(DataAccess.User p)
{
var ret = false;
if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
if (string.IsNullOrEmpty(p.Id) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
p.PassSalt = LgbCryptography.GenerateSalt();
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
@ -86,7 +86,7 @@ namespace Bootstrap.DataAccess.SQLite
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
ret = true;
}
}
@ -105,7 +105,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="id"></param>
/// <param name="approvedBy"></param>
/// <returns></returns>
public override bool ApproveUser(int id, string approvedBy)
public override bool ApproveUser(string id, string approvedBy)
{
var ret = false;
var sql = "update Users set ApprovedTime = datetime('now', 'localtime'), ApprovedBy = @approvedBy where ID = @id";
@ -114,7 +114,7 @@ namespace Bootstrap.DataAccess.SQLite
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
if (ret) CacheCleanUtility.ClearCache(userIds: new List<string>() { id });
}
return ret;
}
@ -125,7 +125,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="rejectBy"></param>
/// <param name="reason"></param>
/// <returns></returns>
public override bool RejectUser(int id, string rejectBy)
public override bool RejectUser(string id, string rejectBy)
{
var ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
@ -146,7 +146,7 @@ namespace Bootstrap.DataAccess.SQLite
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
CacheCleanUtility.ClearCache(userIds: new List<string>() { id });
ret = true;
}
}
@ -164,7 +164,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="roleId">角色ID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public override bool SaveUsersByRoleId(int roleId, IEnumerable<int> userIds)
public override bool SaveUsersByRoleId(string roleId, IEnumerable<string> userIds)
{
bool ret = false;
DataTable dt = new DataTable();
@ -188,7 +188,7 @@ namespace Bootstrap.DataAccess.SQLite
});
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<int>() { roleId });
CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<string>() { roleId });
ret = true;
}
catch (Exception ex)
@ -205,7 +205,7 @@ namespace Bootstrap.DataAccess.SQLite
/// <param name="groupId">GroupID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public override bool SaveUsersByGroupId(int groupId, IEnumerable<int> userIds)
public override bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
@ -225,7 +225,7 @@ namespace Bootstrap.DataAccess.SQLite
});
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<int>() { groupId });
CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<string>() { groupId });
ret = true;
}
catch (Exception ex)

View File

@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess
/// <param name="menuIds"></param>
/// <param name="dictIds"></param>
/// <param name="cacheKey"></param>
public static void ClearCache(IEnumerable<int> roleIds = null, IEnumerable<int> userIds = null, IEnumerable<int> groupIds = null, IEnumerable<int> menuIds = null, string dictIds = null, string cacheKey = null)
public static void ClearCache(IEnumerable<string> roleIds = null, IEnumerable<string> userIds = null, IEnumerable<string> groupIds = null, IEnumerable<string> menuIds = null, string dictIds = null, string cacheKey = null)
{
var cacheKeys = new List<string>();
var corsKeys = new List<string>();

View File

@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="value">需要删除的IDs</param>
/// <returns></returns>
public virtual bool DeleteDict(IEnumerable<int> value)
public virtual bool DeleteDict(IEnumerable<string> value)
{
var ret = false;
var ids = string.Join(",", value);
@ -41,7 +41,7 @@ namespace Bootstrap.DataAccess
if (dict.Category.Length > 50) dict.Category = dict.Category.Substring(0, 50);
if (dict.Name.Length > 50) dict.Name = dict.Name.Substring(0, 50);
if (dict.Code.Length > 50) dict.Code = dict.Code.Substring(0, 50);
string sql = dict.Id == 0 ?
string sql = string.IsNullOrEmpty(dict.Id) ?
"Insert Into Dicts (Category, Name, Code ,Define) Values (@Category, @Name, @Code, @Define)" :
"Update Dicts set Category = @Category, Name = @Name, Code = @Code, Define = @Define where ID = @ID";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
@ -53,7 +53,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(dictIds: dict.Id == 0 ? string.Empty : dict.Id.ToString());
CacheCleanUtility.ClearCache(dictIds: string.IsNullOrEmpty(dict.Id) ? string.Empty : dict.Id.ToString());
return ret;
}
/// <summary>
@ -81,84 +81,46 @@ namespace Bootstrap.DataAccess
/// 获取字典分类名称
/// </summary>
/// <returns></returns>
public virtual IEnumerable<string> RetrieveCategories()
{
var ret = new List<string>();
string sql = "select distinct Category from Dicts";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
ret.Add((string)reader[0]);
}
}
return ret;
}
public virtual IEnumerable<string> RetrieveCategories() => DictHelper.RetrieveDicts().Select(d => d.Category);
/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual string RetrieveWebTitle()
{
var settings = RetrieveDicts();
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
}
public virtual string RetrieveWebTitle() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual string RetrieveWebFooter()
{
var settings = RetrieveDicts();
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
}
public virtual string RetrieveWebFooter() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
/// <summary>
/// 获得系统中配置的可以使用的网站样式
/// </summary>
/// <returns></returns>
public virtual IEnumerable<BootstrapDict> RetrieveThemes()
{
var data = RetrieveDicts();
return data.Where(d => d.Category == "网站样式");
}
public virtual IEnumerable<BootstrapDict> RetrieveThemes() => DictHelper.RetrieveDicts().Where(d => d.Category == "网站样式");
/// <summary>
/// 获得网站设置中的当前样式
/// </summary>
/// <returns></returns>
public virtual string RetrieveActiveTheme()
{
var data = RetrieveDicts();
var theme = data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault();
var theme = DictHelper.RetrieveDicts().Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0).FirstOrDefault();
return theme == null ? string.Empty : (theme.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase) ? string.Empty : theme.Code);
}
/// <summary>
/// 获取头像路径
/// </summary>
/// <returns></returns>
public virtual BootstrapDict RetrieveIconFolderPath()
{
var data = RetrieveDicts();
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" };
}
public virtual BootstrapDict RetrieveIconFolderPath() => DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" };
/// <summary>
/// 获得默认的前台首页地址,默认为~/Home/Index
/// </summary>
/// <returns></returns>
public virtual string RetrieveHomeUrl()
{
var settings = RetrieveDicts();
return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
}
public virtual string RetrieveHomeUrl() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual IEnumerable<KeyValuePair<string, string>> RetrieveApps()
{
var settings = RetrieveDicts();
return settings.Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).OrderBy(d => d.Key);
}
public virtual IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DictHelper.RetrieveDicts().Where(d => d.Category == "应用程序" && d.Define == 0).Select(d => new KeyValuePair<string, string>(d.Code, d.Name)).OrderBy(d => d.Key);
/// <summary>
/// 通过数据库获得所有字典表配置信息缓存Key=DictHelper-RetrieveDicts
/// </summary>

View File

@ -17,7 +17,7 @@ namespace Bootstrap.DataAccess
/// <summary>
///
/// </summary>
public int Id { get; set; }
public string Id { get; set; }
/// <summary>
///
/// </summary>
@ -112,7 +112,7 @@ namespace Bootstrap.DataAccess
{
exceptions.Add(new Exceptions()
{
Id = (int)reader[0],
Id = reader[0].ToString(),
AppDomainName = (string)reader[1],
ErrorPage = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
UserId = reader.IsDBNull(3) ? string.Empty : (string)reader[3],

View File

@ -1,5 +1,4 @@
using Longbow;
using Longbow.Data;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
@ -17,18 +16,15 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获得/设置 群组主键ID
/// </summary>
public int Id { get; set; }
public string Id { get; set; }
/// <summary>
/// 获得/设置 群组名称
/// </summary>
public string GroupName { get; set; }
/// <summary>
/// 获得/设置 群组描述
/// </summary>
public string Description { get; set; }
/// <summary>
/// 获取/设置 用户群组关联状态 checked 标示已经关联 '' 标示未关联
/// </summary>
@ -38,7 +34,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual IEnumerable<Group> RetrieveGroups(int id = 0)
public virtual IEnumerable<Group> RetrieveGroups()
{
string sql = "select * from Groups";
List<Group> groups = new List<Group>();
@ -49,7 +45,7 @@ namespace Bootstrap.DataAccess
{
groups.Add(new Group()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
});
@ -61,7 +57,7 @@ namespace Bootstrap.DataAccess
/// 删除群组信息
/// </summary>
/// <param name="ids"></param>
public virtual bool DeleteGroup(IEnumerable<int> value)
public virtual bool DeleteGroup(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
@ -83,7 +79,7 @@ namespace Bootstrap.DataAccess
bool ret = false;
if (p.GroupName.Length > 50) p.GroupName = p.GroupName.Substring(0, 50);
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
string sql = p.Id == 0 ?
string sql = string.IsNullOrEmpty(p.Id) ?
"Insert Into Groups (GroupName, Description) Values (@GroupName, @Description)" :
"Update Groups set GroupName = @GroupName, Description = @Description where ID = @ID";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
@ -93,7 +89,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(groupIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
CacheCleanUtility.ClearCache(groupIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
return ret;
}
/// <summary>
@ -101,7 +97,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public virtual IEnumerable<Group> RetrieveGroupsByUserId(int userId)
public virtual IEnumerable<Group> RetrieveGroupsByUserId(string userId)
{
string sql = "select g.ID,g.GroupName,g.[Description],case ug.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join UserGroup ug on g.ID=ug.GroupID and UserID=@UserID";
List<Group> groups = new List<Group>();
@ -113,7 +109,7 @@ namespace Bootstrap.DataAccess
{
groups.Add(new Group()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
@ -128,7 +124,7 @@ namespace Bootstrap.DataAccess
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public virtual bool SaveGroupsByUserId(int userId, IEnumerable<int> groupIds)
public virtual bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
{
var ret = false;
DataTable dt = new DataTable();
@ -157,7 +153,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction();
}
}
CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<int>() { userId });
CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<string>() { userId });
ret = true;
}
catch (Exception ex)
@ -173,7 +169,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public virtual IEnumerable<Group> RetrieveGroupsByRoleId(int roleId)
public virtual IEnumerable<Group> RetrieveGroupsByRoleId(string roleId)
{
List<Group> groups = new List<Group>();
string sql = "select g.ID,g.GroupName,g.[Description],case rg.GroupID when g.ID then 'checked' else '' end [status] from Groups g left join RoleGroup rg on g.ID=rg.GroupID and RoleID=@RoleID";
@ -185,7 +181,7 @@ namespace Bootstrap.DataAccess
{
groups.Add(new Group()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
@ -200,7 +196,7 @@ namespace Bootstrap.DataAccess
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public virtual bool SaveGroupsByRoleId(int roleId, IEnumerable<int> groupIds)
public virtual bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
{
bool ret = false;
DataTable dt = new DataTable();
@ -227,7 +223,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction();
}
}
CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<int>() { roleId });
CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<string>() { roleId });
ret = true;
}
catch (Exception ex)

View File

@ -31,7 +31,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="value">需要删除的IDs</param>
/// <returns></returns>
public static bool DeleteDict(IEnumerable<int> value) => DbAdapterManager.Create<Dict>().DeleteDict(value);
public static bool DeleteDict(IEnumerable<string> value) => DbAdapterManager.Create<Dict>().DeleteDict(value);
/// <summary>
/// 保存新建/更新的字典信息
/// </summary>

View File

@ -1,7 +1,6 @@
using Longbow.Cache;
using Longbow.Data;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.DataAccess
{
@ -19,17 +18,12 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<Group> RetrieveGroups(int id = 0)
{
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create<Group>().RetrieveGroups(id));
return id == 0 ? ret : ret.Where(t => id == t.Id);
}
public static IEnumerable<Group> RetrieveGroups() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create<Group>().RetrieveGroups());
/// <summary>
/// 删除群组信息
/// </summary>
/// <param name="ids"></param>
public static bool DeleteGroup(IEnumerable<int> value) => DbAdapterManager.Create<Group>().DeleteGroup(value);
public static bool DeleteGroup(IEnumerable<string> value) => DbAdapterManager.Create<Group>().DeleteGroup(value);
/// <summary>
/// 保存新建/更新的群组信息
/// </summary>
@ -41,28 +35,28 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public static IEnumerable<Group> RetrieveGroupsByUserId(int userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create<Group>().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey);
public static IEnumerable<Group> RetrieveGroupsByUserId(string userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create<Group>().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey);
/// <summary>
/// 保存用户部门关系
/// </summary>
/// <param name="id"></param>
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public static bool SaveGroupsByUserId(int id, IEnumerable<int> groupIds) => DbAdapterManager.Create<Group>().SaveGroupsByUserId(id, groupIds);
public static bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds) => DbAdapterManager.Create<Group>().SaveGroupsByUserId(userId, groupIds);
/// <summary>
/// 根据角色ID指派部门
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public static IEnumerable<Group> RetrieveGroupsByRoleId(int roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create<Group>().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey);
public static IEnumerable<Group> RetrieveGroupsByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create<Group>().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey);
/// <summary>
/// 根据角色ID以及选定的部门ID保到角色部门表
/// </summary>
/// <param name="id"></param>
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public static bool SaveGroupsByRoleId(int id, IEnumerable<int> groupIds) => DbAdapterManager.Create<Group>().SaveGroupsByRoleId(id, groupIds);
public static bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds) => DbAdapterManager.Create<Group>().SaveGroupsByRoleId(roleId, groupIds);
/// <summary>
///
/// </summary>

View File

@ -20,11 +20,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="tId"></param>
/// <returns></returns>
public static IEnumerable<Log> RetrieveLogs(string tId = null)
{
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbAdapterManager.Create<Log>().RetrieveLogs(tId));
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
}
public static IEnumerable<Log> RetrieveLogs() => CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbAdapterManager.Create<Log>().RetrieveLogs());
/// <summary>
/// 保存新增的日志信息
/// </summary>

View File

@ -31,7 +31,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool DeleteMenu(IEnumerable<int> value) => DbAdapterManager.Create<Menu>().DeleteMenu(value);
public static bool DeleteMenu(IEnumerable<string> value) => DbAdapterManager.Create<Menu>().DeleteMenu(value);
/// <summary>
/// 通过用户名获得所有菜单
/// </summary>
@ -43,14 +43,14 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create<Menu>().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey);
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create<Menu>().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey);
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <returns></returns>
public static bool SaveMenusByRoleId(int id, IEnumerable<int> value) => DbAdapterManager.Create<Menu>().SaveMenusByRoleId(id, value);
public static bool SaveMenusByRoleId(string id, IEnumerable<string> value) => DbAdapterManager.Create<Menu>().SaveMenusByRoleId(id, value);
/// <summary>
///
/// </summary>
@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0);
if (appId != "0") menus = menus.Where(m => m.ApplicationCode == appId);
DbHelper.ActiveMenu(null, menus, activeUrl);
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
DbHelper.CascadeMenus(menus, root);
return root;
}
@ -78,7 +78,7 @@ namespace Bootstrap.DataAccess
{
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "0" && m.IsResource == 0);
DbHelper.ActiveMenu(null, menus, activeUrl);
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
DbHelper.CascadeMenus(menus, root);
return root;
}
@ -90,7 +90,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<BootstrapMenu> RetrieveMenus(string userName)
{
var menus = RetrieveAllMenus(userName);
var root = menus.Where(m => m.ParentId == 0).OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
DbHelper.CascadeMenus(menus, root);
return root;
}

View File

@ -21,28 +21,24 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRoles(int id = 0)
{
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbAdapterManager.Create<Role>().RetrieveRoles(id));
return id == 0 ? ret : ret.Where(t => id == t.Id);
}
public static IEnumerable<Role> RetrieveRoles() => CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbAdapterManager.Create<Role>().RetrieveRoles());
/// <summary>
/// 保存用户角色关系
/// </summary>
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public static bool SaveRolesByUserId(int userId, IEnumerable<int> roleIds) => DbAdapterManager.Create<Role>().SaveRolesByUserId(userId, roleIds);
public static bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds) => DbAdapterManager.Create<Role>().SaveRolesByUserId(userId, roleIds);
/// <summary>
/// 查询某个用户所拥有的角色
/// </summary>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRolesByUserId(int userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbAdapterManager.Create<Role>().RetrieveRolesByUserId(userId), RetrieveRolesByUserIdDataKey);
public static IEnumerable<Role> RetrieveRolesByUserId(string userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbAdapterManager.Create<Role>().RetrieveRolesByUserId(userId), RetrieveRolesByUserIdDataKey);
/// <summary>
/// 删除角色表
/// </summary>
/// <param name="value"></param>
public static bool DeleteRole(IEnumerable<int> value) => DbAdapterManager.Create<Role>().DeleteRole(value);
public static bool DeleteRole(IEnumerable<string> value) => DbAdapterManager.Create<Role>().DeleteRole(value);
/// <summary>
/// 保存新建/更新的角色信息
/// </summary>
@ -54,27 +50,27 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRolesByMenuId(int menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbAdapterManager.Create<Role>().RetrieveRolesByMenuId(menuId), RetrieveRolesByMenuIdDataKey);
public static IEnumerable<Role> RetrieveRolesByMenuId(string menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbAdapterManager.Create<Role>().RetrieveRolesByMenuId(menuId), RetrieveRolesByMenuIdDataKey);
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public static bool SavaRolesByMenuId(int id, IEnumerable<int> roleIds) => DbAdapterManager.Create<Role>().SavaRolesByMenuId(id, roleIds);
public static bool SavaRolesByMenuId(string id, IEnumerable<string> roleIds) => DbAdapterManager.Create<Role>().SavaRolesByMenuId(id, roleIds);
/// <summary>
/// 根据GroupId查询和该Group有关的所有Roles
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRolesByGroupId(int groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbAdapterManager.Create<Role>().RetrieveRolesByGroupId(groupId), RetrieveRolesByGroupIdDataKey);
public static IEnumerable<Role> RetrieveRolesByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbAdapterManager.Create<Role>().RetrieveRolesByGroupId(groupId), RetrieveRolesByGroupIdDataKey);
/// <summary>
/// 根据GroupId更新Roles信息删除旧的Roles信息插入新的Roles信息
/// </summary>
/// <param name="id"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public static bool SaveRolesByGroupId(int id, IEnumerable<int> roleIds) => DbAdapterManager.Create<Role>().SaveRolesByGroupId(id, roleIds);
public static bool SaveRolesByGroupId(string id, IEnumerable<string> roleIds) => DbAdapterManager.Create<Role>().SaveRolesByGroupId(id, roleIds);
/// <summary>
///
/// </summary>

View File

@ -37,7 +37,7 @@ namespace Bootstrap.DataAccess
/// 删除用户
/// </summary>
/// <param name="value"></param>
public static bool DeleteUser(IEnumerable<int> value) => DbAdapterManager.Create<User>().DeleteUser(value);
public static bool DeleteUser(IEnumerable<string> value) => DbAdapterManager.Create<User>().DeleteUser(value);
/// <summary>
/// 保存新建
/// </summary>
@ -51,14 +51,14 @@ namespace Bootstrap.DataAccess
/// <param name="password"></param>
/// <param name="displayName"></param>
/// <returns></returns>
public static bool UpdateUser(int id, string password, string displayName) => DbAdapterManager.Create<User>().UpdateUser(id, password, displayName);
public static bool UpdateUser(string id, string password, string displayName) => DbAdapterManager.Create<User>().UpdateUser(id, password, displayName);
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="approvedBy"></param>
/// <returns></returns>
public static bool ApproveUser(int id, string approvedBy) => DbAdapterManager.Create<User>().ApproveUser(id, approvedBy);
public static bool ApproveUser(string id, string approvedBy) => DbAdapterManager.Create<User>().ApproveUser(id, approvedBy);
/// <summary>
///
/// </summary>
@ -74,33 +74,33 @@ namespace Bootstrap.DataAccess
/// <param name="rejectBy"></param>
/// <param name="reason"></param>
/// <returns></returns>
public static bool RejectUser(int id, string rejectBy) => DbAdapterManager.Create<User>().RejectUser(id, rejectBy);
public static bool RejectUser(string id, string rejectBy) => DbAdapterManager.Create<User>().RejectUser(id, rejectBy);
/// <summary>
/// 通过roleId获取所有用户
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public static IEnumerable<User> RetrieveUsersByRoleId(int roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbAdapterManager.Create<User>().RetrieveUsersByRoleId(roleId), RetrieveUsersByRoleIdDataKey);
public static IEnumerable<User> RetrieveUsersByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbAdapterManager.Create<User>().RetrieveUsersByRoleId(roleId), RetrieveUsersByRoleIdDataKey);
/// <summary>
/// 通过角色ID保存当前授权用户插入
/// </summary>
/// <param name="id">角色ID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public static bool SaveUsersByRoleId(int id, IEnumerable<int> userIds) => DbAdapterManager.Create<User>().SaveUsersByRoleId(id, userIds);
public static bool SaveUsersByRoleId(string id, IEnumerable<string> userIds) => DbAdapterManager.Create<User>().SaveUsersByRoleId(id, userIds);
/// <summary>
/// 通过groupId获取所有用户
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public static IEnumerable<User> RetrieveUsersByGroupId(int groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbAdapterManager.Create<User>().RetrieveUsersByGroupId(groupId), RetrieveUsersByRoleIdDataKey);
public static IEnumerable<User> RetrieveUsersByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbAdapterManager.Create<User>().RetrieveUsersByGroupId(groupId), RetrieveUsersByRoleIdDataKey);
/// <summary>
/// 通过部门ID保存当前授权用户插入
/// </summary>
/// <param name="id">GroupID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public static bool SaveUsersByGroupId(int id, IEnumerable<int> userIds) => DbAdapterManager.Create<User>().SaveUsersByGroupId(id, userIds);
public static bool SaveUsersByGroupId(string id, IEnumerable<string> userIds) => DbAdapterManager.Create<User>().SaveUsersByGroupId(id, userIds);
/// 根据用户名修改用户头像
/// </summary>
/// <param name="userName"></param>

View File

@ -15,7 +15,7 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获得/设置 操作日志主键ID
/// </summary>
public int Id { get; set; }
public string Id { get; set; }
/// <summary>
/// 获得/设置 操作类型
@ -51,7 +51,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="tId"></param>
/// <returns></returns>
public virtual IEnumerable<Log> RetrieveLogs(string tId = null)
public virtual IEnumerable<Log> RetrieveLogs()
{
string sql = "select * from Logs where DATEDIFF(Week, LogTime, GETDATE()) = 0";
List<Log> logs = new List<Log>();
@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess
{
logs.Add(new Log()
{
Id = (int)reader[0],
Id = reader[0].ToString(),
CRUD = (string)reader[1],
UserName = (string)reader[2],
LogTime = (DateTime)reader[3],

View File

@ -1,6 +1,5 @@
using Bootstrap.Security;
using Bootstrap.Security.DataAccess;
using Longbow;
using Longbow.Data;
using System;
using System.Collections.Generic;
@ -20,7 +19,7 @@ namespace Bootstrap.DataAccess
/// 删除菜单信息
/// </summary>
/// <param name="value"></param>
public virtual bool DeleteMenu(IEnumerable<int> value)
public virtual bool DeleteMenu(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
@ -44,7 +43,7 @@ namespace Bootstrap.DataAccess
if (p.Name.Length > 50) p.Name = p.Name.Substring(0, 50);
if (p.Icon != null && p.Icon.Length > 50) p.Icon = p.Icon.Substring(0, 50);
if (p.Url != null && p.Url.Length > 4000) p.Url = p.Url.Substring(0, 4000);
string sql = p.Id == 0 ?
string sql = string.IsNullOrEmpty(p.Id) ?
"Insert Into Navigations (ParentId, Name, [Order], Icon, Url, Category, Target, IsResource, [Application]) Values (@ParentId, @Name, @Order, @Icon, @Url, @Category, @Target, @IsResource, @ApplicationCode)" :
"Update Navigations set ParentId = @ParentId, Name = @Name, [Order] = @Order, Icon = @Icon, Url = @Url, Category = @Category, Target = @Target, IsResource = @IsResource, Application = @ApplicationCode where ID = @ID";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
@ -61,7 +60,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(menuIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
return ret;
}
/// <summary>
@ -69,7 +68,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public virtual IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
public virtual IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(string roleId)
{
var menus = new List<BootstrapMenu>();
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
@ -82,7 +81,7 @@ namespace Bootstrap.DataAccess
{
menus.Add(new BootstrapMenu()
{
Id = LgbConvert.ReadValue(reader[0], 0)
Id = reader[0].ToString()
});
}
}
@ -95,7 +94,7 @@ namespace Bootstrap.DataAccess
/// <param name="roleId"></param>
/// <param name="menuIds"></param>
/// <returns></returns>
public virtual bool SaveMenusByRoleId(int roleId, IEnumerable<int> menuIds)
public virtual bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
{
bool ret = false;
DataTable dt = new DataTable();
@ -121,7 +120,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction();
}
}
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<int>() { roleId });
CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<string>() { roleId });
ret = true;
}
catch (Exception ex)
@ -133,7 +132,7 @@ namespace Bootstrap.DataAccess
return ret;
}
/// <summary>
/// 通过当前用户名获得所有菜单,层次化后集合
/// 通过当前用户名获得所有菜单
/// </summary>
/// <param name="userName">当前登陆的用户名</param>
/// <returns></returns>

View File

@ -15,7 +15,7 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 消息主键 数据库自增
/// </summary>
public int Id { get; set; }
public string Id { get; set; }
/// <summary>
/// 标题
/// </summary>
@ -85,7 +85,7 @@ namespace Bootstrap.DataAccess
{
messages.Add(new Message()
{
Id = (int)reader[0],
Id = reader[0].ToString(),
Title = (string)reader[1],
Content = (string)reader[2],
From = (string)reader[3],

View File

@ -1,5 +1,4 @@
using Bootstrap.Security.DataAccess;
using Longbow;
using Longbow.Data;
using System;
using System.Collections.Generic;
@ -18,7 +17,7 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获得/设置 角色主键ID
/// </summary>
public int Id { get; set; }
public string Id { get; set; }
/// <summary>
/// 获得/设置 角色名称
/// </summary>
@ -34,9 +33,8 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 查询所有角色
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual IEnumerable<Role> RetrieveRoles(int id = 0)
public virtual IEnumerable<Role> RetrieveRoles()
{
string sql = "select * from Roles";
var roles = new List<Role>();
@ -47,7 +45,7 @@ namespace Bootstrap.DataAccess
{
roles.Add(new Role()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
RoleName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
});
@ -61,7 +59,7 @@ namespace Bootstrap.DataAccess
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public virtual bool SaveRolesByUserId(int userId, IEnumerable<int> roleIds)
public virtual bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds)
{
var ret = false;
DataTable dt = new DataTable();
@ -91,7 +89,7 @@ namespace Bootstrap.DataAccess
}
transaction.CommitTransaction();
}
CacheCleanUtility.ClearCache(userIds: new List<int>() { userId }, roleIds: roleIds);
CacheCleanUtility.ClearCache(userIds: new List<string>() { userId }, roleIds: roleIds);
ret = true;
}
catch (Exception ex)
@ -106,7 +104,7 @@ namespace Bootstrap.DataAccess
/// 查询某个用户所拥有的角色
/// </summary>
/// <returns></returns>
public virtual IEnumerable<Role> RetrieveRolesByUserId(int userId)
public virtual IEnumerable<Role> RetrieveRolesByUserId(string userId)
{
List<Role> roles = new List<Role>();
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @UserID";
@ -118,7 +116,7 @@ namespace Bootstrap.DataAccess
{
roles.Add(new Role()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
RoleName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
@ -131,7 +129,7 @@ namespace Bootstrap.DataAccess
/// 删除角色表
/// </summary>
/// <param name="value"></param>
public virtual bool DeleteRole(IEnumerable<int> value)
public virtual bool DeleteRole(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
@ -153,7 +151,7 @@ namespace Bootstrap.DataAccess
bool ret = false;
if (!string.IsNullOrEmpty(p.RoleName) && p.RoleName.Length > 50) p.RoleName = p.RoleName.Substring(0, 50);
if (!string.IsNullOrEmpty(p.Description) && p.Description.Length > 50) p.Description = p.Description.Substring(0, 500);
string sql = p.Id == 0 ?
string sql = string.IsNullOrEmpty(p.Id) ?
"Insert Into Roles (RoleName, Description) Values (@RoleName, @Description)" :
"Update Roles set RoleName = @RoleName, Description = @Description where ID = @ID";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
@ -163,7 +161,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
CacheCleanUtility.ClearCache(roleIds: p.Id == 0 ? new List<int>() : new List<int> { p.Id });
CacheCleanUtility.ClearCache(roleIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string> { p.Id });
return ret;
}
/// <summary>
@ -171,7 +169,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public virtual IEnumerable<Role> RetrieveRolesByMenuId(int menuId)
public virtual IEnumerable<Role> RetrieveRolesByMenuId(string menuId)
{
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @NavigationID";
List<Role> roles = new List<Role>();
@ -183,7 +181,7 @@ namespace Bootstrap.DataAccess
{
roles.Add(new Role()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
RoleName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
@ -198,7 +196,7 @@ namespace Bootstrap.DataAccess
/// <param name="menuId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public virtual bool SavaRolesByMenuId(int menuId, IEnumerable<int> roleIds)
public virtual bool SavaRolesByMenuId(string menuId, IEnumerable<string> roleIds)
{
var ret = false;
DataTable dt = new DataTable();
@ -227,7 +225,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction();
}
}
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<int>() { menuId });
CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<string>() { menuId });
ret = true;
}
catch (Exception ex)
@ -243,7 +241,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public virtual IEnumerable<Role> RetrieveRolesByGroupId(int groupId)
public virtual IEnumerable<Role> RetrieveRolesByGroupId(string groupId)
{
List<Role> roles = new List<Role>();
string sql = "select r.ID, r.RoleName, r.[Description], case ur.RoleID when r.ID then 'checked' else '' end [status] from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @GroupID";
@ -255,7 +253,7 @@ namespace Bootstrap.DataAccess
{
roles.Add(new Role()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
RoleName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
@ -270,7 +268,7 @@ namespace Bootstrap.DataAccess
/// <param name="groupId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public virtual bool SaveRolesByGroupId(int groupId, IEnumerable<int> roleIds)
public virtual bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
{
var ret = false;
//构造表格
@ -299,7 +297,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction();
}
}
CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<int>() { groupId });
CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<string>() { groupId });
ret = true;
}
catch (Exception ex)

View File

@ -10,7 +10,7 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获取/设置 任务ID
/// </summary>
public int Id { get; set; }
public string Id { get; set; }
/// <summary>
/// 获取/设置 任务名称
/// </summary>
@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess
{
tasks.Add(new Task()
{
Id = (int)reader[0],
Id = reader[0].ToString(),
TaskName = (string)reader[1],
AssignName = (string)reader[2],
UserName = (string)reader[3],

View File

@ -20,7 +20,7 @@ namespace Bootstrap.DataAccess
/// <summary>
/// 获得/设置 用户主键ID
/// </summary>
public int Id { get; set; }
public string Id { get; set; }
/// <summary>
/// 获取/设置 密码
/// </summary>
@ -129,7 +129,7 @@ namespace Bootstrap.DataAccess
{
users.Add(new User()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
UserName = (string)reader[1],
DisplayName = (string)reader[2],
RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
@ -156,7 +156,7 @@ namespace Bootstrap.DataAccess
{
users.Add(new User()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
UserName = (string)reader[1],
DisplayName = (string)reader[2],
RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
@ -170,7 +170,7 @@ namespace Bootstrap.DataAccess
/// 删除用户
/// </summary>
/// <param name="value"></param>
public virtual bool DeleteUser(IEnumerable<int> value)
public virtual bool DeleteUser(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
@ -190,7 +190,7 @@ namespace Bootstrap.DataAccess
public virtual bool SaveUser(User p)
{
var ret = false;
if (p.Id == 0 && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
if (string.IsNullOrEmpty(p.Id) && p.Description.Length > 500) p.Description = p.Description.Substring(0, 500);
if (p.UserName.Length > 50) p.UserName = p.UserName.Substring(0, 50);
p.PassSalt = LgbCryptography.GenerateSalt();
p.Password = LgbCryptography.ComputeHash(p.Password, p.PassSalt);
@ -203,7 +203,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", DbAdapterManager.ToDBValue(p.ApprovedBy)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@description", p.Description));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: p.Id == 0 ? new List<int>() : new List<int>() { p.Id });
if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
}
return ret;
}
@ -214,7 +214,7 @@ namespace Bootstrap.DataAccess
/// <param name="password"></param>
/// <param name="displayName"></param>
/// <returns></returns>
public virtual bool UpdateUser(int id, string password, string displayName)
public virtual bool UpdateUser(string id, string password, string displayName)
{
bool ret = false;
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
@ -227,7 +227,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(userIds: id == 0 ? new List<int>() : new List<int>() { id });
if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(id) ? new List<string>() : new List<string>() { id });
}
return ret;
}
@ -237,7 +237,7 @@ namespace Bootstrap.DataAccess
/// <param name="id"></param>
/// <param name="approvedBy"></param>
/// <returns></returns>
public virtual bool ApproveUser(int id, string approvedBy)
public virtual bool ApproveUser(string id, string approvedBy)
{
var ret = false;
var sql = "update Users set ApprovedTime = GETDATE(), ApprovedBy = @approvedBy where ID = @id";
@ -246,7 +246,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
if (ret) CacheCleanUtility.ClearCache(userIds: new List<string>() { id });
}
return ret;
}
@ -255,9 +255,8 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="id"></param>
/// <param name="rejectBy"></param>
/// <param name="reason"></param>
/// <returns></returns>
public virtual bool RejectUser(int id, string rejectBy)
public virtual bool RejectUser(string id, string rejectBy)
{
var ret = false;
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RejectUsers"))
@ -266,7 +265,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@rejectedBy", rejectBy));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@rejectedReason", "未填写"));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == -1;
if (ret) CacheCleanUtility.ClearCache(userIds: new List<int>() { id });
if (ret) CacheCleanUtility.ClearCache(userIds: new List<string>() { id });
}
return ret;
}
@ -275,7 +274,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public virtual IEnumerable<User> RetrieveUsersByRoleId(int roleId)
public virtual IEnumerable<User> RetrieveUsersByRoleId(string roleId)
{
List<User> users = new List<User>();
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @RoleID where u.ApprovedTime is not null";
@ -287,7 +286,7 @@ namespace Bootstrap.DataAccess
{
users.Add(new User()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
UserName = (string)reader[1],
DisplayName = (string)reader[2],
Checked = (string)reader[3]
@ -302,7 +301,7 @@ namespace Bootstrap.DataAccess
/// <param name="roleId">角色ID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public virtual bool SaveUsersByRoleId(int roleId, IEnumerable<int> userIds)
public virtual bool SaveUsersByRoleId(string roleId, IEnumerable<string> userIds)
{
bool ret = false;
DataTable dt = new DataTable();
@ -328,7 +327,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction();
}
}
CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<int>() { roleId });
CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<string>() { roleId });
ret = true;
}
catch (Exception ex)
@ -344,7 +343,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public virtual IEnumerable<User> RetrieveUsersByGroupId(int groupId)
public virtual IEnumerable<User> RetrieveUsersByGroupId(string groupId)
{
List<User> users = new List<User>();
string sql = "select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end [status] from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID =@groupId where u.ApprovedTime is not null";
@ -356,7 +355,7 @@ namespace Bootstrap.DataAccess
{
users.Add(new User()
{
Id = LgbConvert.ReadValue(reader[0], 0),
Id = reader[0].ToString(),
UserName = (string)reader[1],
DisplayName = (string)reader[2],
Checked = (string)reader[3]
@ -371,7 +370,7 @@ namespace Bootstrap.DataAccess
/// <param name="groupId">GroupID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public virtual bool SaveUsersByGroupId(int groupId, IEnumerable<int> userIds)
public virtual bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
{
bool ret = false;
DataTable dt = new DataTable();
@ -398,7 +397,7 @@ namespace Bootstrap.DataAccess
transaction.CommitTransaction();
}
}
CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<int>() { groupId });
CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<string>() { groupId });
ret = true;
}
catch (Exception ex)

View File

@ -41,6 +41,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLite", "SQLite", "{523515
DatabaseScripts\SQLite\Install.sql = DatabaseScripts\SQLite\Install.sql
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.DataAccess.MongoDB", "Bootstrap.DataAccess.MongoDB\Bootstrap.DataAccess.MongoDB.csproj", "{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -67,6 +69,10 @@ Global
{BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Release|Any CPU.Build.0 = Release|Any CPU
{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8336F096-4B4A-4710-A1FA-0F5E44CD8D26}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE