合并分支:合并dev-Peta分支功能,数据库操作整合到PetaPoco框架上,依赖Longbow.Data/Bootstrap.Security.DataAccess组件升级

This commit is contained in:
Argo-Surface 2019-01-11 23:20:28 +08:00
parent fd1ddd6097
commit 034fedfddb
93 changed files with 1366 additions and 2860 deletions

View File

@ -14,8 +14,8 @@
<ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.0" />
<PackageReference Include="Longbow.Logging" Version="2.2.1" />
<PackageReference Include="Longbow.Web" Version="2.2.0" />
<PackageReference Include="Longbow.Logging" Version="2.2.4" />
<PackageReference Include="Longbow.Web" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="2.3.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.0" PrivateAssets="All" />

View File

@ -32,7 +32,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpPost]
public bool Post([FromBody]BootstrapDict value)
{
return DictHelper.SaveDict(value);
return DictHelper.Save(value);
}
/// <summary>
///
@ -42,7 +42,7 @@ namespace Bootstrap.Admin.Controllers.Api
[Authorize(Roles = "Administrators")]
public bool Delete([FromBody]IEnumerable<string> value)
{
return DictHelper.DeleteDict(value);
return DictHelper.Delete(value);
}
}
}

View File

@ -24,8 +24,9 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpGet]
public QueryData<object> Get([FromQuery]QueryExceptionOption value)
{
return value.RetrieveData();
return value.Retrieves();
}
/// <summary>
///
/// </summary>
@ -39,6 +40,7 @@ namespace Bootstrap.Admin.Controllers.Api
.Where(f => Path.GetExtension(f).Equals(".log", StringComparison.OrdinalIgnoreCase))
.Select(f => Path.GetFileNameWithoutExtension(f)).OrderByDescending(s => s);
}
/// <summary>
///
/// </summary>
@ -67,6 +69,7 @@ namespace Bootstrap.Admin.Controllers.Api
}
return new JsonResult(sb.ToString());
}
/// <summary>
///
/// </summary>

View File

@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpGet("{id}")]
public Group Get(string id)
{
return GroupHelper.RetrieveGroups().FirstOrDefault(t => t.Id == id);
return GroupHelper.Retrieves().FirstOrDefault(t => t.Id == id);
}
/// <summary>
@ -43,7 +43,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpPost]
public bool Post([FromBody]Group value)
{
return GroupHelper.SaveGroup(value);
return GroupHelper.Save(value);
}
/// <summary>
@ -53,7 +53,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpDelete]
public bool Delete([FromBody]IEnumerable<string> value)
{
return GroupHelper.DeleteGroup(value);
return GroupHelper.Delete(value);
}
/// <summary>
@ -69,10 +69,10 @@ namespace Bootstrap.Admin.Controllers.Api
switch (type)
{
case "user":
ret = GroupHelper.RetrieveGroupsByUserId(id);
ret = GroupHelper.RetrievesByUserId(id);
break;
case "role":
ret = GroupHelper.RetrieveGroupsByRoleId(id);
ret = GroupHelper.RetrievesByRoleId(id);
break;
default:
break;
@ -94,10 +94,10 @@ namespace Bootstrap.Admin.Controllers.Api
switch (type)
{
case "user":
ret = GroupHelper.SaveGroupsByUserId(id, groupIds);
ret = GroupHelper.SaveByUserId(id, groupIds);
break;
case "role":
ret = GroupHelper.SaveGroupsByRoleId(id, groupIds);
ret = GroupHelper.SaveByRoleId(id, groupIds);
break;
default:
break;

View File

@ -31,7 +31,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpGet("{id}")]
public Log Get(string id)
{
return LogHelper.RetrieveLogs().FirstOrDefault(t => t.Id == id);
return LogHelper.Retrieves().FirstOrDefault(t => t.Id == id);
}
/// <summary>
///
@ -44,7 +44,7 @@ namespace Bootstrap.Admin.Controllers.Api
value.ClientAgent = Request.Headers["User-Agent"];
value.ClientIp = HttpContext.Connection.RemoteIpAddress.ToString();
value.UserName = User.Identity.Name;
return LogHelper.SaveLog(value);
return LogHelper.Save(value);
}
}
}

View File

@ -32,7 +32,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpPost]
public bool Post([FromBody]BootstrapMenu value)
{
return MenuHelper.SaveMenu(value);
return MenuHelper.Save(value);
}
/// <summary>
@ -42,7 +42,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpDelete]
public bool Delete([FromBody]IEnumerable<string> value)
{
return MenuHelper.DeleteMenu(value);
return MenuHelper.Delete(value);
}
/// <summary>

View File

@ -38,11 +38,11 @@ namespace Bootstrap.Admin.Controllers
var ret = false;
if (value.UserStatus == UserStates.ApproveUser)
{
ret = UserHelper.ApproveUser(value.Id, User.Identity.Name);
ret = UserHelper.Approve(value.Id, User.Identity.Name);
}
else if (value.UserStatus == UserStates.RejectUser)
{
ret = UserHelper.RejectUser(value.Id, User.Identity.Name);
ret = UserHelper.Reject(value.Id, User.Identity.Name);
}
return ret;
}

View File

@ -36,18 +36,18 @@ namespace Bootstrap.Admin.Controllers.Api
});
// Tasks
var task = TaskHelper.RetrieveTasks();
var task = TaskHelper.Retrieves();
var tasksCount = task.Count();
//Message
var message = MessageHelper.RetrieveMessagesHeader(User.Identity.Name);
var message = MessageHelper.Retrieves(User.Identity.Name);
var messagesCount = message.Count();
message = message.Take(6);
message.AsParallel().ForAll(m => m.FromIcon = Url.Content(m.FromIcon));
//Apps
var apps = ExceptionsHelper.RetrieveExceptions().Where(n => n.ExceptionType != "Longbow.Data.DBAccessException");
var apps = ExceptionsHelper.Retrieves().Where(n => n.ExceptionType != "Longbow.Data.DBAccessException");
var appExceptionsCount = apps.Count();
apps = apps.Take(6);
@ -62,7 +62,7 @@ namespace Bootstrap.Admin.Controllers.Api
});
//Dbs
var dbs = ExceptionsHelper.RetrieveExceptions().Where(n => n.ExceptionType == "Longbow.Data.DBAccessException");
var dbs = ExceptionsHelper.Retrieves().Where(n => n.ExceptionType == "Longbow.Data.DBAccessException");
var dbExceptionsCount = dbs.Count();
dbs = dbs.Take(6);

View File

@ -33,7 +33,7 @@ namespace Bootstrap.Admin.Controllers.Api
if (files.Files.Count > 0)
{
var uploadFile = files.Files[0];
var webSiteUrl = DictHelper.RetrieveIconFolderPath().Code;
var webSiteUrl = DictHelper.RetrieveIconFolderPath();
fileName = string.Format("{0}{1}", userName, Path.GetExtension(uploadFile.FileName));
var fileUrl = string.Format("{0}{1}", webSiteUrl, fileName);
var filePath = Path.Combine(env.WebRootPath, webSiteUrl.Replace("~", string.Empty).Replace("/", "\\").TrimStart('\\') + fileName);

View File

@ -3,7 +3,6 @@ using Longbow.Web.SignalR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Linq;
using System.Threading.Tasks;
@ -36,7 +35,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpPost]
public async Task<bool> Post([FromServices]IHubContext<SignalRHub> hub, [FromBody]User user)
{
var ret = UserHelper.SaveUser(user);
var ret = UserHelper.Save(user);
if (ret) await SignalRManager.Send(hub.Clients.All, new MessageBody() { Category = "Users", Message = string.Format("{0}-{1}", user.UserName, user.Description) });
return ret;
}

View File

@ -38,13 +38,13 @@ namespace Bootstrap.Admin.Controllers.Api
switch (type)
{
case "user":
ret = RoleHelper.RetrieveRolesByUserId(id);
ret = RoleHelper.RetrievesByUserId(id);
break;
case "group":
ret = RoleHelper.RetrieveRolesByGroupId(id);
ret = RoleHelper.RetrievesByGroupId(id);
break;
case "menu":
ret = RoleHelper.RetrieveRolesByMenuId(id);
ret = RoleHelper.RetrievesByMenuId(id);
break;
default:
break;
@ -65,13 +65,13 @@ namespace Bootstrap.Admin.Controllers.Api
switch (type)
{
case "user":
ret = RoleHelper.SaveRolesByUserId(id, roleIds);
ret = RoleHelper.SaveByUserId(id, roleIds);
break;
case "group":
ret = RoleHelper.SaveRolesByGroupId(id, roleIds);
ret = RoleHelper.SaveByGroupId(id, roleIds);
break;
case "menu":
ret = RoleHelper.SavaRolesByMenuId(id, roleIds);
ret = RoleHelper.SavaByMenuId(id, roleIds);
break;
default:
break;
@ -85,7 +85,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpPost]
public bool Post([FromBody]Role value)
{
return RoleHelper.SaveRole(value);
return RoleHelper.Save(value);
}
/// <summary>
///
@ -94,7 +94,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpDelete]
public bool Delete([FromBody]IEnumerable<string> value)
{
return RoleHelper.DeleteRole(value);
return RoleHelper.Delete(value);
}
}
}

View File

@ -18,7 +18,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpGet]
public IEnumerable<Task> Get()
{
return TaskHelper.RetrieveTasks();
return TaskHelper.Retrieves();
}
}
}

View File

@ -61,7 +61,7 @@ namespace Bootstrap.Admin.Controllers.Api
switch (type)
{
case "role":
return UserHelper.RetrieveUsersByRoleId(id).Select(p => new
return UserHelper.RetrievesByRoleId(id).Select(p => new
{
p.Id,
p.DisplayName,
@ -69,7 +69,7 @@ namespace Bootstrap.Admin.Controllers.Api
p.Checked
});
case "group":
return UserHelper.RetrieveUsersByGroupId(id).ToList();
return UserHelper.RetrievesByGroupId(id).ToList();
default:
return null;
}
@ -87,11 +87,11 @@ namespace Bootstrap.Admin.Controllers.Api
value.Description = string.Format("管理员{0}创建用户", User.Identity.Name);
value.ApprovedBy = User.Identity.Name;
value.ApprovedTime = DateTime.Now;
ret = UserHelper.SaveUser(value);
ret = UserHelper.Save(value);
}
else
{
ret = UserHelper.UpdateUser(value.Id, value.Password, value.DisplayName);
ret = UserHelper.Update(value.Id, value.Password, value.DisplayName);
}
return ret;
}
@ -109,10 +109,10 @@ namespace Bootstrap.Admin.Controllers.Api
switch (type)
{
case "role":
ret = UserHelper.SaveUsersByRoleId(id, userIds);
ret = UserHelper.SaveByRoleId(id, userIds);
break;
case "group":
ret = UserHelper.SaveUsersByGroupId(id, userIds);
ret = UserHelper.SaveByGroupId(id, userIds);
break;
default:
break;
@ -126,7 +126,7 @@ namespace Bootstrap.Admin.Controllers.Api
[HttpDelete]
public bool Delete([FromBody]IEnumerable<string> value)
{
return UserHelper.DeleteUser(value);
return UserHelper.Delete(value);
}
/// <summary>
///

View File

@ -1,4 +1,5 @@
using Bootstrap.DataAccess;
using System.IO;
using System.Security.Principal;
namespace Bootstrap.Admin.Models
@ -15,7 +16,7 @@ namespace Bootstrap.Admin.Models
public HeaderBarModel(IIdentity identity)
{
var user = UserHelper.RetrieveUserByUserName(identity.Name);
Icon = user.Icon;
Icon = Path.Combine(DictHelper.RetrieveIconFolderPath(), string.IsNullOrEmpty(user.Icon) ? DictHelper.RetrieveDefaultIcon() : user.Icon);
DisplayName = user.DisplayName;
UserName = user.UserName;
if (!string.IsNullOrEmpty(user.Css)) Theme = user.Css;

View File

@ -22,37 +22,12 @@ namespace Bootstrap.Admin.Query
///
/// </summary>
/// <returns></returns>
public QueryData<object> RetrieveData()
public QueryData<object> Retrieves()
{
var data = ExceptionsHelper.RetrieveExceptions();
if (StartTime > DateTime.MinValue)
{
data = data.Where(t => t.LogTime > StartTime.Value);
}
if (EndTime > DateTime.MinValue)
{
data = data.Where(t => t.LogTime < EndTime.Value.AddDays(1));
}
var data = ExceptionsHelper.RetrievePages(this, StartTime, EndTime);
var ret = new QueryData<object>();
ret.total = data.Count();
switch (Sort)
{
case "ErrorPage":
data = Order == "asc" ? data.OrderBy(t => t.ErrorPage) : data.OrderByDescending(t => t.ErrorPage);
break;
case "UserID":
data = Order == "asc" ? data.OrderBy(t => t.UserId) : data.OrderByDescending(t => t.UserId);
break;
case "UserIp":
data = Order == "asc" ? data.OrderBy(t => t.UserIp) : data.OrderByDescending(t => t.UserIp);
break;
case "LogTime":
data = Order == "asc" ? data.OrderBy(t => t.LogTime) : data.OrderByDescending(t => t.LogTime);
break;
default:
break;
}
ret.rows = data.Skip(Offset).Take(Limit).Select(ex => new { ex.UserId, ex.UserIp, ex.LogTime, ex.Message, ex.ErrorPage, ex.ExceptionType });
ret.total = (int)data.TotalItems;
ret.rows = data.Items.Select(ex => new { ex.UserId, ex.UserIp, ex.LogTime, ex.Message, ex.ErrorPage, ex.ExceptionType });
return ret;
}
}

View File

@ -24,7 +24,7 @@ namespace Bootstrap.Admin.Query
public QueryData<object> RetrieveData()
{
// int limit, int offset, string name, string price, string sort, string order
var data = GroupHelper.RetrieveGroups();
var data = GroupHelper.Retrieves();
if (!string.IsNullOrEmpty(GroupName))
{
data = data.Where(t => t.GroupName.Contains(GroupName));

View File

@ -28,7 +28,7 @@ namespace Bootstrap.Admin.Query
/// <returns></returns>
public QueryData<Log> RetrieveData()
{
var data = LogHelper.RetrieveLogs();
var data = LogHelper.Retrieves();
if (!string.IsNullOrEmpty(OperateType))
{
data = data.Where(t => t.CRUD.ToString().Contains(OperateType));

View File

@ -71,8 +71,8 @@ namespace Bootstrap.Admin.Query
case "IsResource":
data = Order == "asc" ? data.OrderBy(t => t.IsResource) : data.OrderByDescending(t => t.IsResource);
break;
case "ApplicationCode":
data = Order == "asc" ? data.OrderBy(t => t.ApplicationCode) : data.OrderByDescending(t => t.ApplicationCode);
case "Application":
data = Order == "asc" ? data.OrderBy(t => t.Application) : data.OrderByDescending(t => t.Application);
break;
default:
break;
@ -90,7 +90,7 @@ namespace Bootstrap.Admin.Query
p.CategoryName,
p.Target,
p.IsResource,
p.ApplicationCode
p.Application
});
return ret;
}

View File

@ -24,7 +24,7 @@ namespace Bootstrap.Admin.Query
public QueryData<object> RetrieveData()
{
// int limit, int offset, string name, string price, string sort, string order
var data = RoleHelper.RetrieveRoles();
var data = RoleHelper.Retrieves();
if (!string.IsNullOrEmpty(RoleName))
{
data = data.Where(t => t.RoleName.Contains(RoleName));

View File

@ -24,7 +24,7 @@ namespace Bootstrap.Admin.Query
public QueryData<object> RetrieveData()
{
// int limit, int offset, string name, string price, string sort, string order
var data = UserHelper.RetrieveUsers();
var data = UserHelper.Retrieves();
if (!string.IsNullOrEmpty(Name))
{
data = data.Where(t => t.UserName.Contains(Name));

View File

@ -56,7 +56,7 @@ namespace Bootstrap.Admin
services.AddLogging(builder => builder.AddFileLogger().AddDBLogger(ExceptionsHelper.Log));
services.AddConfigurationManager(Configuration);
services.AddCacheManager(Configuration);
services.AddDbAdapter(Configuration);
services.AddDbAdapter();
var dataProtectionBuilder = services.AddDataProtection(op => op.ApplicationDiscriminator = Configuration["ApplicationDiscriminator"])
.SetApplicationName(Configuration["ApplicationName"])
.PersistKeysToFileSystem(new DirectoryInfo(Configuration["KeyPath"]));

View File

@ -37,7 +37,7 @@
Category: "#category",
Target: "#target",
IsResource: "#isRes",
ApplicationCode: "#app"
Application: "#app"
},
events: {
'#btn_assignRole': function (row) {
@ -120,7 +120,7 @@
}
},
{
title: "所属应用", field: "ApplicationCode", sortable: true, formatter: function (value, row, index) {
title: "所属应用", field: "Application", sortable: true, formatter: function (value, row, index) {
return $('#app').next().find('[data-val="' + value + '"]:first').text();
}
}

View File

@ -21,7 +21,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public override bool DeleteDict(IEnumerable<string> value)
public override bool Delete(IEnumerable<string> value)
{
var list = new List<WriteModel<BootstrapDict>>();
foreach (var id in value)
@ -37,7 +37,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool SaveDict(BootstrapDict p)
public override bool Save(BootstrapDict p)
{
if (p.Id == "0")
{

View File

@ -22,7 +22,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Exceptions> RetrieveExceptions()
public override IEnumerable<DataAccess.Exceptions> Retrieves()
{
return MongoDbAccessManager.Exceptions.Find(ex => ex.LogTime >= DateTime.Now.AddDays(-7)).ToList();
}

View File

@ -18,7 +18,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Group> RetrieveGroups()
public override IEnumerable<DataAccess.Group> Retrieves()
{
return MongoDbAccessManager.Groups.Find(FilterDefinition<Group>.Empty).ToList();
}
@ -28,7 +28,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool SaveGroup(DataAccess.Group p)
public override bool Save(DataAccess.Group p)
{
if (p.Id == "0")
{
@ -52,7 +52,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public override bool DeleteGroup(IEnumerable<string> value)
public override bool Delete(IEnumerable<string> value)
{
var list = new List<WriteModel<Group>>();
foreach (var id in value)
@ -68,10 +68,10 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Group> RetrieveGroupsByUserId(string userId)
public override IEnumerable<DataAccess.Group> RetrievesByUserId(string userId)
{
var groups = GroupHelper.RetrieveGroups();
var user = UserHelper.RetrieveUsers().Cast<User>().FirstOrDefault(u => u.Id == userId);
var groups = GroupHelper.Retrieves();
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.Id == userId);
groups.ToList().ForEach(g => g.Checked = user.Groups.Any(id => id == g.Id) ? "checked" : "");
return groups;
}
@ -82,7 +82,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
public override bool SaveByUserId(string userId, IEnumerable<string> groupIds)
{
MongoDbAccessManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders<User>.Update.Set(u => u.Groups, groupIds));
return true;
@ -93,9 +93,9 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Group> RetrieveGroupsByRoleId(string roleId)
public override IEnumerable<DataAccess.Group> RetrievesByRoleId(string roleId)
{
var groups = GroupHelper.RetrieveGroups().Cast<Group>().ToList();
var groups = GroupHelper.Retrieves().Cast<Group>().ToList();
groups.ForEach(p => p.Checked = (p.Roles != null && p.Roles.Contains(roleId)) ? "checked" : "");
return groups;
}
@ -106,7 +106,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
public override bool SaveByRoleId(string roleId, IEnumerable<string> groupIds)
{
var groups = MongoDbAccessManager.Groups.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList();
@ -134,11 +134,11 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<string> RetrieveGroupsByUserName(string userName)
public override IEnumerable<string> RetrievesByUserName(string userName)
{
var groups = new List<string>();
var user = UserHelper.RetrieveUsers().Cast<User>().FirstOrDefault(u => u.UserName == userName);
var group = GroupHelper.RetrieveGroups();
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName == userName);
var group = GroupHelper.Retrieves();
groups.AddRange(user.Groups.Select(r => group.FirstOrDefault(rl => rl.Id == r).GroupName));
if (groups.Count == 0) groups.Add("Default");

View File

@ -13,7 +13,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Log> RetrieveLogs() => MongoDbAccessManager.Logs.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList();
public override IEnumerable<DataAccess.Log> Retrieves() => MongoDbAccessManager.Logs.Find(l => l.LogTime >= DateTime.Now.AddDays(-7)).ToList();
/// <summary>
/// 删除日志信息
/// </summary>
@ -25,7 +25,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="log"></param>
/// <returns></returns>
public override bool SaveLog(DataAccess.Log log)
public override bool Save(DataAccess.Log log)
{
log.LogTime = DateTime.Now;
MongoDbAccessManager.Logs.InsertOne(log);

View File

@ -33,7 +33,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool SaveMenu(BootstrapMenu p)
public override bool Save(BootstrapMenu p)
{
if (p.Id == "0")
{
@ -51,7 +51,7 @@ namespace Bootstrap.DataAccess.MongoDB
.Set(md => md.Category, p.Category)
.Set(md => md.Target, p.Target)
.Set(md => md.IsResource, p.IsResource)
.Set(md => md.ApplicationCode, p.ApplicationCode);
.Set(md => md.Application, p.Application);
MongoDbAccessManager.Menus.UpdateOne(md => md.Id == p.Id, update);
return true;
}
@ -62,7 +62,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public override bool DeleteMenu(IEnumerable<string> value)
public override bool Delete(IEnumerable<string> value)
{
var list = new List<WriteModel<BootstrapMenu>>();
foreach (var id in value)

View File

@ -13,7 +13,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
protected override IEnumerable<DataAccess.Message> RetrieveMessages(string userName)
protected override IEnumerable<DataAccess.Message> Retrieves(string userName)
{
var msg = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.Message>("Messages");
return msg.Find(message => message.To == userName || message.From == userName).ToList();

View File

@ -1,6 +1,5 @@
using Bootstrap.Security;
using Longbow.Configuration;
using Longbow.Data;
using Microsoft.Extensions.Primitives;
using MongoDB.Bson;
using MongoDB.Bson.Serialization;

View File

@ -19,7 +19,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Role> RetrieveRoles()
public override IEnumerable<DataAccess.Role> Retrieves()
{
return MongoDbAccessManager.Roles.Find(FilterDefinition<Role>.Empty).ToList();
}
@ -29,7 +29,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool SaveRole(DataAccess.Role p)
public override bool Save(DataAccess.Role p)
{
if (p.Id == "0")
{
@ -54,7 +54,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public override bool DeleteRole(IEnumerable<string> value)
public override bool Delete(IEnumerable<string> value)
{
var list = new List<WriteModel<Role>>();
foreach (var id in value)
@ -73,8 +73,8 @@ namespace Bootstrap.DataAccess.MongoDB
public override IEnumerable<string> RetrieveRolesByUserName(string userName)
{
var roles = new List<string>();
var user = UserHelper.RetrieveUsers().Cast<User>().FirstOrDefault(u => u.UserName == userName);
var role = RoleHelper.RetrieveRoles();
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.UserName == userName);
var role = RoleHelper.Retrieves();
roles.AddRange(user.Roles.Select(r => role.FirstOrDefault(rl => rl.Id == r).RoleName));
if (roles.Count == 0) roles.Add("Default");
@ -86,10 +86,10 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Role> RetrieveRolesByUserId(string userId)
public override IEnumerable<DataAccess.Role> RetrievesByUserId(string userId)
{
var roles = RoleHelper.RetrieveRoles();
var user = UserHelper.RetrieveUsers().Cast<User>().FirstOrDefault(u => u.Id == userId);
var roles = RoleHelper.Retrieves();
var user = UserHelper.Retrieves().Cast<User>().FirstOrDefault(u => u.Id == userId);
roles.ToList().ForEach(r => r.Checked = user.Roles.Any(id => id == r.Id) ? "checked" : "");
return roles;
}
@ -100,7 +100,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds)
public override bool SaveByUserId(string userId, IEnumerable<string> roleIds)
{
MongoDbAccessManager.Users.FindOneAndUpdate(u => u.Id == userId, Builders<User>.Update.Set(u => u.Roles, roleIds));
return true;
@ -111,9 +111,9 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Role> RetrieveRolesByMenuId(string menuId)
public override IEnumerable<DataAccess.Role> RetrievesByMenuId(string menuId)
{
var roles = RoleHelper.RetrieveRoles().Cast<Role>().ToList();
var roles = RoleHelper.Retrieves().Cast<Role>().ToList();
roles.ForEach(r => r.Checked = (r.Menus != null && r.Menus.Contains(menuId)) ? "checked" : "");
roles.ForEach(r => r.Menus = null);
return roles;
@ -125,7 +125,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <param name="menuId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SavaRolesByMenuId(string menuId, IEnumerable<string> roleIds)
public override bool SavaByMenuId(string menuId, IEnumerable<string> roleIds)
{
var roles = MongoDbAccessManager.Roles.Find(md => md.Menus != null && md.Menus.Contains(menuId)).ToList();
@ -155,10 +155,10 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.Role> RetrieveRolesByGroupId(string groupId)
public override IEnumerable<DataAccess.Role> RetrievesByGroupId(string groupId)
{
var roles = RoleHelper.RetrieveRoles();
var group = GroupHelper.RetrieveGroups().Cast<Group>().FirstOrDefault(u => u.Id == groupId);
var roles = RoleHelper.Retrieves();
var group = GroupHelper.Retrieves().Cast<Group>().FirstOrDefault(u => u.Id == groupId);
roles.ToList().ForEach(r => r.Checked = group.Roles.Any(id => id == r.Id) ? "checked" : "");
return roles;
}
@ -169,7 +169,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <param name="groupId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
public override bool SaveByGroupId(string groupId, IEnumerable<string> roleIds)
{
MongoDbAccessManager.Groups.FindOneAndUpdate(u => u.Id == groupId, Builders<Group>.Update.Set(u => u.Roles, roleIds));
return true;
@ -183,7 +183,7 @@ namespace Bootstrap.DataAccess.MongoDB
public override IEnumerable<string> RetrieveRolesByUrl(string url)
{
var menu = MongoDbAccessManager.Menus.Find(md => md.Url.StartsWith(url)).FirstOrDefault();
var ret = RoleHelper.RetrieveRoles().Cast<Role>().Where(md => md.Menus != null && md.Menus.Contains(menu.Id)).Select(m => m.RoleName).ToList();
var ret = RoleHelper.Retrieves().Cast<Role>().Where(md => md.Menus != null && md.Menus.Contains(menu.Id)).Select(m => m.RoleName).ToList();
if (!ret.Contains("Administrators")) ret.Add("Administrators");
return ret;
}

View File

@ -12,7 +12,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Task> RetrieveTasks()
public override IEnumerable<DataAccess.Task> Retrieves()
{
var users = MongoDbAccessManager.DBAccess.GetCollection<DataAccess.Task>("Tasks");
return users.Find(FilterDefinition<DataAccess.Task>.Empty).SortByDescending(task => task.AssignTime).ToList();

View File

@ -61,7 +61,7 @@ namespace Bootstrap.DataAccess.MongoDB
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.User> RetrieveUsers()
public override IEnumerable<DataAccess.User> Retrieves()
{
var project = Builders<User>.Projection.Include(u => u.Id)
.Include(u => u.UserName)
@ -80,7 +80,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool SaveUser(DataAccess.User user)
public override bool Save(DataAccess.User user)
{
// 已经存在或者已经在新用户中了
if (UserHelper.RetrieveUserByUserName(user.UserName) != null || UserHelper.RetrieveNewUsers().Any(u => u.UserName == user.UserName)) return false;
@ -98,7 +98,7 @@ namespace Bootstrap.DataAccess.MongoDB
ApprovedBy = user.ApprovedBy,
Roles = new List<string>(),
Groups = new List<string>(),
Icon = $"{DictHelper.RetrieveIconFolderPath().Code}default.jpg",
Icon = $"{DictHelper.RetrieveIconFolderPath()}default.jpg",
Description = user.Description
});
return true;
@ -111,7 +111,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <param name="password"></param>
/// <param name="displayName"></param>
/// <returns></returns>
public override bool UpdateUser(string id, string password, string displayName)
public override bool Update(string id, string password, string displayName)
{
var passSalt = LgbCryptography.GenerateSalt();
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
@ -145,7 +145,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public override bool DeleteUser(IEnumerable<string> value)
public override bool Delete(IEnumerable<string> value)
{
var list = new List<WriteModel<User>>();
foreach (var id in value)
@ -161,9 +161,9 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.User> RetrieveUsersByRoleId(string roleId)
public override IEnumerable<DataAccess.User> RetrievesByRoleId(string roleId)
{
var users = UserHelper.RetrieveUsers().Cast<User>().ToList();
var users = UserHelper.Retrieves().Cast<User>().ToList();
users.ForEach(p => p.Checked = (p.Roles != null && p.Roles.Contains(roleId)) ? "checked" : "");
return users;
}
@ -174,7 +174,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <param name="roleId"></param>
/// <param name="userIds"></param>
/// <returns></returns>
public override bool SaveUsersByRoleId(string roleId, IEnumerable<string> userIds)
public override bool SaveByRoleId(string roleId, IEnumerable<string> userIds)
{
var users = MongoDbAccessManager.Users.Find(md => md.Roles != null && md.Roles.Contains(roleId)).ToList();
@ -202,9 +202,9 @@ namespace Bootstrap.DataAccess.MongoDB
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.User> RetrieveUsersByGroupId(string groupId)
public override IEnumerable<DataAccess.User> RetrievesByGroupId(string groupId)
{
var users = UserHelper.RetrieveUsers().Cast<User>().ToList();
var users = UserHelper.Retrieves().Cast<User>().ToList();
users.ForEach(p => p.Checked = (p.Groups != null && p.Groups.Contains(groupId)) ? "checked" : "");
return users;
}
@ -215,7 +215,7 @@ namespace Bootstrap.DataAccess.MongoDB
/// <param name="groupId"></param>
/// <param name="userIds"></param>
/// <returns></returns>
public override bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
public override bool SaveByGroupId(string groupId, IEnumerable<string> userIds)
{
var users = MongoDbAccessManager.Users.Find(md => md.Groups != null && md.Groups.Contains(groupId)).ToList();

View File

@ -1,21 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</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="MySql.Data" Version="8.0.13" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
</ItemGroup>
</Project>

View File

@ -1,10 +0,0 @@
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Dict : DataAccess.Dict
{
}
}

View File

@ -1,10 +0,0 @@
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Exceptions : DataAccess.Exceptions
{
}
}

View File

@ -1,228 +0,0 @@
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Group : DataAccess.Group
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Group> RetrieveGroups()
{
string sql = "select * from `Groups`";
List<Group> groups = new List<Group>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
groups.Add(new Group()
{
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
});
}
}
return groups;
}
/// <summary>
///
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public override bool SaveGroup(DataAccess.Group p)
{
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 = 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))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
}
/// <summary>
/// <summary>
/// 删除群组信息
/// </summary>
/// <param name="ids"></param>
public override bool DeleteGroup(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserGroup where GroupID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from RoleGroup where GroupID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from `Groups` where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.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>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
groups.Add(new Group()
{
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return groups;
}
/// <summary>
/// 保存用户部门关系
/// </summary>
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
{
var ret = false;
//判断用户是否选定角色
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户部门表中该用户所有的部门关系
string sql = $"delete from UserGroup where UserID = {userId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
groupIds.ToList().ForEach(gId =>
{
cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ({userId}, {gId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public override IEnumerable<DataAccess.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";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
groups.Add(new Group()
{
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return groups;
}
/// <summary>
/// 根据角色ID以及选定的部门ID保到角色部门表
/// </summary>
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除角色部门表该角色所有的部门
string sql = $"delete from RoleGroup where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入角色部门表
groupIds.ToList().ForEach(gId =>
{
cmd.CommandText = $"Insert Into RoleGroup (RoleID, GroupID) Values ({roleId}, {gId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -1,10 +0,0 @@
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Log : DataAccess.Log
{
}
}

View File

@ -1,124 +0,0 @@
using Bootstrap.Security;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Menu : DataAccess.Menu
{
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName)
{
var menus = new List<BootstrapMenu>();
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select n.ID, n.ParentId, n.Name, n.Order, n.Icon, n.Url, n.Category, n.Target, n.IsResource, n.Application, d.Name as CategoryName, ln.Name as ParentName from Navigations n inner join Dicts d on n.Category = d.Code and d.Category = @Category and d.Define = 0 left join Navigations ln on n.ParentId = ln.ID inner join (select nr.NavigationID from Users u inner join UserRole ur on ur.UserID = u.ID inner join NavigationRole nr on nr.RoleID = ur.RoleID where u.UserName = @UserName union select nr.NavigationID from Users u inner join UserGroup ug on u.ID = ug.UserID inner join RoleGroup rg on rg.GroupID = ug.GroupID inner join NavigationRole nr on nr.RoleID = rg.RoleID where u.UserName = @UserName union select n.ID from Navigations n where EXISTS (select UserName from Users u inner join UserRole ur on u.ID = ur.UserID inner join Roles r on ur.RoleID = r.ID where u.UserName = @UserName and r.RoleName = @RoleName)) nav on n.ID = nav.NavigationID"))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", "菜单"));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", "Administrators"));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
menus.Add(new BootstrapMenu
{
Id = reader[0].ToString(),
ParentId = reader[1].ToString(),
Name = (string)reader[2],
Order = reader.IsDBNull(3) ? 0 : (int)reader[3],
Icon = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
Url = reader.IsDBNull(5) ? string.Empty : (string)reader[5],
Category = (string)reader[6],
Target = (string)reader[7],
IsResource = reader.IsDBNull(8) ? 0 : (int)reader[8] > 0 ? 1 : 0,
ApplicationCode = reader.IsDBNull(9) ? string.Empty : (string)reader[9],
CategoryName = (string)reader[10],
ParentName = reader.IsDBNull(11) ? string.Empty : (string)reader[11],
});
}
}
}
return menus;
}
/// <summary>
/// Saves the menu.
/// </summary>
/// <returns><c>true</c>, if menu was saved, <c>false</c> otherwise.</returns>
/// <param name="p">P.</param>
public override bool SaveMenu(BootstrapMenu p)
{
if (string.IsNullOrEmpty(p.Name)) return false;
bool ret = false;
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 = 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))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Order", p.Order));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAdapterManager.ToDBValue(p.Icon)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", DbAdapterManager.ToDBValue(p.Url)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", p.Category));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Target", p.Target));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
}
/// <summary>
/// <summary>
/// 通过角色ID保存当前授权菜单
/// </summary>
/// <param name="roleId"></param>
/// <param name="menuIds"></param>
/// <returns></returns>
public override bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除菜单角色表该角色所有的菜单
string sql = $"delete from NavigationRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入菜单角色表
menuIds.ToList().ForEach(mId =>
{
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {mId}, {roleId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -1,50 +0,0 @@
using Longbow;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Message : DataAccess.Message
{
/// <summary>
/// 所有有关userName所有消息列表
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
protected override IEnumerable<DataAccess.Message> RetrieveMessages(string userName)
{
string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from Messages m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.`From` = u.UserName where `To` = @UserName or `From` = @UserName order by m.SendTime desc";
List<DataAccess.Message> messages = new List<DataAccess.Message>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
messages.Add(new DataAccess.Message()
{
Id = reader[0].ToString(),
Title = (string)reader[1],
Content = (string)reader[2],
From = (string)reader[3],
To = (string)reader[4],
SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
Status = (string)reader[6],
Mark = LgbConvert.ReadValue(reader[7], 0),
IsDelete = LgbConvert.ReadValue(reader[8], 0),
Label = (string)reader[9],
LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
FromIcon = (string)reader[11],
FromDisplayName = (string)reader[12]
});
}
}
return messages;
}
}
}

View File

@ -1,174 +0,0 @@
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
///
/// </summary>
public class Role : DataAccess.Role
{
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override IEnumerable<string> RetrieveRolesByUserName(string userName)
{
var entities = new List<string>();
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select r.RoleName from Roles r inner join UserRole ur on r.ID=ur.RoleID inner join Users u on ur.UserID = u.ID and u.UserName = @UserName union select r.RoleName from Roles r inner join RoleGroup rg on r.ID = rg.RoleID inner join `Groups` g on rg.GroupID = g.ID inner join UserGroup ug on ug.GroupID = g.ID inner join Users u on ug.UserID = u.ID and u.UserName=@UserName"))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
entities.Add((string)reader[0]);
}
}
}
return entities;
}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public override IEnumerable<string> RetrieveRolesByUrl(string url)
{
string sql = "select distinct r.RoleName, r.Description from Roles r inner join NavigationRole nr on r.ID = nr.RoleID inner join Navigations n on nr.NavigationID = n.ID and n.Application = '0' and n.Url like @Url";
var ret = new List<string>();
var cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", $"{url}%"));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
ret.Add((string)reader[0]);
}
}
if (ret.Count == 0) ret.Add("Administrators");
return ret;
}
/// <summary>
/// <summary>
/// 保存用户角色关系
/// </summary>
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds)
{
var ret = false;
//判断用户是否选定角色
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete user from config table
string sql = $"delete from UserRole where UserID = {userId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {userId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="menuId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SavaRolesByMenuId(string menuId, IEnumerable<string> roleIds)
{
var ret = false;
//判断用户是否选定角色
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete role from config table
string sql = $"delete from NavigationRole where NavigationID = {menuId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {menuId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 根据GroupId更新Roles信息删除旧的Roles信息插入新的Roles信息
/// </summary>
/// <param name="groupId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
{
var ret = false;
//构造表格
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete user from config table
string sql = $"delete from RoleGroup where GroupID = {groupId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into RoleGroup (GroupID, RoleID) Values ( {groupId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -1,40 +0,0 @@
using Longbow;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess.MySQL
{
public class Task : DataAccess.Task
{
/// <summary>
/// 查询所有任务
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Task> RetrieveTasks()
{
string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000";
List<DataAccess.Task> tasks = new List<DataAccess.Task>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
tasks.Add(new DataAccess.Task()
{
Id = reader[0].ToString(),
TaskName = (string)reader[1],
AssignName = (string)reader[2],
UserName = (string)reader[3],
TaskTime = LgbConvert.ReadValue(reader[4], 0),
TaskProgress = (double)reader[5],
AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue),
AssignDisplayName = (string)reader[7]
});
}
}
return tasks;
}
}
}

View File

@ -1,116 +0,0 @@
using Bootstrap.Security;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.MySQL
{
/// <summary>
/// 用户表实体类
/// </summary>
public class User : DataAccess.User
{
/// <summary>
/// 通过角色ID保存当前授权用户插入
/// </summary>
/// <param name="roleId">角色ID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public override bool SaveUsersByRoleId(string roleId, IEnumerable<string> userIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = $"delete from UserRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
userIds.ToList().ForEach(uId =>
{
cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {uId}, {roleId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 通过部门ID保存当前授权用户插入
/// </summary>
/// <param name="groupId">GroupID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public override bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = $"delete from UserGroup where GroupID = {groupId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
userIds.ToList().ForEach(uId =>
{
cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ( {uId}, {groupId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override BootstrapUser RetrieveUserByUserName(string userName)
{
BootstrapUser user = null;
var sql = "select UserName, DisplayName, CONCAT(case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end, ifnull(Icon, 'default.jpg')) Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName";
var db = DbAccessManager.DBAccess;
var cmd = db.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
using (DbDataReader reader = db.ExecuteReader(cmd))
{
if (reader.Read())
{
user = new BootstrapUser
{
UserName = (string)reader[0],
DisplayName = (string)reader[1],
Icon = (string)reader[2],
Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3]
};
}
}
return user;
}
}
}

View File

@ -1,25 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</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="Longbow.Cache" Version="2.2.0" />
<PackageReference Include="Longbow.Configuration" Version="2.2.1" />
<PackageReference Include="Longbow.Data" Version="2.2.0" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.1.0" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
</ItemGroup>
</Project>

View File

@ -1,10 +0,0 @@
namespace Bootstrap.DataAccess.SQLite
{
/// <summary>
///
/// </summary>
public class Dict : DataAccess.Dict
{
}
}

View File

@ -1,10 +0,0 @@
namespace Bootstrap.DataAccess.SQLite
{
/// <summary>
///
/// </summary>
public class Exceptions : DataAccess.Exceptions
{
}
}

View File

@ -1,90 +0,0 @@
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.SQLite
{
/// <summary>
///
/// </summary>
public class Group : DataAccess.Group
{
/// <summary>
/// 保存用户部门关系
/// </summary>
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
{
var ret = false;
//判断用户是否选定角色
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户部门表中该用户所有的部门关系
string sql = $"delete from UserGroup where UserID = {userId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
groupIds.ToList().ForEach(gId =>
{
cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ({userId}, {gId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 根据角色ID以及选定的部门ID保到角色部门表
/// </summary>
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public override bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除角色部门表该角色所有的部门
string sql = $"delete from RoleGroup where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入角色部门表
groupIds.ToList().ForEach(gId =>
{
cmd.CommandText = $"Insert Into RoleGroup (RoleID, GroupID) Values ({roleId}, {gId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -1,10 +0,0 @@
namespace Bootstrap.DataAccess.SQLite
{
/// <summary>
///
/// </summary>
public class Log : DataAccess.Log
{
}
}

View File

@ -1,53 +0,0 @@
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.SQLite
{
/// <summary>
///
/// </summary>
public class Menu : DataAccess.Menu
{
/// <summary>
/// <summary>
/// 通过角色ID保存当前授权菜单
/// </summary>
/// <param name="roleId"></param>
/// <param name="menuIds"></param>
/// <returns></returns>
public override bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除菜单角色表该角色所有的菜单
string sql = $"delete from NavigationRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入菜单角色表
menuIds.ToList().ForEach(mId =>
{
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ({mId}, {roleId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -1,50 +0,0 @@
using Longbow;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess.SQLite
{
/// <summary>
///
/// </summary>
public class Message : DataAccess.Message
{
/// <summary>
/// 所有有关userName所有消息列表
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
protected override IEnumerable<DataAccess.Message> RetrieveMessages(string userName)
{
string sql = "select m.*, d.Name, ifnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = '消息标签' and d.Define = 0 left join Dicts i on i.Category = '头像地址' and i.Name = '头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
List<DataAccess.Message> messages = new List<DataAccess.Message>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
messages.Add(new DataAccess.Message()
{
Id = reader[0].ToString(),
Title = (string)reader[1],
Content = (string)reader[2],
From = (string)reader[3],
To = (string)reader[4],
SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
Status = (string)reader[6],
Mark = LgbConvert.ReadValue(reader[7], 0),
IsDelete = LgbConvert.ReadValue(reader[8], 0),
Label = (string)reader[9],
LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
FromIcon = (string)reader[11],
FromDisplayName = (string)reader[12]
});
}
}
return messages;
}
}
}

View File

@ -1,130 +0,0 @@
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.SQLite
{
/// <summary>
///
/// </summary>
public class Role : DataAccess.Role
{
/// <summary>
/// <summary>
/// 保存用户角色关系
/// </summary>
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds)
{
var ret = false;
//判断用户是否选定角色
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete user from config table
string sql = $"delete from UserRole where UserID = {userId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {userId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="menuId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SavaRolesByMenuId(string menuId, IEnumerable<string> roleIds)
{
var ret = false;
//判断用户是否选定角色
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete role from config table
string sql = $"delete from NavigationRole where NavigationID = {menuId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into NavigationRole (NavigationID, RoleID) Values ( {menuId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 根据GroupId更新Roles信息删除旧的Roles信息插入新的Roles信息
/// </summary>
/// <param name="groupId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public override bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
{
var ret = false;
//构造表格
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
// delete user from config table
string sql = $"delete from RoleGroup where GroupID = {groupId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
roleIds.ToList().ForEach(rId =>
{
cmd.CommandText = $"Insert Into RoleGroup (GroupID, RoleID) Values ( {groupId}, {rId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
}
}

View File

@ -1,40 +0,0 @@
using Longbow;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess.SQLite
{
public class Task : DataAccess.Task
{
/// <summary>
/// 查询所有任务
/// </summary>
/// <returns></returns>
public override IEnumerable<DataAccess.Task> RetrieveTasks()
{
string sql = "select t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc limit 1000";
List<DataAccess.Task> tasks = new List<DataAccess.Task>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
tasks.Add(new DataAccess.Task()
{
Id = reader[0].ToString(),
TaskName = (string)reader[1],
AssignName = (string)reader[2],
UserName = (string)reader[3],
TaskTime = LgbConvert.ReadValue(reader[4], 0),
TaskProgress = (double)reader[5],
AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue),
AssignDisplayName = (string)reader[7]
});
}
}
return tasks;
}
}
}

View File

@ -1,116 +0,0 @@
using Bootstrap.Security;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.SQLite
{
/// <summary>
/// 用户表实体类
/// </summary>
public class User : DataAccess.User
{
/// <summary>
/// 通过角色ID保存当前授权用户插入
/// </summary>
/// <param name="roleId">角色ID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public override bool SaveUsersByRoleId(string roleId, IEnumerable<string> userIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = $"delete from UserRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
userIds.ToList().ForEach(uId =>
{
cmd.CommandText = $"Insert Into UserRole (UserID, RoleID) Values ( {uId}, {roleId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
/// 通过部门ID保存当前授权用户插入
/// </summary>
/// <param name="groupId">GroupID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public override bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
{
bool ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
{
try
{
//删除用户角色表该角色所有的用户
string sql = $"delete from UserGroup where GroupID = {groupId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
userIds.ToList().ForEach(uId =>
{
cmd.CommandText = $"Insert Into UserGroup (UserID, GroupID) Values ( {uId}, {groupId})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
});
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public override BootstrapUser RetrieveUserByUserName(string userName)
{
BootstrapUser user = null;
var sql = "select UserName, DisplayName, case ifnull(d.Code, '') when '' then '~/images/uploader/' else d.Code end || ifnull(Icon, 'default.jpg') Icon, u.Css from Users u left join Dicts d on d.Define = '0' and d.Category = '头像地址' and Name = '头像路径' where ApprovedTime is not null and UserName = @UserName";
var db = DbAccessManager.DBAccess;
var cmd = db.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
using (DbDataReader reader = db.ExecuteReader(cmd))
{
if (reader.Read())
{
user = new BootstrapUser
{
UserName = (string)reader[0],
DisplayName = (string)reader[1],
Icon = (string)reader[2],
Css = reader.IsDBNull(3) ? string.Empty : (string)reader[3]
};
}
}
return user;
}
}
}

View File

@ -11,11 +11,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="1.1.0" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.1.0" />
<PackageReference Include="Longbow.Web" Version="2.2.0" />
<PackageReference Include="Longbow.Cache" Version="2.2.0" />
<PackageReference Include="Longbow" Version="2.2.1" />
<PackageReference Include="Bootstrap.Security.DataAccess" Version="1.1.1" />
<PackageReference Include="Longbow.Data" Version="2.2.2" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.2.0" />
<PackageReference Include="Longbow.Web" Version="2.2.2" />
<PackageReference Include="Longbow.Cache" Version="2.2.1" />
<PackageReference Include="Longbow" Version="2.2.3" />
<PackageReference Include="PetaPoco.Compiled" Version="1.0.1" />
</ItemGroup>
</Project>

View File

@ -1,18 +0,0 @@
using Longbow.Data;
namespace Bootstrap.DataAccess
{
/// <summary>
///
/// </summary>
public static class DbAccessManager
{
/// <summary>
///
/// </summary>
public static IDbAccess DBAccess
{
get { return DbAdapterManager.CreateDB("ba"); }
}
}
}

View File

@ -0,0 +1,39 @@
using PetaPoco;
namespace Bootstrap.DataAccess
{
/// <summary>
///
/// </summary>
public static class DbManager
{
/// <summary>
///
/// </summary>
public static IDatabase Db { get { return Create(); } }
/// <summary>
///
/// </summary>
/// <param name="connectionName"></param>
/// <returns></returns>
public static IDatabase Create(string connectionName = null, bool keepAlive = false)
{
var db = Longbow.Data.DbManager.Create(connectionName, keepAlive);
return db.AddMaps();
}
private static IDatabase AddMaps(this IDatabase database)
{
database.AddMap<Dict>("Dicts");
database.AddMap<User>("Users", new string[] { "Checked", "Period", "NewPassword", "UserStatus" });
database.AddMap<Exceptions>("Exceptions", new string[] { "Period" });
database.AddMap<Group>("Groups", new string[] { "Checked" });
database.AddMap<Log>("Logs");
database.AddMap<Menu>("Navigations", new string[] { "ParentName", "CategoryName", "Active", "Menus" });
database.AddMap<Role>("Roles", new string[] { "Checked" });
database.AddMap<Task>("Tasks");
return database;
}
}
}

View File

@ -2,8 +2,6 @@
using Bootstrap.Security.DataAccess;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess
@ -18,42 +16,29 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="value">需要删除的IDs</param>
/// <returns></returns>
public virtual bool DeleteDict(IEnumerable<string> value)
public virtual bool Delete(IEnumerable<string> value)
{
var ret = false;
var ids = string.Join(",", value);
string sql = $"Delete from Dicts where ID in ({ids})";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == value.Count();
}
return ret;
string sql = $"where ID in ({ids})";
DbManager.Db.Delete<BootstrapDict>(sql);
return true;
}
/// <summary>
/// 保存新建/更新的字典信息
/// </summary>
/// <param name="dict"></param>
/// <returns></returns>
public virtual bool SaveDict(BootstrapDict dict)
public virtual bool Save(BootstrapDict dict)
{
bool ret = false;
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 = 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))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", dict.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Define", dict.Define));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
DbManager.Db.Save(dict);
return true;
}
/// <summary>
/// 保存网站个性化设置
/// </summary>
@ -63,37 +48,34 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public virtual bool SaveSettings(BootstrapDict dict)
{
var ret = false;
string sql = "Update Dicts set Code = @Code where Category = @Category and Name = @Name";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", dict.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Code", dict.Code));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", dict.Category));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
DbManager.Db.Update<BootstrapDict>("set Code = @Code where Category = @Category and Name = @Name", dict);
return true;
}
/// <summary>
/// 获取字典分类名称
/// </summary>
/// <returns></returns>
public virtual IEnumerable<string> RetrieveCategories() => DictHelper.RetrieveDicts().Select(d => d.Category).Distinct();
/// <summary>
///
/// </summary>
/// <returns></returns>
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() => (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() => DictHelper.RetrieveDicts().Where(d => d.Category == "网站样式");
/// <summary>
/// 获得网站设置中的当前样式
/// </summary>
@ -103,21 +85,27 @@ namespace Bootstrap.DataAccess
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() => DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" };
public virtual string RetrieveIconFolderPath() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/images/uploader/" }).Code;
/// <summary>
/// 获得默认的前台首页地址,默认为~/Home/Index
/// </summary>
/// <returns></returns>
public virtual string RetrieveHomeUrl() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
public virtual string RetrieveDefaultIcon() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "头像文件" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "default.jpg" }).Code;
/// <summary>
///
/// </summary>
/// <returns></returns>
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

@ -1,11 +1,10 @@
using Longbow;
using Longbow.Configuration;
using Longbow.Data;
using Longbow.Web.Mvc;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess
{
@ -18,53 +17,57 @@ namespace Bootstrap.DataAccess
///
/// </summary>
public string Id { get; set; }
/// <summary>
///
/// </summary>
public string AppDomainName { get; set; }
/// <summary>
///
/// </summary>
public string ErrorPage { get; set; }
/// <summary>
///
/// </summary>
public string UserId { get; set; }
/// <summary>
///
/// </summary>
public string UserIp { get; set; }
/// <summary>
///
/// </summary>
public string Message { get; set; }
/// <summary>
///
/// </summary>
public string StackTrace { get; set; }
/// <summary>
///
/// </summary>
public DateTime LogTime { get; set; }
/// <summary>
///
/// </summary>
public string ExceptionType { get; set; }
/// <summary>
///
/// </summary>
public string Message { get; set; }
/// <summary>
///
/// </summary>
public string StackTrace { get; set; }
/// <summary>
///
/// </summary>
public DateTime LogTime { get; set; }
/// <summary>
/// 获得/设置 时间描述 2分钟内为刚刚
/// </summary>
public string Period { get; set; }
private static void ClearExceptions()
private static void ClearExceptions() => System.Threading.Tasks.Task.Run(() =>
{
System.Threading.Tasks.Task.Run(() =>
{
string sql = $"delete from Exceptions where LogTime < @LogTime";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepExceptionsPeriod"], 1)), DbType.DateTime));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
});
}
DbManager.Db.Execute("delete from Exceptions where LogTime < @0", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepExceptionsPeriod"], 1)));
});
/// <summary>
///
/// </summary>
@ -73,62 +76,47 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public virtual bool Log(Exception ex, NameValueCollection additionalInfo)
{
if (ex == null) return true;
if (additionalInfo == null)
if (ex == null) throw new ArgumentNullException(nameof(ex));
var errorPage = additionalInfo?["ErrorPage"] ?? (ex.GetType().Name.Length > 50 ? ex.GetType().Name.Substring(0, 50) : ex.GetType().Name);
DbManager.Db.Insert(new Exceptions()
{
additionalInfo = new NameValueCollection
{
["UserId"] = null,
["UserIp"] = null,
["ErrorPage"] = null
};
}
var errorPage = additionalInfo["ErrorPage"] ?? (ex.GetType().Name.Length > 50 ? ex.GetType().Name.Substring(0, 50) : ex.GetType().Name);
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, @LogTime)";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ErrorPage", errorPage));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", DbAdapterManager.ToDBValue(additionalInfo["UserId"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserIp", DbAdapterManager.ToDBValue(additionalInfo["UserIp"])));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Message", ex.Message));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@StackTrace", DbAdapterManager.ToDBValue(ex.StackTrace)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now, DbType.DateTime));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
ClearExceptions();
}
AppDomainName = AppDomain.CurrentDomain.FriendlyName,
ErrorPage = errorPage,
UserId = additionalInfo?["UserId"],
UserIp = additionalInfo?["UserIp"],
ExceptionType = ex.GetType().FullName,
Message = ex.Message,
StackTrace = ex.StackTrace,
LogTime = DateTime.Now
});
ClearExceptions();
return true;
}
/// <summary>
/// 查询一周内所有异常
/// </summary>
/// <returns></returns>
public virtual IEnumerable<Exceptions> RetrieveExceptions()
public virtual IEnumerable<Exceptions> Retrieves() => DbManager.Db.Fetch<Exceptions>("select * from Exceptions where LogTime > @0 order by LogTime desc", DateTime.Now.AddDays(-7));
/// <summary>
///
/// </summary>
/// <param name="po"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <param name="sort"></param>
/// <returns></returns>
public virtual Page<Exceptions> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime)
{
string sql = "select * from Exceptions where LogTime > @LogTime order by LogTime desc";
List<Exceptions> exceptions = new List<Exceptions>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now.AddDays(-7), DbType.DateTime));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
exceptions.Add(new Exceptions()
{
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],
UserIp = reader.IsDBNull(4) ? string.Empty : (string)reader[4],
ExceptionType = (string)reader[5],
Message = (string)reader[6],
StackTrace = reader.IsDBNull(7) ? string.Empty : (string)reader[7],
LogTime = LgbConvert.ReadValue(reader[8], DateTime.MinValue)
});
}
}
return exceptions;
var sql = new Sql("select * from Exceptions");
if (startTime.HasValue) sql.Append("where LogTime > @0", startTime.Value);
if (endTime.HasValue) sql.Append("where LogTime < @0", endTime.Value);
if (startTime == null && endTime == null) sql.Append("where LogTime > @0", DateTime.Today.AddDays(-7));
sql.Append("order by @0", $"{po.Sort} {po.Order}");
return DbManager.Db.Page<Exceptions>(po.PageIndex, po.Limit, sql);
}
}
}

View File

@ -1,10 +1,6 @@
using Bootstrap.Security.DataAccess;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
namespace Bootstrap.DataAccess
@ -39,57 +35,30 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual IEnumerable<Group> RetrieveGroups()
{
string sql = "select * from Groups";
List<Group> groups = new List<Group>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
groups.Add(new Group()
{
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
});
}
}
return groups;
}
public virtual IEnumerable<Group> Retrieves() => DbManager.Db.Fetch<Group>("select * from Groups");
/// <summary>
/// 删除群组信息
/// </summary>
/// <param name="ids"></param>
public virtual bool DeleteGroup(IEnumerable<string> value)
public virtual bool Delete(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserGroup where GroupID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from RoleGroup where GroupID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Groups where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
db.BeginTransaction();
db.Execute($"delete from UserGroup where GroupID in ({ids})");
db.Execute($"delete from RoleGroup where GroupID in ({ids})");
db.Execute($"delete from Groups where ID in ({ids})");
db.CompleteTransaction();
ret = true;
}
catch (Exception e)
{
db.AbortTransaction();
throw e;
}
return ret;
}
@ -99,22 +68,10 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public virtual bool SaveGroup(Group p)
public virtual bool Save(Group p)
{
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 = 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))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupName", p.GroupName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
DbManager.Db.Save(p);
return !p.Id.IsNullOrEmpty();
}
/// <summary>
@ -122,27 +79,14 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
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>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
groups.Add(new Group()
{
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return groups;
}
public virtual IEnumerable<Group> RetrievesByUserId(string userId) => DbManager.Db.Fetch<Group>("select g.ID, g.GroupName, g.Description, case ug.GroupID when g.ID then 'checked' else '' end Checked from Groups g left join UserGroup ug on g.ID = ug.GroupID and UserID = @0", userId);
/// <summary>
/// 根据角色ID指派部门
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public virtual IEnumerable<Group> RetrievesByRoleId(string roleId) => DbManager.Db.Fetch<Group>("select g.ID, g.GroupName, g.Description, case rg.GroupID when g.ID then 'checked' else '' end Checked from Groups g left join RoleGroup rg on g.ID = rg.GroupID and RoleID = @0", roleId);
/// <summary>
/// 保存用户部门关系
@ -150,113 +94,50 @@ namespace Bootstrap.DataAccess
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public virtual bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
public virtual bool SaveByUserId(string userId, IEnumerable<string> groupIds)
{
var ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
//判断用户是否选定角色
groupIds.ToList().ForEach(groupId => dt.Rows.Add(userId, groupId));
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
//删除用户部门表中该用户所有的部门关系
string sql = $"delete from UserGroup where UserID = {userId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
bulk.BatchSize = 1000;
bulk.DestinationTableName = "UserGroup";
bulk.ColumnMappings.Add("UserID", "UserID");
bulk.ColumnMappings.Add("GroupID", "GroupID");
bulk.WriteToServer(dt);
transaction.CommitTransaction();
}
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
db.BeginTransaction();
//删除用户部门表中该用户所有的部门关系
db.Execute("delete from UserGroup where UserID = @0", userId);
db.InsertBulk("UserGroup", groupIds.Select(g => new { UserID = userId, GroupID = g }));
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
/// <summary>
/// 根据角色ID指派部门
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
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";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
groups.Add(new Group()
{
Id = reader[0].ToString(),
GroupName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return groups;
}
/// <summary>
/// 根据角色ID以及选定的部门ID保到角色部门表
/// </summary>
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public virtual bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
public virtual bool SaveByRoleId(string roleId, IEnumerable<string> groupIds)
{
bool ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("GroupID", typeof(int));
dt.Columns.Add("RoleID", typeof(int));
groupIds.ToList().ForEach(groupId => dt.Rows.Add(groupId, roleId));
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
//删除角色部门表该角色所有的部门
string sql = $"delete from RoleGroup where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入角色部门表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
bulk.BatchSize = 1000;
bulk.ColumnMappings.Add("GroupID", "GroupID");
bulk.ColumnMappings.Add("RoleID", "RoleID");
bulk.DestinationTableName = "RoleGroup";
bulk.WriteToServer(dt);
transaction.CommitTransaction();
}
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
db.BeginTransaction();
//删除角色部门表该角色所有的部门
db.Execute("delete from RoleGroup where RoleID = @0", roleId);
db.InsertBulk("RoleGroup", groupIds.Select(g => new { RoleID = roleId, GroupID = g }));
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
@ -266,6 +147,6 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public virtual IEnumerable<string> RetrieveGroupsByUserName(string userName) => DbHelper.RetrieveGroupsByUserName(userName);
public virtual IEnumerable<string> RetrievesByUserName(string userName) => DbHelper.RetrieveGroupsByUserName(userName);
}
}

View File

@ -17,37 +17,42 @@ namespace Bootstrap.DataAccess
/// 缓存索引BootstrapAdmin后台清理缓存时使用
/// </summary>
public const string RetrieveDictsDataKey = "BootstrapDict-RetrieveDicts";
/// <summary>
///
/// </summary>
public const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<BootstrapDict> RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key => DbAdapterManager.Create<Dict>().RetrieveDicts());
public static IEnumerable<BootstrapDict> RetrieveDicts() => CacheManager.GetOrAdd(RetrieveDictsDataKey, key => DbContextManager.Create<Dict>().RetrieveDicts());
/// <summary>
/// 删除字典中的数据
/// </summary>
/// <param name="value">需要删除的IDs</param>
/// <returns></returns>
public static bool DeleteDict(IEnumerable<string> value)
public static bool Delete(IEnumerable<string> value)
{
var ret = DbAdapterManager.Create<Dict>().DeleteDict(value);
var ret = DbContextManager.Create<Dict>().Delete(value);
CacheCleanUtility.ClearCache(dictIds: value);
return ret;
}
/// <summary>
/// 保存新建/更新的字典信息
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool SaveDict(BootstrapDict p)
public static bool Save(BootstrapDict p)
{
var ret = DbAdapterManager.Create<Dict>().SaveDict(p);
if (ret) CacheCleanUtility.ClearCache( new List<string>() { p.Id });
var ret = DbContextManager.Create<Dict>().Save(p);
if (ret) CacheCleanUtility.ClearCache(new List<string>() { p.Id });
return ret;
}
/// <summary>
/// 保存网站个性化设置
/// </summary>
@ -57,49 +62,63 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static bool SaveSettings(BootstrapDict dict)
{
var ret = DbAdapterManager.Create<Dict>().SaveSettings(dict);
var ret = DbContextManager.Create<Dict>().SaveSettings(dict);
if (ret) CacheCleanUtility.ClearCache(dictIds: new List<string>());
return ret;
}
/// <summary>
/// 获取字典分类名称
/// </summary>
/// <returns></returns>
public static IEnumerable<string> RetrieveCategories() => CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => DbAdapterManager.Create<Dict>().RetrieveCategories());
public static IEnumerable<string> RetrieveCategories() => CacheManager.GetOrAdd(RetrieveCategoryDataKey, key => DbContextManager.Create<Dict>().RetrieveCategories());
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string RetrieveWebTitle() => DbAdapterManager.Create<Dict>().RetrieveWebTitle();
public static string RetrieveWebTitle() => DbContextManager.Create<Dict>().RetrieveWebTitle();
/// <summary>
///
/// </summary>
/// <returns></returns>
public static string RetrieveWebFooter() => DbAdapterManager.Create<Dict>().RetrieveWebFooter();
public static string RetrieveWebFooter() => DbContextManager.Create<Dict>().RetrieveWebFooter();
/// <summary>
/// 获得系统中配置的可以使用的网站样式
/// </summary>
/// <returns></returns>
public static IEnumerable<BootstrapDict> RetrieveThemes() => DbAdapterManager.Create<Dict>().RetrieveThemes();
public static IEnumerable<BootstrapDict> RetrieveThemes() => DbContextManager.Create<Dict>().RetrieveThemes();
/// <summary>
/// 获得网站设置中的当前样式
/// </summary>
/// <returns></returns>
public static string RetrieveActiveTheme() => DbAdapterManager.Create<Dict>().RetrieveActiveTheme();
public static string RetrieveActiveTheme() => DbContextManager.Create<Dict>().RetrieveActiveTheme();
/// <summary>
/// 获取头像路径
/// </summary>
/// <returns></returns>
public static BootstrapDict RetrieveIconFolderPath() => DbAdapterManager.Create<Dict>().RetrieveIconFolderPath();
public static string RetrieveIconFolderPath() => DbContextManager.Create<Dict>().RetrieveIconFolderPath();
/// <summary>
/// 获得默认的前台首页地址,默认为~/Home/Index
/// </summary>
/// <returns></returns>
public static string RetrieveHomeUrl() => DbAdapterManager.Create<Dict>().RetrieveHomeUrl();
public static string RetrieveHomeUrl() => DbContextManager.Create<Dict>().RetrieveHomeUrl();
/// <summary>
/// 获得默认的前台首页地址,默认为~/Home/Index
/// </summary>
/// <returns></returns>
public static string RetrieveDefaultIcon() => DbContextManager.Create<Dict>().RetrieveDefaultIcon();
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DbAdapterManager.Create<Dict>().RetrieveApps();
public static IEnumerable<KeyValuePair<string, string>> RetrieveApps() => DbContextManager.Create<Dict>().RetrieveApps();
}
}

View File

@ -1,5 +1,7 @@
using Longbow.Cache;
using Longbow.Data;
using Longbow.Web.Mvc;
using PetaPoco;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
@ -23,7 +25,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static void Log(Exception ex, NameValueCollection additionalInfo)
{
var ret = DbAdapterManager.Create<Exceptions>().Log(ex, additionalInfo);
var ret = DbContextManager.Create<Exceptions>().Log(ex, additionalInfo);
if (ret) CacheManager.Clear(RetrieveExceptionsDataKey);
}
@ -31,6 +33,15 @@ namespace Bootstrap.DataAccess
/// 查询一周内所有异常
/// </summary>
/// <returns></returns>
public static IEnumerable<Exceptions> RetrieveExceptions() => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbAdapterManager.Create<Exceptions>().RetrieveExceptions());
public static IEnumerable<Exceptions> Retrieves() => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbContextManager.Create<Exceptions>().Retrieves());
/// <summary>
///
/// </summary>
/// <param name="po"></param>
/// <param name="startTime"></param>
/// <param name="endTime"></param>
/// <returns></returns>
public static Page<Exceptions> RetrievePages(PaginationOption po, DateTime? startTime, DateTime? endTime) => CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key => DbContextManager.Create<Exceptions>().RetrievePages(po, startTime, endTime));
}
}

View File

@ -19,16 +19,16 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<Group> RetrieveGroups() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbAdapterManager.Create<Group>().RetrieveGroups());
public static IEnumerable<Group> Retrieves() => CacheManager.GetOrAdd(RetrieveGroupsDataKey, key => DbContextManager.Create<Group>().Retrieves());
/// <summary>
/// 删除群组信息
/// </summary>
/// <param name="ids"></param>
public static bool DeleteGroup(IEnumerable<string> value)
/// <param name="values"></param>
public static bool Delete(IEnumerable<string> values)
{
var ret = DbAdapterManager.Create<Group>().DeleteGroup(value);
if (ret) CacheCleanUtility.ClearCache(groupIds: value);
var ret = DbContextManager.Create<Group>().Delete(values);
if (ret) CacheCleanUtility.ClearCache(groupIds: values);
return ret;
}
@ -37,9 +37,9 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool SaveGroup(Group p)
public static bool Save(Group p)
{
var ret = DbAdapterManager.Create<Group>().SaveGroup(p);
var ret = DbContextManager.Create<Group>().Save(p);
if (ret) CacheCleanUtility.ClearCache(groupIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
return ret;
}
@ -48,7 +48,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public static IEnumerable<Group> RetrieveGroupsByUserId(string userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbAdapterManager.Create<Group>().RetrieveGroupsByUserId(userId), RetrieveGroupsByUserIdDataKey);
public static IEnumerable<Group> RetrievesByUserId(string userId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId), k => DbContextManager.Create<Group>().RetrievesByUserId(userId), RetrieveGroupsByUserIdDataKey);
/// <summary>
/// 保存用户部门关系
@ -56,9 +56,9 @@ namespace Bootstrap.DataAccess
/// <param name="userId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public static bool SaveGroupsByUserId(string userId, IEnumerable<string> groupIds)
public static bool SaveByUserId(string userId, IEnumerable<string> groupIds)
{
var ret = DbAdapterManager.Create<Group>().SaveGroupsByUserId(userId, groupIds);
var ret = DbContextManager.Create<Group>().SaveByUserId(userId, groupIds);
if (ret) CacheCleanUtility.ClearCache(groupIds: groupIds, userIds: new List<string>() { userId });
return ret;
}
@ -68,7 +68,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public static IEnumerable<Group> RetrieveGroupsByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbAdapterManager.Create<Group>().RetrieveGroupsByRoleId(roleId), RetrieveGroupsByRoleIdDataKey);
public static IEnumerable<Group> RetrievesByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId), key => DbContextManager.Create<Group>().RetrievesByRoleId(roleId), RetrieveGroupsByRoleIdDataKey);
/// <summary>
/// 根据角色ID以及选定的部门ID保到角色部门表
@ -76,9 +76,9 @@ namespace Bootstrap.DataAccess
/// <param name="roleId"></param>
/// <param name="groupIds"></param>
/// <returns></returns>
public static bool SaveGroupsByRoleId(string roleId, IEnumerable<string> groupIds)
public static bool SaveByRoleId(string roleId, IEnumerable<string> groupIds)
{
var ret = DbAdapterManager.Create<Group>().SaveGroupsByRoleId(roleId, groupIds);
var ret = DbContextManager.Create<Group>().SaveByRoleId(roleId, groupIds);
if (ret) CacheCleanUtility.ClearCache(groupIds: groupIds, roleIds: new List<string>() { roleId });
return ret;
}
@ -88,6 +88,6 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<string> RetrieveGroupsByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbAdapterManager.Create<Group>().RetrieveGroupsByUserName(userName), RetrieveGroupsByUserNameDataKey);
public static IEnumerable<string> RetrievesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveGroupsByUserNameDataKey, userName), r => DbContextManager.Create<Group>().RetrievesByUserName(userName), RetrieveGroupsByUserNameDataKey);
}
}

View File

@ -13,20 +13,22 @@ namespace Bootstrap.DataAccess
///
/// </summary>
public const string RetrieveLogsDataKey = "LogHelper-RetrieveLogs";
/// <summary>
/// 查询所有日志信息
/// </summary>
/// <param name="tId"></param>
/// <returns></returns>
public static IEnumerable<Log> RetrieveLogs() => CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbAdapterManager.Create<Log>().RetrieveLogs());
public static IEnumerable<Log> Retrieves() => CacheManager.GetOrAdd(RetrieveLogsDataKey, key => DbContextManager.Create<Log>().Retrieves());
/// <summary>
/// 保存新增的日志信息
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool SaveLog(Log p)
public static bool Save(Log p)
{
var ret = DbAdapterManager.Create<Log>().SaveLog(p);
var ret = DbContextManager.Create<Log>().Save(p);
if (ret) CacheManager.Clear(RetrieveLogsDataKey);
return ret;
}

View File

@ -27,9 +27,9 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool SaveMenu(BootstrapMenu p)
public static bool Save(BootstrapMenu p)
{
var ret = DbAdapterManager.Create<Menu>().SaveMenu(p);
var ret = DbContextManager.Create<Menu>().Save(p);
if (ret) CacheCleanUtility.ClearCache(menuIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
return ret;
}
@ -39,9 +39,9 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool DeleteMenu(IEnumerable<string> value)
public static bool Delete(IEnumerable<string> value)
{
var ret = DbAdapterManager.Create<Menu>().DeleteMenu(value);
var ret = DbContextManager.Create<Menu>().Delete(value);
if (ret) CacheCleanUtility.ClearCache(menuIds: value);
return ret;
}
@ -58,7 +58,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public static IEnumerable<object> RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbAdapterManager.Create<Menu>().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey);
public static IEnumerable<object> RetrieveMenusByRoleId(string roleId) => CacheManager.GetOrAdd($"{RetrieveMenusByRoleIdDataKey}-{roleId}", k => DbContextManager.Create<Menu>().RetrieveMenusByRoleId(roleId), RetrieveMenusByRoleIdDataKey);
/// <summary>
///
@ -68,7 +68,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
{
var ret = DbAdapterManager.Create<Menu>().SaveMenusByRoleId(roleId, menuIds);
var ret = DbContextManager.Create<Menu>().SaveMenusByRoleId(roleId, menuIds);
if (ret) CacheCleanUtility.ClearCache(menuIds: menuIds, roleIds: new List<string>() { roleId });
return ret;
}
@ -82,10 +82,9 @@ namespace Bootstrap.DataAccess
public static IEnumerable<BootstrapMenu> RetrieveAppMenus(string appId, string userName, string activeUrl)
{
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "1" && m.IsResource == 0);
if (appId != "0") menus = menus.Where(m => m.ApplicationCode == appId);
var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
DbHelper.CascadeMenus(menus, root);
DbHelper.ActiveMenu(null, menus, activeUrl);
if (appId != "0") menus = menus.Where(m => m.Application == appId);
var root = DbHelper.CascadeMenus(menus);
DbHelper.ActiveMenu(root, activeUrl);
return root;
}
@ -100,9 +99,8 @@ namespace Bootstrap.DataAccess
public static IEnumerable<BootstrapMenu> RetrieveSystemMenus(string userName, string activeUrl = null)
{
var menus = RetrieveAllMenus(userName).Where(m => m.Category == "0" && m.IsResource == 0);
var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
DbHelper.CascadeMenus(menus, root);
DbHelper.ActiveMenu(null, menus, activeUrl);
var root = DbHelper.CascadeMenus(menus);
DbHelper.ActiveMenu(root, activeUrl);
return root;
}
@ -114,9 +112,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<object> RetrieveMenus(string userName)
{
var menus = RetrieveAllMenus(userName);
var root = menus.Where(m => m.ParentId == "0").OrderBy(m => m.ApplicationCode).ThenBy(m => m.Order);
DbHelper.CascadeMenus(menus, root);
return root;
return DbHelper.CascadeMenus(menus);
}
/// <summary>
@ -124,6 +120,6 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
private static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbAdapterManager.Create<Menu>().RetrieveAllMenus(userName), RetrieveMenusAll);
private static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create<Menu>().RetrieveAllMenus(userName), RetrieveMenusAll);
}
}

View File

@ -18,30 +18,30 @@ namespace Bootstrap.DataAccess
/// 收件箱
/// </summary>
/// <param name="userName"></param>
public static IEnumerable<Message> Inbox(string userName) => DbAdapterManager.Create<Message>().Inbox(userName);
public static IEnumerable<Message> Inbox(string userName) => DbContextManager.Create<Message>().Inbox(userName);
/// <summary>
/// 发件箱
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<Message> SendMail(string userName) => DbAdapterManager.Create<Message>().SendMail(userName);
public static IEnumerable<Message> SendMail(string userName) => DbContextManager.Create<Message>().SendMail(userName);
/// <summary>
/// 垃圾箱
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<Message> Trash(string userName) => DbAdapterManager.Create<Message>().Trash(userName);
public static IEnumerable<Message> Trash(string userName) => DbContextManager.Create<Message>().Trash(userName);
/// <summary>
/// 标旗
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<Message> Mark(string userName) => DbAdapterManager.Create<Message>().Flag(userName);
public static IEnumerable<Message> Mark(string userName) => DbContextManager.Create<Message>().Flag(userName);
/// <summary>
/// 获取Header处显示的消息列表
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<Message> RetrieveMessagesHeader(string userName) => CacheManager.GetOrAdd(RetrieveMessageDataKey, key => DbAdapterManager.Create<Message>().RetrieveMessagesHeader(userName).OrderByDescending(n => n.SendTime));
public static IEnumerable<Message> Retrieves(string userName) => CacheManager.GetOrAdd(RetrieveMessageDataKey, key => DbContextManager.Create<Message>().RetrieveHeaders(userName).OrderByDescending(n => n.SendTime));
}
}

View File

@ -21,7 +21,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRoles() => CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbAdapterManager.Create<Role>().RetrieveRoles());
public static IEnumerable<Role> Retrieves() => CacheManager.GetOrAdd(RetrieveRolesDataKey, key => DbContextManager.Create<Role>().Retrieves());
/// <summary>
/// 保存用户角色关系
@ -29,9 +29,9 @@ namespace Bootstrap.DataAccess
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public static bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds)
public static bool SaveByUserId(string userId, IEnumerable<string> roleIds)
{
var ret = DbAdapterManager.Create<Role>().SaveRolesByUserId(userId, roleIds);
var ret = DbContextManager.Create<Role>().SaveByUserId(userId, roleIds);
if (ret) CacheCleanUtility.ClearCache(userIds: new List<string>() { userId }, roleIds: roleIds);
return ret;
}
@ -40,15 +40,15 @@ namespace Bootstrap.DataAccess
/// 查询某个用户所拥有的角色
/// </summary>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRolesByUserId(string userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbAdapterManager.Create<Role>().RetrieveRolesByUserId(userId), RetrieveRolesByUserIdDataKey);
public static IEnumerable<Role> RetrievesByUserId(string userId) => CacheManager.GetOrAdd($"{RetrieveRolesByUserIdDataKey}-{userId}", key => DbContextManager.Create<Role>().RetrievesByUserId(userId), RetrieveRolesByUserIdDataKey);
/// <summary>
/// 删除角色表
/// </summary>
/// <param name="value"></param>
public static bool DeleteRole(IEnumerable<string> value)
public static bool Delete(IEnumerable<string> value)
{
var ret = DbAdapterManager.Create<Role>().DeleteRole(value);
var ret = DbContextManager.Create<Role>().Delete(value);
if (ret) CacheCleanUtility.ClearCache(roleIds: value);
return ret;
}
@ -58,9 +58,9 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool SaveRole(Role p)
public static bool Save(Role p)
{
var ret = DbAdapterManager.Create<Role>().SaveRole(p);
var ret = DbContextManager.Create<Role>().Save(p);
if (ret) CacheCleanUtility.ClearCache(roleIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string> { p.Id });
return ret;
}
@ -70,7 +70,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRolesByMenuId(string menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbAdapterManager.Create<Role>().RetrieveRolesByMenuId(menuId), RetrieveRolesByMenuIdDataKey);
public static IEnumerable<Role> RetrievesByMenuId(string menuId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId), key => DbContextManager.Create<Role>().RetrievesByMenuId(menuId), RetrieveRolesByMenuIdDataKey);
/// <summary>
///
@ -78,9 +78,9 @@ namespace Bootstrap.DataAccess
/// <param name="menuId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public static bool SavaRolesByMenuId(string menuId, IEnumerable<string> roleIds)
public static bool SavaByMenuId(string menuId, IEnumerable<string> roleIds)
{
var ret = DbAdapterManager.Create<Role>().SavaRolesByMenuId(menuId, roleIds);
var ret = DbContextManager.Create<Role>().SavaByMenuId(menuId, roleIds);
if (ret) CacheCleanUtility.ClearCache(roleIds: roleIds, menuIds: new List<string>() { menuId });
return ret;
}
@ -90,7 +90,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public static IEnumerable<Role> RetrieveRolesByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbAdapterManager.Create<Role>().RetrieveRolesByGroupId(groupId), RetrieveRolesByGroupIdDataKey);
public static IEnumerable<Role> RetrievesByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId), key => DbContextManager.Create<Role>().RetrievesByGroupId(groupId), RetrieveRolesByGroupIdDataKey);
/// <summary>
/// 根据GroupId更新Roles信息删除旧的Roles信息插入新的Roles信息
@ -98,9 +98,9 @@ namespace Bootstrap.DataAccess
/// <param name="groupId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public static bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
public static bool SaveByGroupId(string groupId, IEnumerable<string> roleIds)
{
var ret = DbAdapterManager.Create<Role>().SaveRolesByGroupId(groupId, roleIds);
var ret = DbContextManager.Create<Role>().SaveByGroupId(groupId, roleIds);
if (ret) CacheCleanUtility.ClearCache(roleIds: roleIds, groupIds: new List<string>() { groupId });
return ret;
}
@ -110,13 +110,13 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<string> RetrieveRolesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), key => DbAdapterManager.Create<Role>().RetrieveRolesByUserName(userName), RetrieveRolesByUserNameDataKey);
public static IEnumerable<string> RetrieveRolesByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUserNameDataKey, userName), key => DbContextManager.Create<Role>().RetrieveRolesByUserName(userName), RetrieveRolesByUserNameDataKey);
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public static IEnumerable<string> RetrieveRolesByUrl(string url) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUrlDataKey, url), key => DbAdapterManager.Create<Role>().RetrieveRolesByUrl(url), RetrieveRolesByUrlDataKey);
public static IEnumerable<string> RetrieveRolesByUrl(string url) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveRolesByUrlDataKey, url), key => DbContextManager.Create<Role>().RetrieveRolesByUrl(url), RetrieveRolesByUrlDataKey);
}
}

View File

@ -13,10 +13,11 @@ namespace Bootstrap.DataAccess
///
/// </summary>
public const string RetrieveTasksDataKey = "TaskHelper-RetrieveTasks";
/// <summary>
/// 查询所有任务
/// </summary>
/// <returns></returns>
public static IEnumerable<Task> RetrieveTasks() => CacheManager.GetOrAdd(RetrieveTasksDataKey, key => DbAdapterManager.Create<Task>().RetrieveTasks());
public static IEnumerable<Task> Retrieves() => CacheManager.GetOrAdd(RetrieveTasksDataKey, key => DbContextManager.Create<Task>().Retrieves());
}
}

View File

@ -15,45 +15,51 @@ namespace Bootstrap.DataAccess
public const string RetrieveUsersByGroupIdDataKey = "UserHelper-RetrieveUsersByGroupId";
public const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers";
public const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName";
/// <summary>
/// 查询所有用户
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<User> RetrieveUsers() => CacheManager.GetOrAdd(RetrieveUsersDataKey, key => DbAdapterManager.Create<User>().RetrieveUsers());
public static IEnumerable<User> Retrieves() => CacheManager.GetOrAdd(RetrieveUsersDataKey, key => DbContextManager.Create<User>().Retrieves());
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <param name="password"></param>
/// <returns></returns>
public static bool Authenticate(string userName, string password) => DbAdapterManager.Create<User>().Authenticate(userName, password);
public static bool Authenticate(string userName, string password) => DbContextManager.Create<User>().Authenticate(userName, password);
/// <summary>
/// 查询所有的新注册用户
/// </summary>
/// <returns></returns>
public static IEnumerable<User> RetrieveNewUsers() => CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key => DbAdapterManager.Create<User>().RetrieveNewUsers());
public static IEnumerable<User> RetrieveNewUsers() => CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key => DbContextManager.Create<User>().RetrieveNewUsers());
/// <summary>
/// 删除用户
/// </summary>
/// <param name="value"></param>
public static bool DeleteUser(IEnumerable<string> value)
public static bool Delete(IEnumerable<string> value)
{
var ret = DbAdapterManager.Create<User>().DeleteUser(value);
var ret = DbContextManager.Create<User>().Delete(value);
if (ret) CacheCleanUtility.ClearCache(userIds: value);
return ret;
}
/// <summary>
/// 保存新建
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool SaveUser(User p)
public static bool Save(User p)
{
var ret = DbAdapterManager.Create<User>().SaveUser(p);
var ret = DbContextManager.Create<User>().Save(p);
if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(p.Id) ? new List<string>() : new List<string>() { p.Id });
return ret;
}
/// <summary>
///
/// </summary>
@ -61,24 +67,26 @@ namespace Bootstrap.DataAccess
/// <param name="password"></param>
/// <param name="displayName"></param>
/// <returns></returns>
public static bool UpdateUser(string id, string password, string displayName)
public static bool Update(string id, string password, string displayName)
{
var ret = DbAdapterManager.Create<User>().UpdateUser(id, password, displayName);
var ret = DbContextManager.Create<User>().Update(id, password, displayName);
if (ret) CacheCleanUtility.ClearCache(userIds: string.IsNullOrEmpty(id) ? new List<string>() : new List<string>() { id });
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="approvedBy"></param>
/// <returns></returns>
public static bool ApproveUser(string id, string approvedBy)
public static bool Approve(string id, string approvedBy)
{
var ret = DbAdapterManager.Create<User>().ApproveUser(id, approvedBy);
var ret = DbContextManager.Create<User>().Approve(id, approvedBy);
if (ret) CacheCleanUtility.ClearCache(userIds: new List<string>() { id });
return ret;
}
/// <summary>
///
/// </summary>
@ -86,7 +94,8 @@ namespace Bootstrap.DataAccess
/// <param name="password"></param>
/// <param name="newPass"></param>
/// <returns></returns>
public static bool ChangePassword(string userName, string password, string newPass) => DbAdapterManager.Create<User>().ChangePassword(userName, password, newPass);
public static bool ChangePassword(string userName, string password, string newPass) => DbContextManager.Create<User>().ChangePassword(userName, password, newPass);
/// <summary>
///
/// </summary>
@ -94,48 +103,53 @@ namespace Bootstrap.DataAccess
/// <param name="rejectBy"></param>
/// <param name="reason"></param>
/// <returns></returns>
public static bool RejectUser(string id, string rejectBy)
public static bool Reject(string id, string rejectBy)
{
var ret = DbAdapterManager.Create<User>().RejectUser(id, rejectBy);
var ret = DbContextManager.Create<User>().Reject(id, rejectBy);
if (ret) CacheCleanUtility.ClearCache(userIds: new List<string>() { id });
return ret;
}
/// <summary>
/// 通过roleId获取所有用户
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public static IEnumerable<User> RetrieveUsersByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbAdapterManager.Create<User>().RetrieveUsersByRoleId(roleId), RetrieveUsersByRoleIdDataKey);
public static IEnumerable<User> RetrievesByRoleId(string roleId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId), k => DbContextManager.Create<User>().RetrievesByRoleId(roleId), RetrieveUsersByRoleIdDataKey);
/// <summary>
/// 通过角色ID保存当前授权用户插入
/// </summary>
/// <param name="roleId">角色ID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public static bool SaveUsersByRoleId(string roleId, IEnumerable<string> userIds)
public static bool SaveByRoleId(string roleId, IEnumerable<string> userIds)
{
var ret = DbAdapterManager.Create<User>().SaveUsersByRoleId(roleId, userIds);
var ret = DbContextManager.Create<User>().SaveByRoleId(roleId, userIds);
if (ret) CacheCleanUtility.ClearCache(userIds: userIds, roleIds: new List<string>() { roleId });
return ret;
}
/// <summary>
/// 通过groupId获取所有用户
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
public static IEnumerable<User> RetrieveUsersByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbAdapterManager.Create<User>().RetrieveUsersByGroupId(groupId), RetrieveUsersByRoleIdDataKey);
public static IEnumerable<User> RetrievesByGroupId(string groupId) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId), k => DbContextManager.Create<User>().RetrievesByGroupId(groupId), RetrieveUsersByRoleIdDataKey);
/// <summary>
/// 通过部门ID保存当前授权用户插入
/// </summary>
/// <param name="groupId">GroupID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public static bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
public static bool SaveByGroupId(string groupId, IEnumerable<string> userIds)
{
var ret = DbAdapterManager.Create<User>().SaveUsersByGroupId(groupId, userIds);
var ret = DbContextManager.Create<User>().SaveByGroupId(groupId, userIds);
if (ret) CacheCleanUtility.ClearCache(userIds: userIds, groupIds: new List<string>() { groupId });
return ret;
}
/// 根据用户名修改用户头像
/// </summary>
/// <param name="userName"></param>
@ -143,10 +157,11 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static bool SaveUserIconByName(string userName, string iconName)
{
var ret = DbAdapterManager.Create<User>().SaveUserIconByName(userName, iconName);
var ret = DbContextManager.Create<User>().SaveUserIconByName(userName, iconName);
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
return ret;
}
/// <summary>
///
/// </summary>
@ -155,7 +170,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static bool SaveDisplayName(string userName, string displayName)
{
var ret = DbAdapterManager.Create<User>().SaveDisplayName(userName, displayName);
var ret = DbContextManager.Create<User>().SaveDisplayName(userName, displayName);
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{RetrieveUsersDataKey}*");
return ret;
}
@ -168,15 +183,16 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static bool SaveUserCssByName(string userName, string cssName)
{
var ret = DbAdapterManager.Create<User>().SaveUserCssByName(userName, cssName);
var ret = DbContextManager.Create<User>().SaveUserCssByName(userName, cssName);
if (ret) CacheCleanUtility.ClearCache(cacheKey: $"{UserHelper.RetrieveUsersDataKey}*");
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => DbAdapterManager.Create<User>().RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey);
public static BootstrapUser RetrieveUserByUserName(string userName) => CacheManager.GetOrAdd(string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName), k => DbContextManager.Create<User>().RetrieveUserByUserName(userName), RetrieveUsersByNameDataKey);
}
}

View File

@ -2,8 +2,6 @@
using Longbow.Configuration;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess
{
@ -46,35 +44,14 @@ namespace Bootstrap.DataAccess
/// 获取/设置 请求网址
/// </summary>
public string RequestUrl { get; set; }
/// <summary>
/// 查询所有日志信息
/// </summary>
/// <param name="tId"></param>
/// <returns></returns>
public virtual IEnumerable<Log> RetrieveLogs()
{
string sql = "select * from Logs where LogTime > @LogTime";
List<Log> logs = new List<Log>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now.AddDays(-7), DbType.DateTime));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
logs.Add(new Log()
{
Id = reader[0].ToString(),
CRUD = (string)reader[1],
UserName = (string)reader[2],
LogTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
ClientIp = (string)reader[4],
ClientAgent = (string)reader[5],
RequestUrl = (string)reader[6]
});
}
}
return logs;
}
public virtual IEnumerable<Log> Retrieves() => DbManager.Db.Fetch<Log>();
/// <summary>
/// 删除日志信息
/// </summary>
@ -84,34 +61,23 @@ namespace Bootstrap.DataAccess
{
System.Threading.Tasks.Task.Run(() =>
{
string sql = $"delete from Logs where LogTime < @LogTime";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepLogsPeriod"], 1)), DbType.DateTime));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd);
var dtm = DateTime.Now.AddMonths(0 - LgbConvert.ReadValue(ConfigurationManager.AppSettings["KeepLogsPeriod"], 1));
DbManager.Db.Execute("delete from Logs where LogTime < @0", dtm);
});
}
/// <summary>
/// 保存新增的日志信息
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public virtual bool SaveLog(Log p)
public virtual bool Save(Log p)
{
if (p == null) throw new ArgumentNullException(nameof(p));
bool ret = false;
string sql = "Insert Into Logs (CRUD, UserName, LogTime, ClientIp, ClientAgent, RequestUrl) Values (@CRUD, @UserName, @LogTime, @ClientIp, @ClientAgent, @RequestUrl)";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@CRUD", p.CRUD));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", p.UserName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@LogTime", DateTime.Now, DbType.DateTime));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ClientIp", p.ClientIp));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ClientAgent", p.ClientAgent));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RequestUrl", p.RequestUrl));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
DeleteLogAsync();
return ret;
p.LogTime = DateTime.Now;
DbManager.Db.Save(p);
return true;
}
}
}

View File

@ -1,11 +1,7 @@
using Bootstrap.Security;
using Bootstrap.Security.DataAccess;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
namespace Bootstrap.DataAccess
@ -19,30 +15,23 @@ namespace Bootstrap.DataAccess
/// 删除菜单信息
/// </summary>
/// <param name="value"></param>
public virtual bool DeleteMenu(IEnumerable<string> value)
public virtual bool Delete(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var ret = false;
var db = DbManager.Db;
try
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from NavigationRole where NavigationID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Navigations where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
var ids = string.Join(",", value);
db.BeginTransaction();
db.Execute($"delete from NavigationRole where NavigationID in ({ids})");
db.Execute($"delete from Navigations where ID in ({ids})");
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
@ -51,31 +40,15 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public virtual bool SaveMenu(BootstrapMenu p)
public virtual bool Save(BootstrapMenu p)
{
if (string.IsNullOrEmpty(p.Name)) return false;
bool ret = false;
if (string.IsNullOrEmpty(p.Name)) throw new ArgumentNullException(nameof(p.Name));
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 = 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))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ParentId", p.ParentId));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Name", p.Name));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Order", p.Order));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Icon", DbAdapterManager.ToDBValue(p.Icon)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Url", DbAdapterManager.ToDBValue(p.Url)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Category", p.Category));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Target", p.Target));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@IsResource", p.IsResource));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApplicationCode", p.ApplicationCode));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
DbManager.Db.Save(p);
return true;
}
/// <summary>
/// 查询某个角色所配置的菜单
@ -84,22 +57,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public virtual IEnumerable<object> RetrieveMenusByRoleId(string roleId)
{
var menus = new List<BootstrapMenu>();
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
menus.Add(new BootstrapMenu()
{
Id = reader[0].ToString()
});
}
}
}
var menus = DbManager.Db.Fetch<BootstrapMenu>("select NavigationID as Id from NavigationRole where RoleID = @0", roleId);
return menus.Select(m => new { m.Id });
}
/// <summary>
@ -111,36 +69,19 @@ namespace Bootstrap.DataAccess
public virtual bool SaveMenusByRoleId(string roleId, IEnumerable<string> menuIds)
{
bool ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("NavigationID", typeof(int));
menuIds.ToList().ForEach(menuId => dt.Rows.Add(roleId, menuId));
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
//删除菜单角色表该角色所有的菜单
string sql = $"delete from NavigationRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入菜单角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
bulk.DestinationTableName = "NavigationRole";
bulk.ColumnMappings.Add("RoleID", "RoleID");
bulk.ColumnMappings.Add("NavigationID", "NavigationID");
bulk.WriteToServer(dt);
transaction.CommitTransaction();
}
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
db.BeginTransaction();
db.Execute("delete from NavigationRole where RoleID = @0", roleId);
db.InsertBulk("NavigationRole", menuIds.Select(g => new { NavigationID = g, RoleID = roleId }));
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}

View File

@ -1,8 +1,5 @@
using Longbow;
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess
@ -16,102 +13,96 @@ namespace Bootstrap.DataAccess
/// 消息主键 数据库自增
/// </summary>
public string Id { get; set; }
/// <summary>
/// 标题
/// </summary>
public string Title { get; set; }
/// <summary>
/// 内容
/// </summary>
public string Content { get; set; }
/// <summary>
/// 发消息人
/// </summary>
public string From { get; set; }
/// <summary>
/// 收消息人
/// </summary>
public string To { get; set; }
/// <summary>
/// 消息发送时间
/// </summary>
public DateTime SendTime { get; set; }
/// <summary>
/// 消息状态0-未读1-已读 和Dict表的通知消息关联
/// </summary>
public string Status { get; set; }
/// <summary>
/// 标旗状态0-未标旗1-已标旗
/// </summary>
public int Mark { get; set; }
/// <summary>
/// 删除状态0-未删除1-已删除
/// </summary>
public int IsDelete { get; set; }
/// <summary>
/// 消息标签0-一般1-紧要 和Dict表的消息标签关联
/// </summary>
public string Label { get; set; }
/// <summary>
/// 获得/设置 标签名称
/// </summary>
public string LabelName { get; set; }
/// <summary>
/// 获得/设置 时间描述 2分钟内为刚刚
/// </summary>
public string Period { get; set; }
/// <summary>
/// 获得/设置 发件人头像
/// </summary>
public string FromIcon { get; set; }
/// <summary>
/// 获得/设置 发件人昵称
/// </summary>
public string FromDisplayName { get; set; }
//TODO: SQL语句不兼容
/// <summary>
/// 所有有关userName所有消息列表
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
protected virtual IEnumerable<Message> RetrieveMessages(string userName)
protected virtual IEnumerable<Message> Retrieves(string userName)
{
string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/images/uploader/default.jpg'), u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = N'消息标签' and d.Define = 0 left join Dicts i on i.Category = N'头像地址' and i.Name = N'头像路径' and i.Define = 0 inner join Users u on m.[From] = u.UserName where [To] = @UserName or [From] = @UserName order by m.SendTime desc";
List<Message> messages = new List<Message>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
messages.Add(new Message()
{
Id = reader[0].ToString(),
Title = (string)reader[1],
Content = (string)reader[2],
From = (string)reader[3],
To = (string)reader[4],
SendTime = LgbConvert.ReadValue(reader[5], DateTime.MinValue),
Status = (string)reader[6],
Mark = (int)reader[7],
IsDelete = (int)reader[8],
Label = (string)reader[9],
LabelName = LgbConvert.ReadValue(reader[10], string.Empty),
FromIcon = (string)reader[11],
FromDisplayName = (string)reader[12]
});
}
}
return messages;
var db = DbManager.Db;
var t = db.Provider.EscapeSqlIdentifier("To");
var f = db.Provider.EscapeSqlIdentifier("From");
return db.Fetch<Message>($"select m.*, d.Name, u.DisplayName from [Messages] m left join Dicts d on m.Label = d.Code and d.Category = @Category and d.Define = 0 inner join Users u on m.{f} = u.UserName where {t} = @UserName or {f} = @UserName order by SendTime desc", new { UserName = userName, Category = "消息标签" });
}
/// <summary>
/// 收件箱
/// </summary>
/// <param name="userName"></param>
public virtual IEnumerable<Message> Inbox(string userName)
{
var messageRet = RetrieveMessages(userName);
var messageRet = Retrieves(userName);
return messageRet.Where(n => n.To.Equals(userName, StringComparison.OrdinalIgnoreCase));
}
/// <summary>
/// 发件箱
/// </summary>
@ -119,9 +110,10 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public virtual IEnumerable<Message> SendMail(string userName)
{
var messageRet = RetrieveMessages(userName);
var messageRet = Retrieves(userName);
return messageRet.Where(n => n.From.Equals(userName, StringComparison.OrdinalIgnoreCase));
}
/// <summary>
/// 垃圾箱
/// </summary>
@ -129,9 +121,10 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public virtual IEnumerable<Message> Trash(string userName)
{
var messageRet = RetrieveMessages(userName);
var messageRet = Retrieves(userName);
return messageRet.Where(n => n.IsDelete == 1);
}
/// <summary>
/// 标旗
/// </summary>
@ -139,15 +132,16 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public virtual IEnumerable<Message> Flag(string userName)
{
var messageRet = RetrieveMessages(userName);
var messageRet = Retrieves(userName);
return messageRet.Where(n => n.Mark == 1);
}
/// <summary>
/// 获取Header处显示的消息列表
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public virtual IEnumerable<Message> RetrieveMessagesHeader(string userName)
public virtual IEnumerable<Message> RetrieveHeaders(string userName)
{
var messageRet = Inbox(userName);
messageRet.AsParallel().ForAll(n =>

View File

@ -1,10 +1,6 @@
using Bootstrap.Security.DataAccess;
using Longbow.Data;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
namespace Bootstrap.DataAccess
@ -38,25 +34,7 @@ namespace Bootstrap.DataAccess
/// 查询所有角色
/// </summary>
/// <returns></returns>
public virtual IEnumerable<Role> RetrieveRoles()
{
string sql = "select * from Roles";
var roles = new List<Role>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
roles.Add(new Role()
{
Id = reader[0].ToString(),
RoleName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2]
});
}
}
return roles;
}
public virtual IEnumerable<Role> Retrieves() => DbManager.Db.Fetch<Role>();
/// <summary>
/// 保存用户角色关系
@ -64,43 +42,23 @@ namespace Bootstrap.DataAccess
/// <param name="userId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public virtual bool SaveRolesByUserId(string userId, IEnumerable<string> roleIds)
public virtual bool SaveByUserId(string userId, IEnumerable<string> roleIds)
{
var ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("RoleID", typeof(int));
//判断用户是否选定角色
roleIds.ToList().ForEach(roleId => dt.Rows.Add(userId, roleId));
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
// delete user from config table
string sql = $"delete from UserRole where UserID = {userId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
if (dt.Rows.Count > 0)
{
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
bulk.DestinationTableName = "UserRole";
bulk.ColumnMappings.Add("UserID", "UserID");
bulk.ColumnMappings.Add("RoleID", "RoleID");
bulk.WriteToServer(dt);
}
}
transaction.CommitTransaction();
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
db.BeginTransaction();
// delete user from config table
db.Execute("delete from UserRole where UserID = @0", userId);
db.InsertBulk("UserRole", roleIds.Select(g => new { UserID = userId, RoleID = g }));
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
@ -109,62 +67,31 @@ namespace Bootstrap.DataAccess
/// 查询某个用户所拥有的角色
/// </summary>
/// <returns></returns>
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";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@UserID", userId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
roles.Add(new Role()
{
Id = reader[0].ToString(),
RoleName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return roles;
}
public virtual IEnumerable<Role> RetrievesByUserId(string userId) => DbManager.Db.Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join UserRole ur on r.ID = ur.RoleID and UserID = @0", userId);
/// <summary>
/// 删除角色表
/// </summary>
/// <param name="value"></param>
public virtual bool DeleteRole(IEnumerable<string> value)
public virtual bool Delete(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"delete from UserRole where RoleID in ({ids})"))
{
try
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from RoleGroup where RoleID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from NavigationRole where RoleID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Roles where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
}
db.BeginTransaction();
db.Execute($"delete from UserRole where RoleID in ({ids})");
db.Execute($"delete from RoleGroup where RoleID in ({ids})");
db.Execute($"delete from NavigationRole where RoleID in ({ids})");
db.Execute($"delete from Roles where ID in ({ids})");
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
@ -174,22 +101,13 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public virtual bool SaveRole(Role p)
public virtual bool Save(Role p)
{
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 = 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))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ID", p.Id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleName", p.RoleName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Description", DbAdapterManager.ToDBValue(p.Description)));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
DbManager.Db.Save(p);
return true;
}
/// <summary>
@ -197,27 +115,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="menuId"></param>
/// <returns></returns>
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>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@NavigationID", menuId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
roles.Add(new Role()
{
Id = reader[0].ToString(),
RoleName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return roles;
}
public virtual IEnumerable<Role> RetrievesByMenuId(string menuId) => DbManager.Db.Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join NavigationRole ur on r.ID = ur.RoleID and NavigationID = @0", menuId);
/// <summary>
///
@ -225,42 +123,23 @@ namespace Bootstrap.DataAccess
/// <param name="menuId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public virtual bool SavaRolesByMenuId(string menuId, IEnumerable<string> roleIds)
public virtual bool SavaByMenuId(string menuId, IEnumerable<string> roleIds)
{
var ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("NavigationID", typeof(int));
dt.Columns.Add("RoleID", typeof(int));
//判断用户是否选定角色
roleIds.ToList().ForEach(roleId => dt.Rows.Add(menuId, roleId));
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
db.BeginTransaction();
try
{
try
{
// delete role from config table
string sql = $"delete from NavigationRole where NavigationID = {menuId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
bulk.BatchSize = 1000;
bulk.DestinationTableName = "NavigationRole";
bulk.ColumnMappings.Add("NavigationID", "NavigationID");
bulk.ColumnMappings.Add("RoleID", "RoleID");
bulk.WriteToServer(dt);
transaction.CommitTransaction();
}
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
// delete role from config table
db.Execute("delete from NavigationRole where NavigationID = @0", menuId);
db.InsertBulk("NavigationRole", roleIds.Select(g => new { NavigationID = menuId, RoleID = g }));
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
@ -270,27 +149,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
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";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
roles.Add(new Role()
{
Id = reader[0].ToString(),
RoleName = (string)reader[1],
Description = reader.IsDBNull(2) ? string.Empty : (string)reader[2],
Checked = (string)reader[3]
});
}
}
return roles;
}
public virtual IEnumerable<Role> RetrievesByGroupId(string groupId) => DbManager.Db.Fetch<Role>("select r.ID, r.RoleName, r.Description, case ur.RoleID when r.ID then 'checked' else '' end Checked from Roles r left join RoleGroup ur on r.ID = ur.RoleID and GroupID = @0", groupId);
/// <summary>
/// 根据GroupId更新Roles信息删除旧的Roles信息插入新的Roles信息
@ -298,42 +157,22 @@ namespace Bootstrap.DataAccess
/// <param name="groupId"></param>
/// <param name="roleIds"></param>
/// <returns></returns>
public virtual bool SaveRolesByGroupId(string groupId, IEnumerable<string> roleIds)
public virtual bool SaveByGroupId(string groupId, IEnumerable<string> roleIds)
{
var ret = false;
//构造表格
DataTable dt = new DataTable();
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
roleIds.ToList().ForEach(roleId => dt.Rows.Add(roleId, groupId));
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
// delete user from config table
string sql = $"delete from RoleGroup where GroupID = {groupId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
// insert batch data into config table
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
bulk.BatchSize = 1000;
bulk.DestinationTableName = "RoleGroup";
bulk.ColumnMappings.Add("RoleID", "RoleID");
bulk.ColumnMappings.Add("GroupID", "GroupID");
bulk.WriteToServer(dt);
transaction.CommitTransaction();
}
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
// delete user from config table
db.Execute("delete from RoleGroup where GroupID = @0", groupId);
db.InsertBulk("RoleGroup", roleIds.Select(g => new { GroupID = groupId, RoleID = g }));
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}

View File

@ -1,72 +1,57 @@
using Longbow;
using System;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
namespace Bootstrap.DataAccess
{
/// <summary>
///
/// </summary>
public class Task
{
/// <summary>
/// 获取/设置 任务ID
/// </summary>
public string Id { get; set; }
/// <summary>
/// 获取/设置 任务名称
/// </summary>
public string TaskName { get; set; }
/// <summary>
/// 获取/设置 分配人
/// </summary>
public string AssignName { get; set; }
/// <summary>
/// 获得/设置 分配人昵称
/// </summary>
public string AssignDisplayName { get; set; }
/// <summary>
/// 获取/设置 完成任务人
/// </summary>
public string UserName { get; set; }
/// <summary>
/// 获取/设置 任务所需时间(天)
/// </summary>
public int TaskTime { get; set; }
/// <summary>
/// 获取/设置 任务进度
/// </summary>
public double TaskProgress { get; set; }
/// <summary>
/// 获取/设置 分配时间
/// </summary>
public DateTime AssignTime { get; set; }
/// <summary>
/// 查询所有任务
/// </summary>
/// <returns></returns>
public virtual IEnumerable<Task> RetrieveTasks()
{
string sql = "select top 100 t.*, u.DisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc";
List<Task> tasks = new List<Task>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
tasks.Add(new Task()
{
Id = reader[0].ToString(),
TaskName = (string)reader[1],
AssignName = (string)reader[2],
UserName = (string)reader[3],
TaskTime = (int)reader[4],
TaskProgress = (double)reader[5],
AssignTime = LgbConvert.ReadValue(reader[6], DateTime.MinValue),
AssignDisplayName = (string)reader[7]
});
}
}
return tasks;
}
public virtual IEnumerable<Task> Retrieves() => DbManager.Db.SkipTake<Task>(0, 1000, "select t.*, u.DisplayName AssignDisplayName from Tasks t inner join Users u on t.UserName = u.UserName order by AssignTime desc");
}
}

View File

@ -1,13 +1,8 @@
using Bootstrap.Security;
using Bootstrap.Security.DataAccess;
using Longbow;
using Longbow.Data;
using Longbow.Security.Cryptography;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
namespace Bootstrap.DataAccess
@ -21,46 +16,57 @@ namespace Bootstrap.DataAccess
/// 获得/设置 用户主键ID
/// </summary>
public string Id { get; set; }
/// <summary>
/// 获取/设置 密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 获取/设置 密码盐
/// </summary>
public string PassSalt { get; set; }
/// <summary>
/// 获取/设置 角色用户关联状态 checked 标示已经关联 '' 标示未关联
/// </summary>
public string Checked { get; set; }
/// <summary>
/// 获得/设置 用户注册时间
/// </summary>
public DateTime RegisterTime { get; set; }
/// <summary>
/// 获得/设置 用户被批复时间
/// </summary>
public DateTime ApprovedTime { get; set; }
public DateTime? ApprovedTime { get; set; }
/// <summary>
/// 获得/设置 用户批复人
/// </summary>
public string ApprovedBy { get; set; }
/// <summary>
/// 获得/设置 用户的申请理由
/// </summary>
public string Description { get; set; }
/// <summary>
/// 获得/设置 用户当前状态 0 表示管理员注册用户 1 表示用户注册 2 表示更改密码 3 表示更改个人皮肤 4 表示更改显示名称 5 批复新用户注册操作
/// </summary>
public UserStates UserStatus { get; set; }
/// <summary>
/// 获得/设置 通知描述 2分钟内为刚刚
/// </summary>
public string Period { get; set; }
/// <summary>
/// 获得/设置 新密码
/// </summary>
public string NewPassword { get; set; }
/// <summary>
/// 验证用户登陆账号与密码正确
/// </summary>
@ -69,25 +75,11 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public virtual bool Authenticate(string userName, string password)
{
if (string.IsNullOrEmpty(userName) && string.IsNullOrEmpty(password)) return false;
string oldPassword = null;
string passwordSalt = null;
string sql = "select Password, PassSalt from Users where ApprovedTime is not null and UserName = @UserName";
var db = DbAccessManager.DBAccess;
using (DbCommand cmd = db.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(db.CreateParameter("@UserName", userName));
using (DbDataReader reader = db.ExecuteReader(cmd))
{
if (reader.Read())
{
oldPassword = (string)reader[0];
passwordSalt = (string)reader[1];
}
}
}
return !string.IsNullOrEmpty(passwordSalt) && oldPassword == LgbCryptography.ComputeHash(password, passwordSalt);
var user = DbManager.Db.SingleOrDefault<User>("select Password, PassSalt from Users where ApprovedTime is not null and UserName = @0", userName);
return !string.IsNullOrEmpty(user.PassSalt) && user.Password == LgbCryptography.ComputeHash(password, user.PassSalt);
}
/// <summary>
///
/// </summary>
@ -100,159 +92,87 @@ namespace Bootstrap.DataAccess
bool ret = false;
if (Authenticate(userName, password))
{
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
string sql = "set Password = @0, PassSalt = @1 where UserName = @2";
var passSalt = LgbCryptography.GenerateSalt();
var newPassword = LgbCryptography.ComputeHash(newPass, passSalt);
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
ret = DbManager.Db.Update<User>(sql, newPassword, passSalt, userName) == 1;
}
return ret;
}
/// <summary>
/// 查询所有用户
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public virtual IEnumerable<User> RetrieveUsers()
{
List<User> users = new List<User>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
public virtual IEnumerable<User> Retrieves() => DbManager.Db.Fetch<User>("select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
users.Add(new User()
{
Id = reader[0].ToString(),
UserName = (string)reader[1],
DisplayName = (string)reader[2],
RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue),
ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5],
Description = (string)reader[6]
});
}
}
return users;
}
/// <summary>
/// 查询所有的新注册用户
/// </summary>
/// <returns></returns>
public virtual IEnumerable<User> RetrieveNewUsers()
{
string sql = "select ID, UserName, DisplayName, RegisterTime, Description from Users Where ApprovedTime is null order by RegisterTime desc";
List<User> users = new List<User>();
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
users.Add(new User()
{
Id = reader[0].ToString(),
UserName = (string)reader[1],
DisplayName = (string)reader[2],
RegisterTime = LgbConvert.ReadValue(reader[3], DateTime.MinValue),
Description = (string)reader[4]
});
}
}
return users;
}
public virtual IEnumerable<User> RetrieveNewUsers() => DbManager.Db.Fetch<User>("select ID, UserName, DisplayName, RegisterTime, Description from Users Where ApprovedTime is null order by RegisterTime desc");
/// <summary>
/// 删除用户
/// </summary>
/// <param name="value"></param>
public virtual bool DeleteUser(IEnumerable<string> value)
public virtual bool Delete(IEnumerable<string> value)
{
bool ret = false;
var ids = string.Join(",", value);
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"Delete from UserRole where UserID in ({ids})"))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from UserGroup where UserID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from Users where ID in ({ids})";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
var ids = string.Join(",", value);
db.BeginTransaction();
db.Execute($"Delete from UserRole where UserID in ({ids})");
db.Execute($"delete from UserGroup where UserID in ({ids})");
db.Execute($"delete from Users where ID in ({ids})");
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
/// <summary>
/// 新建前台User View调用/注册用户调用
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public virtual bool SaveUser(User p)
public virtual bool Save(User p)
{
var ret = false;
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);
p.RegisterTime = DateTime.Now;
var db = DbAccessManager.DBAccess;
using (TransactionPackage transaction = db.BeginTransaction())
var db = DbManager.Db;
try
{
try
db.BeginTransaction();
if (!db.Exists<User>("where UserName = @0", p.UserName))
{
using (DbCommand cmd = db.CreateCommand(CommandType.Text, "select UserName from Users Where UserName = @userName"))
{
cmd.Parameters.Add(db.CreateParameter("@userName", p.UserName));
var un = db.ExecuteScalar(cmd, transaction);
if (DbAdapterManager.ToObjectValue(un) == null)
{
object approveTime = DBNull.Value;
if (p.ApprovedTime != DateTime.MinValue) approveTime = p.ApprovedTime;
cmd.CommandText = "Insert Into Users (UserName, Password, PassSalt, DisplayName, RegisterTime, ApprovedBy, ApprovedTime, Description) values (@userName, @password, @passSalt, @displayName, @registerTime, @approvedBy, @approveTime, @description)";
cmd.Parameters.Add(db.CreateParameter("@password", p.Password));
cmd.Parameters.Add(db.CreateParameter("@passSalt", p.PassSalt));
cmd.Parameters.Add(db.CreateParameter("@registerTime", DateTime.Now));
cmd.Parameters.Add(db.CreateParameter("@displayName", p.DisplayName));
cmd.Parameters.Add(db.CreateParameter("@approvedBy", DbAdapterManager.ToDBValue(p.ApprovedBy)));
cmd.Parameters.Add(db.CreateParameter("@approveTime", approveTime));
cmd.Parameters.Add(db.CreateParameter("@description", p.Description));
db.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"insert into UserRole (UserID, RoleID) select ID, (select ID from Roles where RoleName = 'Default') RoleId from Users where UserName = '{p.UserName}'";
cmd.Parameters.Clear();
db.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
}
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
db.Insert(p);
db.Execute("insert into UserRole (UserID, RoleID) select ID, (select ID from Roles where RoleName = 'Default') RoleId from Users where UserName = @0", p.UserName);
}
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
/// <summary>
/// User List 视图保存按钮调用
/// </summary>
@ -260,278 +180,148 @@ namespace Bootstrap.DataAccess
/// <param name="password"></param>
/// <param name="displayName"></param>
/// <returns></returns>
public virtual bool UpdateUser(string id, string password, string displayName)
public virtual bool Update(string id, string password, string displayName)
{
bool ret = false;
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt, DisplayName = @DisplayName where ID = @id";
var passSalt = LgbCryptography.GenerateSalt();
var newPassword = LgbCryptography.ComputeHash(password, passSalt);
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@Password", newPassword));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@PassSalt", passSalt));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
return DbManager.Db.Update<User>("set Password = @1, PassSalt = @2, DisplayName = @3 where ID = @0", id, newPassword, passSalt, displayName) == 1;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="approvedBy"></param>
/// <returns></returns>
public virtual bool ApproveUser(string id, string approvedBy)
{
var ret = false;
var sql = "update Users set ApprovedTime = @ApproveTime, ApprovedBy = @approvedBy where ID = @id";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@id", id));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@ApproveTime", DateTime.Now, DbType.DateTime));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@approvedBy", approvedBy));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
}
public virtual bool Approve(string id, string approvedBy) => DbManager.Db.Update<User>("set ApprovedTime = @1, ApprovedBy = @2 where ID = @0", id, DateTime.Now, approvedBy) == 1;
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="rejectBy"></param>
/// <returns></returns>
public virtual bool RejectUser(string id, string rejectBy)
public virtual bool Reject(string id, string rejectBy)
{
var ret = false;
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, $"insert into RejectUsers (UserName, DisplayName, RegisterTime, RejectedBy, RejectedTime, RejectedReason) select UserName, DisplayName, Registertime, '{rejectBy}', @RejectTime, '未填写' from Users where ID = {id}"))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RejectTime", DateTime.Now, DbType.DateTime));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.Parameters.Clear();
cmd.CommandText = $"delete from UserRole where UserId = {id}";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from UserGroup where UserId = {id}";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
cmd.CommandText = $"delete from users where ID = {id}";
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
transaction.CommitTransaction();
ret = true;
}
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
db.BeginTransaction();
db.Execute("insert into RejectUsers (UserName, DisplayName, RegisterTime, RejectedBy, RejectedTime, RejectedReason) select UserName, DisplayName, Registertime, @1, @2, @3 from Users where ID = @0", id, rejectBy, DateTime.Now, "未填写");
db.Execute("delete from UserRole where UserId = @0", id);
db.Execute("delete from UserGroup where UserId = @0", id);
db.Execute("delete from users where ID = @0", id);
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
/// <summary>
/// 通过roleId获取所有用户
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
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";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@RoleID", roleId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
users.Add(new User()
{
Id = reader[0].ToString(),
UserName = (string)reader[1],
DisplayName = (string)reader[2],
Checked = (string)reader[3]
});
}
}
return users;
}
public virtual IEnumerable<User> RetrievesByRoleId(string roleId) => DbManager.Db.Fetch<User>("select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end Checked from Users u left join UserRole ur on u.ID = ur.UserID and RoleID = @0 where u.ApprovedTime is not null", roleId);
/// <summary>
/// 通过角色ID保存当前授权用户插入
/// </summary>
/// <param name="roleId">角色ID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public virtual bool SaveUsersByRoleId(string roleId, IEnumerable<string> userIds)
public virtual bool SaveByRoleId(string roleId, IEnumerable<string> userIds)
{
bool ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("RoleID", typeof(int));
dt.Columns.Add("UserID", typeof(int));
userIds.ToList().ForEach(userId => dt.Rows.Add(roleId, userId));
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
//删除用户角色表该角色所有的用户
string sql = $"delete from UserRole where RoleID = {roleId}";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
bulk.DestinationTableName = "UserRole";
bulk.ColumnMappings.Add("RoleID", "RoleID");
bulk.ColumnMappings.Add("UserID", "UserID");
bulk.WriteToServer(dt);
transaction.CommitTransaction();
}
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
db.BeginTransaction();
//删除用户角色表该角色所有的用户
db.Execute("delete from UserRole where RoleID = @0", roleId);
db.InsertBulk("UserRole", userIds.Select(g => new { UserID = g, RoleID = roleId }));
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
/// <summary>
/// 通过groupId获取所有用户
/// </summary>
/// <param name="groupId"></param>
/// <returns></returns>
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";
DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql);
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
using (DbDataReader reader = DbAccessManager.DBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
users.Add(new User()
{
Id = reader[0].ToString(),
UserName = (string)reader[1],
DisplayName = (string)reader[2],
Checked = (string)reader[3]
});
}
}
return users;
}
public virtual IEnumerable<User> RetrievesByGroupId(string groupId) => DbManager.Db.Fetch<User>("select u.ID, u.UserName, u.DisplayName, case ur.UserID when u.ID then 'checked' else '' end Checked from Users u left join UserGroup ur on u.ID = ur.UserID and GroupID = @0 where u.ApprovedTime is not null", groupId);
/// <summary>
/// 通过部门ID保存当前授权用户插入
/// </summary>
/// <param name="groupId">GroupID</param>
/// <param name="userIds">用户ID数组</param>
/// <returns></returns>
public virtual bool SaveUsersByGroupId(string groupId, IEnumerable<string> userIds)
public virtual bool SaveByGroupId(string groupId, IEnumerable<string> userIds)
{
bool ret = false;
DataTable dt = new DataTable();
dt.Columns.Add("UserID", typeof(int));
dt.Columns.Add("GroupID", typeof(int));
userIds.ToList().ForEach(userId => dt.Rows.Add(userId, groupId));
using (TransactionPackage transaction = DbAccessManager.DBAccess.BeginTransaction())
var db = DbManager.Db;
try
{
try
{
//删除用户角色表该角色所有的用户
string sql = "delete from UserGroup where GroupID = @GroupID";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@GroupID", groupId));
DbAccessManager.DBAccess.ExecuteNonQuery(cmd, transaction);
//批插入用户角色表
using (SqlBulkCopy bulk = new SqlBulkCopy((SqlConnection)transaction.Transaction.Connection, SqlBulkCopyOptions.Default, (SqlTransaction)transaction.Transaction))
{
bulk.DestinationTableName = "UserGroup";
bulk.ColumnMappings.Add("UserID", "UserID");
bulk.ColumnMappings.Add("GroupID", "GroupID");
bulk.WriteToServer(dt);
transaction.CommitTransaction();
}
}
ret = true;
}
catch (Exception ex)
{
transaction.RollbackTransaction();
throw ex;
}
db.BeginTransaction();
//删除用户角色表该角色所有的用户
db.Execute("delete from UserGroup where GroupID = @0", groupId);
db.InsertBulk("UserGroup", userIds.Select(g => new { UserID = g, GroupID = groupId }));
db.CompleteTransaction();
ret = true;
}
catch (Exception ex)
{
db.AbortTransaction();
throw ex;
}
return ret;
}
/// <summary>
/// 根据用户名修改用户头像
/// </summary>
/// <param name="userName"></param>
/// <param name="iconName"></param>
/// <returns></returns>
public virtual bool SaveUserIconByName(string userName, string iconName)
{
bool ret = false;
string sql = "Update Users set Icon = @iconName where UserName = @userName";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@iconName", iconName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
}
public virtual bool SaveUserIconByName(string userName, string iconName) => DbManager.Db.Update<User>("set Icon = @1 where UserName = @0", userName, iconName) == 1;
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <param name="displayName"></param>
/// <returns></returns>
public virtual bool SaveDisplayName(string userName, string displayName)
{
bool ret = false;
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@DisplayName", displayName));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
}
public virtual bool SaveDisplayName(string userName, string displayName) => DbManager.Db.Update<User>("set DisplayName = @1 where UserName = @0", userName, displayName) == 1;
/// <summary>
/// 根据用户名更改用户皮肤
/// </summary>
/// <param name="userName"></param>
/// <param name="cssName"></param>
/// <returns></returns>
public virtual bool SaveUserCssByName(string userName, string cssName)
{
bool ret = false;
string sql = "Update Users set Css = @cssName where UserName = @userName";
using (DbCommand cmd = DbAccessManager.DBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@cssName", DbAdapterManager.ToDBValue(cssName)));
cmd.Parameters.Add(DbAccessManager.DBAccess.CreateParameter("@userName", userName));
ret = DbAccessManager.DBAccess.ExecuteNonQuery(cmd) == 1;
}
return ret;
}
public virtual bool SaveUserCssByName(string userName, string cssName) => DbManager.Db.Update<User>("set Css = @1 where UserName = @0", userName, cssName) == 1;
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public virtual BootstrapUser RetrieveUserByUserName(string userName) => DbHelper.RetrieveUserByUserName(userName);
/// <summary>
///
/// </summary>
@ -541,6 +331,7 @@ namespace Bootstrap.DataAccess
return string.Format("{0} ({1})", UserName, DisplayName);
}
}
/// <summary>
///
/// </summary>

View File

@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2047
# Visual Studio Version 16
VisualStudioVersion = 16.0.28407.52
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLServer", "SQLServer", "{87319AF5-7C40-4362-B67C-35F9DD737DB4}"
ProjectSection(SolutionItems) = preProject
@ -31,8 +31,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.Client.DataAccess
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess", "Bootstrap.DataAccess\Bootstrap.DataAccess.csproj", "{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess.SQLite", "Bootstrap.DataAccess.SQLite\Bootstrap.DataAccess.SQLite.csproj", "{BC18A24F-5C99-4DF5-803D-72A912BCBD57}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SQLite", "SQLite", "{523515EC-2AD7-4282-9AF4-9D20371183B0}"
ProjectSection(SolutionItems) = preProject
DatabaseScripts\SQLite\InitData.sql = DatabaseScripts\SQLite\InitData.sql
@ -56,7 +54,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MySQL", "MySQL", "{084E2E94
DatabaseScripts\MySQL\install.sql = DatabaseScripts\MySQL\install.sql
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Bootstrap.DataAccess.MySQL", "Bootstrap.DataAccess.MySQL\Bootstrap.DataAccess.MySQL.csproj", "{B6877AEA-EC65-47DA-BA6E-FD657729C285}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UniTest", "UniTest\UniTest.csproj", "{1019D84F-2D0E-4976-947E-10AB16A4E53F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -80,18 +78,14 @@ Global
{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D62BE79-BE13-43C8-969B-C9B00B3C84B7}.Release|Any CPU.Build.0 = Release|Any CPU
{BC18A24F-5C99-4DF5-803D-72A912BCBD57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{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
{B6877AEA-EC65-47DA-BA6E-FD657729C285}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B6877AEA-EC65-47DA-BA6E-FD657729C285}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B6877AEA-EC65-47DA-BA6E-FD657729C285}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6877AEA-EC65-47DA-BA6E-FD657729C285}.Release|Any CPU.Build.0 = Release|Any CPU
{1019D84F-2D0E-4976-947E-10AB16A4E53F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1019D84F-2D0E-4976-947E-10AB16A4E53F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1019D84F-2D0E-4976-947E-10AB16A4E53F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1019D84F-2D0E-4976-947E-10AB16A4E53F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -25,6 +25,7 @@ INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'消息状
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'消息标签', N'一般', N'0', 0)
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'消息标签', N'紧要', N'1', 0)
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'头像地址', N'头像路径', N'~/images/uploader/', 0)
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'头像地址', N'头像文件', N'default.jpg', 0)
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站样式', N'蓝色样式', N'blue.css', 0)
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'网站样式', N'黑色样式', N'black.css', 0)
INSERT [dbo].[Dicts] ([Category], [Name], [Code], [Define]) VALUES (N'当前样式', N'使用样式', N'blue.css', 0)

View File

@ -1,268 +1,275 @@
[
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a13"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a13\")",
"Category": "菜单",
"Name": "系统菜单",
"Code": "0",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a14"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a14\")",
"Category": "菜单",
"Name": "外部菜单",
"Code": "1",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a15"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a15\")",
"Category": "应用程序",
"Name": "未设置",
"Code": "0",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a16"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a16\")",
"Category": "网站设置",
"Name": "网站标题",
"Code": "后台管理系统",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a17"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a17\")",
"Category": "网站设置",
"Name": "网站页脚",
"Code": "2016 © 通用后台管理系统",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a18"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a18\")",
"Category": "系统通知",
"Name": "用户注册",
"Code": "0",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a19"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a19\")",
"Category": "系统通知",
"Name": "程序异常",
"Code": "1",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a1a"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1a\")",
"Category": "系统通知",
"Name": "数据库连接",
"Code": "2",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a1b"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1b\")",
"Category": "通知状态",
"Name": "未处理",
"Code": "0",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a1c"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1c\")",
"Category": "通知状态",
"Name": "已处理",
"Code": "1",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a1d"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1d\")",
"Category": "处理结果",
"Name": "同意",
"Code": "0",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a1e"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1e\")",
"Category": "处理结果",
"Name": "拒绝",
"Code": "1",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a1f"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a1f\")",
"Category": "消息状态",
"Name": "未读",
"Code": "0",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a20"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a20\")",
"Category": "消息状态",
"Name": "已读",
"Code": "1",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a21"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a21\")",
"Category": "消息标签",
"Name": "一般",
"Code": "0",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a22"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a22\")",
"Category": "消息标签",
"Name": "紧要",
"Code": "1",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a23"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a23\")",
"Category": "头像地址",
"Name": "头像路径",
"Code": "~/images/uploader/",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a24"),
"_id": "ObjectId(\"4bd6c73d5fa31256f77e4a23\")",
"Category": "头像地址",
"Name": "头像文件",
"Code": "default.jpg",
"Define": "NumberInt(0)"
},
{
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a24\")",
"Category": "当前样式",
"Name": "使用样式",
"Code": "blue.css",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a25"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a25\")",
"Category": "网站设置",
"Name": "前台首页",
"Code": "~/Home/Index",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a26"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a26\")",
"Category": "应用程序",
"Name": "组垛平台",
"Code": "4",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a27"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a27\")",
"Category": "组垛平台",
"Name": "网站标题",
"Code": "托盘组垛程序",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a28"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a28\")",
"Category": "组垛平台",
"Name": "网站页脚",
"Code": "版权所有:中烟信息",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a29"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a29\")",
"Category": "组垛平台",
"Name": "个人中心地址",
"Code": "http://localhost:50852/Admin/Profiles",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a2a"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2a\")",
"Category": "组垛平台",
"Name": "系统设置地址",
"Code": "http://localhost:50852/Admin/Index",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a2b"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2b\")",
"Category": "设备厂商",
"Name": "远望谷",
"Code": "Invengo",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a2c"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2c\")",
"Category": "设备厂商",
"Name": "测试",
"Code": "Test",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a2d"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2d\")",
"Category": "远程数据库",
"Name": "组垛数据库",
"Code": "Corp_Scan",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a2e"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2e\")",
"Category": "网站样式",
"Name": "黑色样式",
"Code": "black.css",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a2f"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a2f\")",
"Category": "网站样式",
"Name": "蓝色样式",
"Code": "blue.css",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a30"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a30\")",
"Category": "设备天线",
"Name": "天线1",
"Code": "1",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a31"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a31\")",
"Category": "设备天线",
"Name": "天线2",
"Code": "2",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a32"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a32\")",
"Category": "应用程序",
"Name": "测试平台",
"Code": "2",
"Define": NumberInt(0)
"Define": "NumberInt(0)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a33"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a33\")",
"Category": "测试平台",
"Name": "网站标题",
"Code": "托盘组垛程序",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a34"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a34\")",
"Category": "测试平台",
"Name": "网站页脚",
"Code": "通用后台管理测试平台",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a35"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a35\")",
"Category": "测试平台",
"Name": "个人中心地址",
"Code": "http://localhost:50852/Admin/Profiles",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a36"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a36\")",
"Category": "测试平台",
"Name": "系统设置地址",
"Code": "http://localhost:50852/Admin/Settings",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a37"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a37\")",
"Category": "设备驱动",
"Name": "Invengo",
"Code": "Longbow.Invengo.Device, Longbow.Invengo",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
},
{
"_id": ObjectId("5bd6c73d5fa31256f77e4a38"),
"_id": "ObjectId(\"5bd6c73d5fa31256f77e4a38\")",
"Category": "设备驱动",
"Name": "Test",
"Code": "Pallet.DeviceInterface.Device, Pallet.DeviceHub",
"Define": NumberInt(1)
"Define": "NumberInt(1)"
}
]

View File

@ -22,6 +22,7 @@ INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '消息状态
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '消息标签', '一般', '0', 0);
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '消息标签', '紧要', '1', 0);
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '头像地址', '头像路径', '~/images/uploader/', 0);
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '头像地址', '头像文件', 'default.jpg', 0);
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '网站样式', '蓝色样式', 'blue.css', 0);
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '网站样式', '黑色样式', 'black.css', 0);
INSERT INTO Dicts (ID, Category, Name, Code, Define) VALUES (NULL, '当前样式', '使用样式', 'blue.css', 0);

View File

@ -20,6 +20,7 @@ INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '消息标签', '一般', '0', 0);
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '消息标签', '紧要', '1', 0);
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '头像地址', '头像路径', '~/images/uploader/', 0);
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '头像地址', '头像文件', 'default.jpg', 0);
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站样式', '蓝色样式', 'blue.css', 0);
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '网站样式', '黑色样式', 'black.css', 0);
INSERT INTO [Dicts] ([ID], [Category], [Name], [Code], [Define]) VALUES (NULL, '当前样式', '使用样式', 'blue.css', 0);

View File

@ -1,3 +0,0 @@
<lgb>
<token>tH0NNQQxF3DJiiPpEWlKmsCMOhp/ijYoPnWvpjAH9Nfph06YjvCg6SBgs0SLGKrp+pHKey0Lf/wN94bR7/TYcsHrX20WvxvhBPmk2REJxLyqn6M+fAQAX++XZsQH9ywhgZaM2maGN+cXO+y+5aXGvUYKKOL6dxCIRBSNtAl21swA</token>
</lgb>

View File

@ -1,4 +0,0 @@
D:
cd "D:\src\Longbow\BootstrapAdmin\Publish\Web-App\WebConsole\bin"
rem xcopy "C:\Longbow.Utility 2005\Release\Longbow.ComponentModel.dll" /f /y
rem call "D:\src\Longbow\Scripts\LgbSign.bat" OutFactoryScanContracts.dll Release Manual

View File

@ -1,124 +0,0 @@
Option Explicit
Dim fso, shell
Dim targetDir, targetName, extName, keyFile, destDir, solutionDir, cmd, file, assemblyDir, outDir, batFile, signCmd
Dim msg(), m
keyFile = "..\Keys\Longbow.Utility.snk"
destDir = "Publish\Web-App\WebConsole"
assemblyDir = "C:\Longbow.Utility 2005\Release"
batFile = "..\Scripts\LgbSign.bat"
signCmd = "%ProgramFiles(x86)%\Microsoft SDKs\Windows\v7.0A\bin\sn.exe"
Set shell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
If WScript.Arguments.Count > 0 Then
targetDir = WScript.Arguments(0)
End If
If WScript.Arguments.Count > 1 Then
targetName = WScript.Arguments(1)
End If
If WScript.Arguments.Count > 2 Then
extName = WScript.Arguments(2)
End If
If WScript.Arguments.Count > 3 Then
solutionDir = WScript.Arguments(3)
keyFile = solutionDir & keyFile
destDir = solutionDir & destDir
batFile = solutionDir & batFile
End If
If WScript.Arguments.Count > 4 Then
outDir = WScript.Arguments(4)
End If
If WScript.Arguments.Count > 5 Then
If WScript.Arguments(5) = "Debug" Then
ReSignFile targetDir & targetName & extName
WScript.Echo WScript.Arguments(5) & " Mode... Quit copy AFTER Re-signed assembly"
WScript.Quit
Else
If extName = ".dll" Then
WScript.Echo WScript.Arguments(5) & " Mode... Quit copy BEFORE Re-signed assembly"
WScript.Quit
End If
End If
End If
destDir = destdir & targetName & "\"
If NOT fso.FolderExists(destDir) then
fso.CreateFolder(destDir)
End If
If NOT fso.FolderExists(destdir & "Original\") then
fso.CreateFolder(destdir & "Original\")
End If
If extName = ".exe" Then
CopyFile fso, targetDir, destDir, targetName & extName & ".config", true
End If
CopyFile fso, targetDir, destdir & "Original\", targetName & extName, true
ReDim msg(0)
msg(0) = """" & batFile & """ """ & destdir & targetName & extName & """ """ & keyFile
For Each file in fso.GetFolder(targetDir).Files
If fso.GetExtensionName(file) = "dll" then
If NOT CopyFile(fso, assemblyDir, destDir, file.Name, false) Then
ReDim Preserve msg(UBound(msg)+1)
msg(UBound(msg)) = """" & signCmd & """ """ & destdir & file.Name & """"
CopyFile fso, solutionDir & GetFileName(file.Name) & "\" & outDir, destDir & "Original\", file.Name, true
ReSignFile targetdir & file.Name
Else
CopyFile fso, assemblyDir, destDir & "Original\", file.Name, true
End If
End If
Next
ReSignFile targetDir & targetName & extName
Wscript.Echo "Ready for DotFuscator... After Dotfuscator run the following command Please!"
For Each m in msg
Wscript.Echo m
Next
Function CopyFile(fso, targetDir, destDir, targetName, show)
If fso.FileExists(targetDir & targetName) then
fso.CopyFile targetDir & targetName, destDir & targetName, True
Wscript.Echo targetDir & targetName & " --> " & destDir & targetName & " Copied!"
CopyFile = True
Else
If show then
Wscript.Echo "Missing " & targetDir & targetName & " Not Copied!"
end if
CopyFile = False
End If
End Function
Function GetFileName(fileName)
Dim pos, index
index = 1
Do
pos = index + 1
index = InStr(pos, fileName, ".")
Loop while index > 0
If pos > 0 Then
GetFileName = Left(fileName, pos -2)
Else
GetFileName = fileName
End If
End Function
Sub ReSignFile(fileName)
If Not fso.FileExists(shell.ExpandEnvironmentStrings(signCmd)) Then
signCmd = "%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\sn.exe"
End If
cmd = """"& signCmd &""" -R """ & fileName & """ " & keyFile
shell.run cmd, 0, True
WScript.Echo "Assembly '" & fileName & "' successfully re-signed @_@"
End Sub

View File

@ -0,0 +1,23 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
namespace Bootstrap.DataAccess
{
public class BootstrapAdminStartup
{
public BootstrapAdminStartup()
{
var config = new ConfigurationBuilder().AddInMemoryCollection(new KeyValuePair<string, string>[] {
new KeyValuePair<string, string>("ConnectionStrings:ba", "Data Source=.;Initial Catalog=UnitTest;User ID=sa;Password=sa"),
new KeyValuePair<string, string>("DB:0:Enabled", "false"),
new KeyValuePair<string, string>("LongbowCache:Enabled", "false")
}).Build();
var sc = new ServiceCollection();
sc.AddSingleton<IConfiguration>(config);
sc.AddConfigurationManager(config);
sc.AddCacheManager(config);
sc.AddDbAdapter();
}
}
}

View File

@ -0,0 +1,103 @@
using Xunit;
namespace Bootstrap.DataAccess
{
public class DictsTest : IClassFixture<BootstrapAdminStartup>
{
[Fact]
public void Delete_Ok()
{
var dict = new Dict();
Assert.True(dict.Delete(new string[] { "64", "65" }));
}
[Fact]
public void Save_Ok()
{
var dict = new Dict()
{
Category = "UnitTest",
Name = "Test1",
Code = "1",
Define = 1
};
Assert.True(dict.Save(dict));
}
[Fact]
public void SaveSettings_Ok()
{
var dict = new Dict()
{
Category = "UnitTest",
Name = "Test1",
Code = "1",
Define = 1
};
Assert.True(dict.SaveSettings(dict));
}
[Fact]
public void RetrieveCategories_Ok()
{
var dict = new Dict();
Assert.NotEmpty(dict.RetrieveCategories());
}
[Fact]
public void RetrieveWebTitle_Ok()
{
var dict = new Dict();
Assert.Equal("后台管理系统", dict.RetrieveWebTitle());
}
[Fact]
public void RetrieveWebFooter_Ok()
{
var dict = new Dict();
Assert.Equal("2016 © 通用后台管理系统", dict.RetrieveWebFooter());
}
[Fact]
public void RetrieveThemes_Ok()
{
var dict = new Dict();
Assert.NotEmpty(dict.RetrieveThemes());
}
[Fact]
public void RetrieveActiveTheme_Ok()
{
var dict = new Dict();
Assert.Equal("blue.css", dict.RetrieveActiveTheme());
}
[Fact]
public void RetrieveIconFolderPath_Ok()
{
var dict = new Dict();
Assert.Equal("~/images/uploader/", dict.RetrieveIconFolderPath());
}
[Fact]
public void RetrieveHomeUrl_Ok()
{
var dict = new Dict();
Assert.Equal("~/Home/Index", dict.RetrieveHomeUrl());
}
[Fact]
public void RetrieveApps_Ok()
{
var dict = new Dict();
Assert.NotEmpty(dict.RetrieveApps());
}
[Fact]
public void RetrieveDicts_Ok()
{
var dict = new Dict();
Assert.NotEmpty(dict.RetrieveDicts());
}
}
}

View File

@ -0,0 +1,31 @@
using Longbow.Web.Mvc;
using System;
using Xunit;
namespace Bootstrap.DataAccess
{
public class ExceptionsTest : IClassFixture<BootstrapAdminStartup>
{
[Fact]
public void Log_Ok()
{
Exceptions excep = new Exceptions();
Assert.True(excep.Log(new Exception("UnitTest"), null));
}
[Fact]
public void Retrieves_Ok()
{
Exceptions excep = new Exceptions();
Assert.NotEmpty(excep.Retrieves());
}
[Fact]
public void RetrievePages_Ok()
{
var excep = new Exceptions();
var op = excep.RetrievePages(new PaginationOption() { Offset = 0, Limit = 20, Sort = "LogTime", Order = "desc" }, null, null);
Assert.NotNull(op);
}
}
}

View File

@ -0,0 +1,63 @@
using Xunit;
namespace Bootstrap.DataAccess
{
public class GroupsTest : IClassFixture<BootstrapAdminStartup>
{
[Fact]
public void Retrieves_Ok()
{
Group g = new Group();
Assert.NotEmpty(g.Retrieves());
}
[Fact]
public void Save_Ok()
{
Group g = new Group() { GroupName = "UnitTest", Description = "UnitTestSave" };
Assert.True(g.Save(g));
}
[Fact]
public void Delete_Ok()
{
Group g = new Group();
Assert.True(g.Delete(new string[] { "12", "13" }));
}
[Fact]
public void RetrievesByRoleId_Ok()
{
Group p = new Group();
var groups = p.RetrievesByRoleId("1");
}
[Fact]
public void RetrievesByUserId_Ok()
{
Group p = new Group();
var groups = p.RetrievesByUserId("1");
}
[Fact]
public void SaveByUserId_Ok()
{
Group p = new Group();
var groups = p.SaveByUserId("1", new string[] { "1", "2", "3" });
}
[Fact]
public void SaveByRoleId_Ok()
{
Group p = new Group();
var groups = p.SaveByRoleId("1", new string[] { "1", "2" });
}
[Fact]
public void RetrievesByUserName_Ok()
{
Group p = new Group();
Assert.NotEmpty(p.RetrievesByUserName("Admin"));
}
}
}

View File

@ -0,0 +1,28 @@
using Xunit;
namespace Bootstrap.DataAccess
{
public class LogsTest : IClassFixture<BootstrapAdminStartup>
{
[Fact]
public void Save_Ok()
{
var log = new Log()
{
UserName = "UnitTest",
ClientAgent = "UnitTest-Agent",
ClientIp = "::",
CRUD = "UnitTest",
RequestUrl = "~/Home/Index"
};
Assert.True(log.Save(log));
}
[Fact]
public void Retrieves_Ok()
{
var log = new Log();
Assert.NotEmpty(log.Retrieves());
}
}
}

View File

@ -0,0 +1,54 @@
using Xunit;
namespace Bootstrap.DataAccess
{
public class MenusTest : IClassFixture<BootstrapAdminStartup>
{
[Fact]
public void Save_Ok()
{
var m = new Menu()
{
Name = "UnitTest",
Application = "0",
Category = "0",
Icon = "fa fa-fa",
IsResource = 0,
Target = "_blank",
Order = 10,
Url = "#",
ParentId = "0"
};
Assert.True(m.Save(m));
}
[Fact]
public void RetrieveMenusByRoleId_Ok()
{
var m = new Menu();
Assert.NotEmpty(m.RetrieveMenusByRoleId("1"));
}
[Fact]
public void Delete_Ok()
{
var m = new Menu();
Assert.True(m.Delete(new string[] { "452" }));
}
[Fact]
public void RetrieveAllMenus_Ok()
{
var m = new Menu();
Assert.NotEmpty(m.RetrieveAllMenus("Admin"));
}
[Fact]
public void SaveMenusByRoleId_Ok()
{
var m = new Menu();
Assert.True(m.SaveMenusByRoleId("1", new string[] { "450", "451" }));
}
}
}

View File

@ -0,0 +1,14 @@
using Xunit;
namespace Bootstrap.DataAccess
{
public class MessagesTest : IClassFixture<BootstrapAdminStartup>
{
[Fact]
public void RetrieveHeaders_Ok()
{
var m = new Message();
m.RetrieveHeaders("Admin");
}
}
}

View File

@ -0,0 +1,83 @@
using Xunit;
namespace Bootstrap.DataAccess
{
public class RolesTest : IClassFixture<BootstrapAdminStartup>
{
[Fact]
public void SaveRolesByUserId_Ok()
{
var role = new Role();
Assert.True(role.SaveByUserId("1", new string[] { "1", "2" }));
}
[Fact]
public void RetrieveRolesByUserId_Ok()
{
var role = new Role();
Assert.NotEmpty(role.RetrievesByUserId("1"));
}
[Fact]
public void DeleteRole_Ok()
{
var role = new Role()
{
Description = "Role_Desc",
RoleName = "UnitTest"
};
role.Save(role);
Assert.True(role.Delete(new string[] { role.Id.ToString() }));
}
[Fact]
public void SaveRole_Ok()
{
var role = new Role()
{
Description = "Role_Desc",
RoleName = "UnitTest"
};
Assert.True(role.Save(role));
}
[Fact]
public void RetrieveRolesByMenuId_Ok()
{
var menu = new Menu();
menu.SaveMenusByRoleId("1", new string[] { "1" });
var role = new Role();
var rs = role.RetrievesByMenuId("1");
Assert.Contains(rs, r => r.Checked == "checked");
}
[Fact]
public void SavaRolesByMenuId_Ok()
{
var role = new Role();
Assert.True(role.SavaByMenuId("1", new string[] { "1" }));
}
[Fact]
public void RetrieveRolesByGroupId_Ok()
{
var role = new Role();
Assert.Contains(role.RetrievesByGroupId("1"), r => r.Checked == "checked");
}
[Fact]
public void RetrieveRolesByUserName_Ok()
{
var role = new Role();
Assert.NotEmpty(role.RetrieveRolesByUserName("Admin"));
}
[Fact]
public void RetrieveRolesByUrl_Ok()
{
var role = new Role();
Assert.NotEmpty(role.RetrieveRolesByUrl("~/Home/Index"));
}
}
}

View File

@ -0,0 +1,15 @@
using System.Linq;
using Xunit;
namespace Bootstrap.DataAccess
{
public class TasksTest : IClassFixture<BootstrapAdminStartup>
{
[Fact]
public void Retrieves_Ok()
{
var t = new Task();
Assert.Equal(Enumerable.Empty<Task>(), t.Retrieves());
}
}
}

View File

@ -0,0 +1,135 @@
using System;
using Xunit;
namespace Bootstrap.DataAccess
{
/// <summary>
///
/// </summary>
public class UsersTest : IClassFixture<BootstrapAdminStartup>
{
/// <summary>
///
/// </summary>
[Fact]
public void Authenticate_Ok()
{
var u = new User();
Assert.True(u.Authenticate("Admin", "123789"));
}
[Fact]
public void ChangePassword_Ok()
{
var u = new User();
Assert.True(u.ChangePassword("Admin", "123789", "123789"));
}
[Fact]
public void Retrieves_Ok()
{
var u = new User();
Assert.NotEmpty(u.Retrieves());
}
[Fact]
public void RetrieveNewUsers_Ok()
{
var u = new User();
Assert.Empty(u.RetrieveNewUsers());
}
[Fact]
public void Update_Ok()
{
var u = new User();
Assert.True(u.Update("1", "123789", "Administrators"));
}
[Fact]
public void ApproveUser_Ok()
{
var u = new User();
Assert.True(u.Approve("3", "Administrators"));
}
[Fact]
public void RetrieveUsersByRoleId_Ok()
{
var u = new User();
var users = u.RetrievesByRoleId("1");
Assert.NotEmpty(users);
Assert.Contains(users, usr => usr.Checked == "checked");
}
[Fact]
public void RetrievesByGroupId_Ok()
{
var u = new User();
var users = u.RetrievesByGroupId("1");
Assert.NotEmpty(users);
Assert.Contains(users, usr => !usr.Checked.IsNullOrEmpty());
}
[Fact]
public void DeleteUser_Ok()
{
var u = new User();
Assert.True(u.Delete(new string[] { "5", "6" }));
}
[Fact]
public void SaveUser_Ok()
{
var u = new User();
Assert.True(u.Save(new User { UserName = "UnitTest", DisplayName = "DisplayName", ApprovedBy = "System", ApprovedTime = DateTime.Now, Description = "Desc", Icon = "default.jpg" }));
}
[Fact]
public void SaveUserIconByName_Ok()
{
var u = new User();
Assert.True(u.SaveUserIconByName("Admin", "default.jpg"));
}
[Fact]
public void SaveDisplayName_Ok()
{
var u = new User();
Assert.True(u.SaveDisplayName("Admin", "Administrators"));
}
[Fact]
public void SaveUserCssByName_Ok()
{
var u = new User();
Assert.True(u.SaveUserCssByName("Admin", "default.css"));
}
[Fact]
public void Reject_Ok()
{
var u = new User();
u.UserName = "UnitTest-Reject";
u.DisplayName = "DisplayName";
u.Description = "Desc";
u.Icon = "default.jpg";
u.Save(u);
Assert.True(u.Reject(u.Id, "Argo"));
}
[Fact]
public void SaveByGroupId_Ok()
{
var u = new User();
Assert.True(u.SaveByGroupId("1", new string[] { "1" }));
}
[Fact]
public void SaveByRoleId_Ok()
{
var u = new User();
Assert.True(u.SaveByRoleId("1", new string[] { "1", "2" }));
}
}
}

19
UniTest/UniTest.csproj Normal file
View File

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj" />
</ItemGroup>
</Project>

View File

@ -1,36 +0,0 @@
using System.Reflection;
//// General Information about an assembly is controlled through the following
//// set of attributes. Change these attribute values to modify the information
//// associated with an assembly.
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Cig MES Corporation Author: Argo Zhang (Argo@live.ca)")]
[assembly: AssemblyCopyright("Copyright (c) CIG All rights reserved.")]
#if DEBUG
[assembly: AssemblyTrademark("Cig MES Component Debug Version")]
#else
[assembly: AssemblyTrademark("Cig MES Component Release Version")]
#endif
[assembly: AssemblyCulture("")]
[assembly: AssemblyProduct("Cig MES (R) Component")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
//[assembly: ComVisible(false)]
//[assembly: CLSCompliant(true)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
//[assembly: Guid("a5f49ad1-f158-4eb7-9398-75fb414af28f")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]