Publish: 发布新版本V2.0,根据新的CacheManager接口,增加缓存相对过期时间功能,文件编码格式更改为UTF-8

This commit is contained in:
Argo-Lenovo 2017-04-05 13:58:50 +08:00 committed by Argo-MacBookPro
parent 22ae3b0fd3
commit 35190af759
60 changed files with 271 additions and 1493 deletions

View File

@ -1,14 +0,0 @@
using Longbow.Web.Mvc;
using System;
namespace Bootstrap.Admin
{
/// <summary>
///
/// </summary>
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)]
class BAAuthorizeAttribute : LgbAuthorizeAttribute
{
}
}

View File

@ -1,5 +1,4 @@
using Bootstrap.DataAccess;
using Longbow.Caching;
using Longbow.ExceptionManagement;
using Longbow.ExceptionManagement.Configuration;
using System;
@ -22,7 +21,6 @@ namespace Bootstrap.Admin
{
if (publisherElement.Mode == PublisherMode.Off) return;
ExceptionHelper.Log(ex, additionalInfo);
CacheManager.Clear();
}
}
}

View File

@ -1,4 +1,4 @@
using Bootstrap.Security.Mvc;
using Bootstrap.Security.Mvc;
using Longbow.Web.Mvc;
using System;
using System.Web.Mvc;

View File

@ -28,7 +28,7 @@
top: 94px;
bottom: 40px;
position: absolute;
overflow-y: auto;
overflow: auto;
}
.form-group .form-control-url {
@ -78,7 +78,7 @@
top: 94px;
bottom: 40px;
position: absolute;
overflow-y: auto;
overflow: auto;
}
.main-content {

View File

@ -37,7 +37,7 @@
.clearcache {
position: absolute;
right: 60px;
font-size: 17px;
font-size: 1.7rem;
color: #d9534f;
margin-top: -1px;
box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15), 0 1px 1px rgba(0, 0, 0, .075);
@ -181,108 +181,79 @@ aside {
.sidebar {
display: none;
overflow-y: auto;
overflow: auto;
width: 100%;
z-index: 5;
background: #2a3542;
}
.sidebar ul li a {
padding-right: 25px;
}
.sidebar .sub-menu > .sub li {
padding-left: 32px;
}
.sidebar ul li {
position: relative;
}
ul.sidebar-menu {
padding: 20px 0 15px 0;
.sidebar-menu {
padding: 20px 0;
margin-bottom: 0;
}
ul.sidebar-menu, ul.sidebar-menu li ul.sub {
padding-left: 0;
.sidebar-menu .dcjq-icon {
height: 17px;
width: 17px;
display: inline-block;
background: url(images/nav-expand.png) no-repeat;
float: right;
}
ul.sidebar-menu .dcjq-icon {
height: 17px;
width: 17px;
display: inline-block;
background: url(images/nav-expand.png) no-repeat;
background-position: top;
position: absolute;
right: 10px;
top: 15px;
border-radius: 3px;
.sidebar-menu .active .dcjq-icon {
background-position: bottom;
}
.sidebar-menu li {
margin: 5px 10px;
}
.sidebar-menu li a {
color: #aeb2b7;
display: block;
padding: 15px 10px;
font-size: 1.2rem;
transition: all 0.3s ease;
border-radius: 4px;
}
ul.sidebar-menu .active .dcjq-icon {
background-position: bottom;
}
ul.sidebar-menu li {
line-height: 20px;
margin-bottom: 5px;
margin-left: 10px;
margin-right: 10px;
}
ul.sidebar-menu li a.active i {
color: #FF6C60;
.sidebar-menu li a.active, .sidebar-menu li a:hover, .sidebar-menu li a:focus {
background: #35404d;
color: #fff;
}
ul.sidebar-menu li a i {
font-size: 15px;
.sidebar-menu li a.active i {
color: #FF6C60;
}
.sidebar-menu li a i {
font-size: 1.5rem;
width: 22px;
}
ul.sidebar-menu li a {
color: #aeb2b7;
text-decoration: none;
display: block;
padding: 15px 0 15px 10px;
font-size: 12px;
outline: none;
transition: all 0.3s ease;
}
.sidebar-menu li .sub {
padding-left: 0;
}
ul.sidebar-menu li a.active, ul.sidebar-menu li a:hover, ul.sidebar-menu li a:focus {
background: #35404d;
color: #fff;
display: block;
border-radius: 4px;
transition: all 0.3s ease;
}
ul.sidebar-menu li ul.sub li a:hover, ul.sidebar-menu li ul.sub li.active a {
.sidebar-menu li .sub li a:hover, .sidebar-menu li .sub li.active a {
color: #FF6C60;
transition: all 0.3s ease;
display: block;
}
ul.sidebar-menu li ul.sub li {
.sidebar-menu li .sub li {
background: #35404D;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
margin: 0;
padding: 0 10px 0 32px;
}
ul.sidebar-menu li ul.sub li:last-child {
.sidebar-menu li .sub li:last-child {
border-radius: 0 0 4px 4px;
padding-bottom: 10px;
}
ul.sidebar-menu li ul.sub li a {
font-size: 12px;
padding: 6px 0;
line-height: 35px;
height: 35px;
transition: all 0.3s ease;
color: #aeb2b7;
.sidebar-menu li .sub li a {
padding: 12px 0;
}
/*Modal Dialog Checkbox*/
@ -309,7 +280,7 @@ ul.sidebar-menu {
}
.modal-body .affix a {
font-size: 20px;
font-size: 2rem;
margin-top: 16px;
}
@ -350,7 +321,7 @@ ul.sidebar-menu {
/*cache*/
.panel .fa-refresh {
font-size: 15px;
font-size: 1.5rem;
}
.bootstrap-select .dropdown-menu {
@ -368,23 +339,11 @@ input[type="datetime"] {
/*Messages*/
.mail-box {
border-collapse: collapse;
border-spacing: 0;
display: table;
table-layout: fixed;
width: 100%;
display: flex;
}
.mail-box aside {
display: table-cell;
float: none;
height: 100%;
padding: 0;
vertical-align: top;
}
.mail-box .sm-side {
width: 25%;
flex: 0.4;
background: #e5e8ef;
border-radius: 4px 0 0 4px;
}
@ -415,7 +374,6 @@ input[type="datetime"] {
}
.mail-box .sm-side .user-head .user-name h5 {
font-size: 14px;
margin-top: 15px;
margin-bottom: 0;
font-weight: 300;
@ -478,7 +436,7 @@ input[type="datetime"] {
}
.mail-box .lg-side {
width: 75%;
flex: 0.6;
background: #fff;
border-radius: 0 4px 4px 0;
}
@ -513,18 +471,6 @@ input[type="datetime"] {
cursor: pointer;
}
.dropdown-menu {
padding: 0;
}
.dropdown-menu li a {
padding: 6px 20px;
}
.dropdown-menu .divider {
margin: 0;
}
/*Bootstrap Table BUG */
.fixed-table-loading {
padding-top: 5px;

View File

@ -1,8 +1,12 @@
body {
html {
font-size: 62.5%;
}
body {
color: #797979;
background: #f1f2f7;
font-family: 'Open Sans', sans-serif;
font-size: 13px;
font-size: 1.4rem;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-webkit-overflow-scrolling: touch;
@ -63,7 +67,6 @@ a, a:hover, a:focus {
}
.header > .dropdown > a span {
font-size: 13px;
display: inline-block;
min-width: 18px;
}
@ -126,7 +129,7 @@ a, a:hover, a:focus {
}
.header > .dropdown .dropdown-menu li a i {
font-size: 17px;
font-size: 1.7rem;
display: block;
margin-bottom: 4px;
}
@ -140,7 +143,7 @@ a, a:hover, a:focus {
/*Title*/
.sidebar-toggle-box {
font-size: 21px;
font-size: 2.1rem;
color: #333;
float: left;
margin-top: 15px;
@ -160,6 +163,7 @@ a, a:hover, a:focus {
bottom: 0;
right: 0;
white-space: nowrap;
z-index: 5;
}
.go-top {
@ -216,7 +220,7 @@ a, a:hover, a:focus {
color: #666666;
border-radius: 4px;
-webkit-border-radius: 4px;
font-size: 16px;
font-size: 1.6rem;
border: 1px solid #f0f0f8;
padding: 2px 6px;
margin-right: 15px;
@ -292,7 +296,7 @@ a, a:hover, a:focus {
.notify-row .dropdown-menu li a {
border-bottom: 1px solid #EBEBEB;
font-size: 12px;
font-size: 1.2rem;
list-style: none;
padding: 15px 10px;
}
@ -328,15 +332,15 @@ a, a:hover, a:focus {
}
.notify-row .dropdown-menu .small {
font-size: 10px;
font-style: italic;
font-weight: bold;
float: right;
padding-top: 2px;
font-size: 1rem;
}
.notify-row .dropdown-menu.tasks-bar .desc {
font-size: 13px;
font-size: 1.3rem;
font-weight: normal;
display: block;
overflow: hidden;
@ -347,7 +351,7 @@ a, a:hover, a:focus {
.notify-row .dropdown-menu.tasks-bar .percent {
display: inline-block;
float: right;
font-size: 13px;
font-size: 1.3rem;
font-weight: 600;
}
@ -377,14 +381,14 @@ a, a:hover, a:focus {
}
.notify-row .dropdown-menu.inbox .subject .time {
font-size: 11px;
font-size: 1.1rem;
font-style: italic;
font-weight: bold;
float: right;
}
.notify-row .dropdown-menu.inbox .message {
font-size: 11px;
font-size: 1.1rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@ -393,60 +397,9 @@ a, a:hover, a:focus {
left: 56px;
margin-top: 2px;
}
.dropdown-menu.menu {
top: 50px;
left: 6px;
margin-right: 15px;
min-height: 160px;
min-width: 280px;
}
.dropdown-menu.menu .arrow-up {
left: 8px;
top: -10px;
}
.dropdown-menu.menu .menu-submenu {
padding: 0 16px;
}
.dropdown-menu.menu .menu-submenu ul {
float: left;
padding-left: 10px;
padding-right: 10px;
}
.dropdown-menu.menu .menu-submenu li p {
color: #323232;
font-size: 14px;
text-transform: none;
font-weight: bold;
border-bottom: solid 1px #a9d86e;
padding: 10px 0 4px 0;
margin-bottom: 14px;
}
.dropdown-menu.menu .menu-submenu li a {
margin-bottom: 15px;
display: inline-block;
color: #323232;
font-size: 13px;
}
.dropdown-menu.menu .menu-submenu li a.active, .dropdown-menu.menu .menu-submenu li p.active {
color: #0376d8;
}
.dropdown-menu.menu .menu-submenu li a:hover {
color: #2e6da4;
}
.dropdown-menu.menu .menu-submenu li a i {
padding-right: 6px;
}
/*end*/
ul.breadcrumb {
.breadcrumb {
position: absolute;
top: 56px;
left: 15px;
@ -459,15 +412,15 @@ ul.breadcrumb {
border-top-right-radius: 0;
}
ul.breadcrumb > li.active {
.breadcrumb > li.active {
display: inline-block;
}
ul.breadcrumb > li.load {
.breadcrumb > li.load {
display: none;
}
ul.breadcrumb > li > a > i {
.breadcrumb > li > a > i {
padding-right: 6px;
}

View File

@ -53,7 +53,7 @@
.tasks-widget .task-list li > .task-title .task-value {
position: absolute;
left: 190px;
right: 40px;
right: 62px;
top: 15px;
display: inline-block;
}
@ -82,6 +82,11 @@
margin-right: 4px;
}
.tasks-widget .task-list li > .task-title .hidden-phone > span {
margin-right: 6px;
vertical-align: middle;
}
.tasks-widget .task-list li > .task-title .hidden-phone button.btn-xs {
font-size: 12px;
line-height: 1.5;

View File

@ -1,5 +1,6 @@
using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Security.Principal;
using Longbow.Web.Mvc;
using Newtonsoft.Json.Linq;
@ -17,7 +18,7 @@ namespace Bootstrap.Admin.Controllers
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<Dict> Get([FromUri]QueryDictOption value)
public QueryData<BootstrapDict> Get([FromUri]QueryDictOption value)
{
return value.RetrieveData();
}
@ -27,7 +28,7 @@ namespace Bootstrap.Admin.Controllers
/// <param name="id"></param>
/// <returns></returns>
[HttpGet]
public Dict Get(int id)
public BootstrapDict Get(int id)
{
return DictHelper.RetrieveDicts().FirstOrDefault(t => t.Id == id);
}
@ -36,7 +37,7 @@ namespace Bootstrap.Admin.Controllers
/// </summary>
/// <param name="value"></param>
[HttpPost]
public bool Post([FromBody]Dict value)
public bool Post([FromBody]BootstrapDict value)
{
return DictHelper.SaveDict(value);
}
@ -46,9 +47,9 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns>
[HttpPost]
[AllowAnonymous]
public IEnumerable<Dict> Post(int id, [FromBody]JObject value)
public IEnumerable<BootstrapDict> Post(int id, [FromBody]JObject value)
{
IEnumerable<Dict> ret = new List<Dict>();
IEnumerable<BootstrapDict> ret = new List<BootstrapDict>();
dynamic json = value;
switch ((string)json.type)
{

View File

@ -28,7 +28,7 @@ namespace Bootstrap.Admin.Controllers
public ActionResult Lock()
{
FormsAuthentication.SignOut();
var user = UserHelper.RetrieveUsersByName(User.Identity.Name);
var user = BootstrapUser.RetrieveUserByUserName(User.Identity.Name);
return View(new LockModel
{
UserName = user.UserName,

View File

@ -36,9 +36,8 @@ namespace Bootstrap.Admin.Controllers
string password = user.password;
if (LgbPrincipal.Authenticate(userName, password) || BootstrapUser.Authenticate(userName, password))
{
var interval = int.Parse(Math.Round(FormsAuthentication.Timeout.TotalSeconds).ToString(CultureInfo.InvariantCulture));
var token = CacheManager.AddOrUpdate(string.Format("WebApi-{0}", userName), interval, k => new LoginInfo() { UserName = userName, Token = Guid.NewGuid().ToString() }, (k, info) => info, "WebApi 数据缓存");
CacheManager.AddOrUpdate(token.Token, interval, k => token, (k, info) => info, "Token 数据缓存");
var token = CacheManager.AddOrUpdate(string.Format("WebApi-{0}", userName), k => new LoginInfo() { UserName = userName, Token = Guid.NewGuid().ToString() }, (k, info) => info, "WebApi");
CacheManager.AddOrUpdate(token.Token, k => token, (k, info) => info, "Token");
return token;
}
return new LoginInfo() { UserName = userName };

View File

@ -1,5 +1,6 @@
using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Web.Mvc;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
@ -16,7 +17,7 @@ namespace Bootstrap.Admin.Controllers
/// <param name="value"></param>
/// <returns></returns>
[HttpGet]
public QueryData<Menu> Get([FromUri]QueryMenuOption value)
public QueryData<BootstrapMenu> Get([FromUri]QueryMenuOption value)
{
return value.RetrieveData(User.Identity.Name);
}
@ -25,7 +26,7 @@ namespace Bootstrap.Admin.Controllers
/// </summary>
/// <param name="value"></param>
[HttpPost]
public bool Post([FromBody]Menu value)
public bool Post([FromBody]BootstrapMenu value)
{
return MenuHelper.SaveMenu(value);
}
@ -38,10 +39,16 @@ namespace Bootstrap.Admin.Controllers
{
return MenuHelper.DeleteMenu(value);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <returns></returns>
[HttpPost]
public IEnumerable<Menu> Post(int id, [FromBody]JObject value)
public IEnumerable<BootstrapMenu> Post(int id, [FromBody]JObject value)
{
var ret = new List<Menu>();
var ret = new List<BootstrapMenu>();
dynamic json = value;
switch ((string)json.type)
{
@ -49,13 +56,19 @@ namespace Bootstrap.Admin.Controllers
ret = MenuHelper.RetrieveMenusByRoleId(id).ToList();
break;
case "user":
ret = MenuHelper.RetrieveAllMenusByUserName(User.Identity.Name).ToList();
ret = BootstrapMenu.RetrieveAllMenus(User.Identity.Name).ToList();
break;
default:
break;
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <returns></returns>
[HttpPut]
public bool Put(int id, [FromBody]JObject value)
{

View File

@ -1,5 +1,6 @@
using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Security.Principal;
using Longbow.Web.Mvc;
using Newtonsoft.Json.Linq;
@ -34,15 +35,15 @@ namespace Bootstrap.Admin.Controllers
if (value.UserStatus == 9)
{
// vlaidate userName
return UserHelper.RetrieveUsersByName(value.UserName) == null;
return BootstrapUser.RetrieveUserByUserName(value.UserName) == null;
}
var ret = false;
if (value.UserName.Equals(User.Identity.Name, System.StringComparison.OrdinalIgnoreCase) || LgbPrincipal.IsAdmin(User))
{
if (value.UserStatus == 1)
ret = UserHelper.SaveUserInfoByName(value);
ret = BootstrapUser.SaveUserInfoByName(value.UserName, value.DisplayName);
else if (value.UserStatus == 2)
ret = UserHelper.ChangePassword(value);
ret = BootstrapUser.ChangePassword(value.UserName, value.Password, value.NewPassword);
}
return ret;
}
@ -76,9 +77,9 @@ namespace Bootstrap.Admin.Controllers
/// <param name="userName"></param>
/// <returns></returns>
[HttpGet]
public User Get(string userName)
public BootstrapUser Get(string userName)
{
return UserHelper.RetrieveUsersByName(userName);
return BootstrapUser.RetrieveUserByUserName(userName);
}
/// <summary>
///

View File

@ -1,4 +1,5 @@
using Bootstrap.DataAccess;
using Bootstrap.Security;
using System.Web;
namespace Bootstrap.Admin.Models
@ -10,20 +11,15 @@ namespace Bootstrap.Admin.Models
{
public HeaderBarModel()
{
var user = UserHelper.RetrieveUsersByName(HttpContext.Current.User.Identity.Name);
var user = BootstrapUser.RetrieveUserByUserName(HttpContext.Current.User.Identity.Name);
Icon = user.Icon;
DisplayName = user.DisplayName;
UserName = user.UserName;
UserId = user.Id;
}
public string UserName { get; private set; }
/// <summary>
///
/// </summary>
public int UserId { get; private set; }
/// <summary>
///
/// </summary>
public string DisplayName { get; private set; }
/// <summary>
///

View File

@ -1,4 +1,5 @@
using Bootstrap.DataAccess;
using Bootstrap.Security;
using System;
using System.Collections.Generic;
using System.Linq;
@ -9,13 +10,13 @@ namespace Bootstrap.Admin.Models
{
public NavigatorBarModel(string url)
{
Navigations = MenuHelper.RetrieveNavigationsByUserName(UserName).Where(m => m.IsResource == 0);
Navigations = BootstrapMenu.RetrieveSystemMenus(UserName);
Applications = DictHelper.RetrieveApps();
ActiveMenu(null, Navigations.ToList(), url);
HomeUrl = "~/Admin/Index";
}
private void ActiveMenu(Menu parent, List<Menu> menus, string url)
private void ActiveMenu(BootstrapMenu parent, List<BootstrapMenu> menus, string url)
{
menus.ForEach(m =>
{
@ -27,7 +28,7 @@ namespace Bootstrap.Admin.Models
/// <summary>
///
/// </summary>
public IEnumerable<Menu> Navigations { get; private set; }
public IEnumerable<BootstrapMenu> Navigations { get; private set; }
/// <summary>
///
/// </summary>

View File

@ -1,4 +1,5 @@
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Web.Mvc;
using System.Linq;
@ -22,7 +23,7 @@ namespace Bootstrap.Admin.Models
/// 字典表查询
/// </summary>
/// <returns></returns>
public QueryData<Dict> RetrieveData()
public QueryData<BootstrapDict> RetrieveData()
{
var data = DictHelper.RetrieveDicts();
if (!string.IsNullOrEmpty(Category))
@ -37,7 +38,7 @@ namespace Bootstrap.Admin.Models
{
data = data.Where(t => t.Define.ToString() == Define);
}
var ret = new QueryData<Dict>();
var ret = new QueryData<BootstrapDict>();
ret.total = data.Count();
// 通过option.Sort属性判断对那列进行排序
switch (Sort)

View File

@ -1,4 +1,4 @@
using Bootstrap.DataAccess;
using Bootstrap.Security;
using Longbow.Web.Mvc;
using System.Linq;
@ -23,9 +23,9 @@ namespace Bootstrap.Admin.Models
/// </summary>
public string IsResource { get; set; }
public QueryData<Menu> RetrieveData(string userName)
public QueryData<BootstrapMenu> RetrieveData(string userName)
{
var data = MenuHelper.RetrieveMenus(userName);
var data = BootstrapMenu.RetrieveMenusByUserName(userName);
if (!string.IsNullOrEmpty(ParentName))
{
data = data.Where(t => t.ParentName.Contains(ParentName));
@ -42,7 +42,7 @@ namespace Bootstrap.Admin.Models
{
data = data.Where(t => t.IsResource.ToString() == IsResource);
}
var ret = new QueryData<Menu>();
var ret = new QueryData<BootstrapMenu>();
ret.total = data.Count();
switch (Sort)
{

View File

@ -37,9 +37,18 @@ namespace Bootstrap.Admin.Models
case "UserName":
data = Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName);
break;
case "DisplayName":
data = Order == "asc" ? data.OrderBy(t => t.DisplayName) : data.OrderByDescending(t => t.DisplayName);
break;
case "RegisterTime":
data = Order == "asc" ? data.OrderBy(t => t.RegisterTime) : data.OrderByDescending(t => t.RegisterTime);
break;
case "ApprovedTime":
data = Order == "asc" ? data.OrderBy(t => t.ApprovedTime) : data.OrderByDescending(t => t.ApprovedTime);
break;
case "ApprovedBy":
data = Order == "asc" ? data.OrderBy(t => t.ApprovedBy) : data.OrderByDescending(t => t.ApprovedBy);
break;
default:
break;
}

View File

@ -1,28 +0,0 @@
using Bootstrap.DataAccess;
using Longbow.Web.Mvc;
using System.Collections.Generic;
using System.Linq;
namespace Bootstrap.Admin.Models
{
public class UserEntity
{
public int total { get; private set; }
public IEnumerable<User> rows { get; private set; }
public void RetrieveUsers(UsersPageOption option)
{
// int limit, int offset, string name, string price, string sort, string order
var data = UserHelper.RetrieveUsers(string.Empty);
if (!string.IsNullOrEmpty(option.Name))
{
data = data.Where(t => t.UserName.Contains(option.Name));
}
total = data.Count();
// TODO: 通过option.Sort属性判断对那列进行排序现在统一对名称列排序
data = option.Order == "asc" ? data.OrderBy(t => t.UserName) : data.OrderByDescending(t => t.UserName);
rows = data.Skip(option.Offset).Take(option.Limit);
}
}
}

View File

@ -1,12 +0,0 @@
using Longbow.Web.Mvc;
namespace Bootstrap.Admin.Models
{
/// <summary>
///
/// </summary>
public class UsersPageOption : PaginationOption
{
public string Name { get; set; }
}
}

View File

@ -306,8 +306,8 @@
sortOrder: "desc", //排序方式
sidePagination: "server", //分页方式client客户端分页server服务端分页*
pageNumber: 1, //初始化加载第一页,默认第一页
pageSize: 10, //每页的记录行数(*
pageList: [10, 25, 50, 100], //可供选择的每页的行数(*
pageSize: 20, //每页的记录行数(*
pageList: [20, 40, 80, 120], //可供选择的每页的行数(*
search: false, //是否显示表格搜索,此搜索是客户端搜索,不会进服务端,所以,个人感觉意义不大
strictSearch: false,
showColumns: true, //是否显示所有的列

View File

@ -6,16 +6,16 @@
maxlength: 50
}
}, {
button: ['sysSave']
});
button: ['sysSave']
});
$('#footerDataForm').autoValidate({
sysFoot: {
required: true,
maxlength: 50
}
}, {
button: ['footSave']
});
button: ['footSave']
});
var bsa = new BootstrapAdmin({
url: Settings.url,
@ -105,7 +105,7 @@
if (result && options.key == '') {
result = $.parseJSON(result);
if ($.isArray(result)) {
var html = '<li class="{4}"><i class="fa fa-ellipsis-v"></i><div class="task-title"><span class="task-title-sp" role="tooltip" title="{1}">{2}</span><span class="badge badge-sm label-success">{0}</span><span class="task-value" title="{3}">{3}</span><div class="pull-right hidden-phone"><button class="btn btn-danger btn-xs fa fa-trash-o" title="{1}" data-key="{1}" data-url="{5}" role="tooltip" data-placement="left"></button></div></div></li>';
var html = '<li class="{4}"><i class="fa fa-ellipsis-v"></i><div class="task-title"><span class="task-title-sp" role="tooltip" title="{1}">{2}</span><span class="badge badge-sm label-success">{0}</span><span class="task-value" title="{3}">{3}</span><div class="pull-right hidden-phone"><span>{6}</span><button class="btn btn-danger btn-xs fa fa-trash-o" title="{1}" data-key="{1}" data-url="{5}" role="tooltip" data-placement="left"></button></div></div></li>';
var content = result.sort(function (x, y) {
return x.Key > y.Key ? 1 : -1;
}).map(function (ele) {
@ -145,7 +145,7 @@
default:
break;
}
return $.format(html, ele.Interval, ele.Key, ele.Desc, ele.Value, css, options.url);
return $.format(html, ele.Interval, ele.Key, ele.Desc, ele.Value, css, options.url, Math.max(0, ele.Interval - Math.round((new Date() - new Date(ele.CreateTime)) / 1000)));
}).join('');
$sortable.append($.format('<li class="title">{0}-{1}</li>', options.item.Desc, options.item.Key));
$sortable.append(content);

View File

@ -75,7 +75,7 @@
}]
},
callback: function (data) {
if (data && data.success && data.oper === 'save' && data.data.ID === $('#userId').val()) {
if (data && data.success && data.oper === 'save' && data.UserName == $('#userDisplayName').attr('data-userName')) {
$('#userDisplayName').text(data.data.DisplayName);
}
if (data && data.oper === 'create') {
@ -90,11 +90,17 @@
$('table').smartTable({
url: User.url, //请求后台的URL*
sortName: 'DisplayName',
sortOrder: "asc",
queryParams: function (params) { return $.extend(params, { name: $("#txt_search_name").val(), displayName: $('#txt_display_name').val() }); }, //传递参数(*
columns: [{ checkbox: true },
columns: [
{ checkbox: true },
{ title: "Id", field: "Id", events: bsa.idEvents(), formatter: BootstrapAdmin.idFormatter },
{ title: "登陆名称", field: "UserName", sortable: true },
{ title: "显示名称", field: "DisplayName", sortable: true }
{ title: "显示名称", field: "DisplayName", sortable: true },
{ title: "注册时间", field: "RegisterTime", sortable: true },
{ title: "授权时间", field: "ApprovedTime", sortable: true },
{ title: "授权人", field: "ApprovedBy", sortable: true },
{ title: "说明", field: "Description", sortable: false }
]
});
@ -124,8 +130,8 @@
maxlength: 50
}
}, {
userName: {
remote: "此登陆名称已存在"
}
});
userName: {
remote: "此登陆名称已存在"
}
});
});

View File

@ -1,24 +1,4 @@
$(function () {
$.extend({
"format": function (source, params) {
if (params === undefined) {
return source;
}
if (arguments.length > 2 && params.constructor !== Array) {
params = $.makeArray(arguments).slice(1);
}
if (params.constructor !== Array) {
params = [params];
}
$.each(params, function (i, n) {
source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function () {
return n;
});
});
return source;
}
});
var ajax = function (options) {
options = $.extend({
test: false,
@ -39,7 +19,7 @@
return;
}
$.ajax({
url: '../' + options.url,
url: options.url,
data: options.data,
type: options.method,
headers: options.headers,

View File

@ -12,7 +12,7 @@
callback: function (result) {
if (result) {
var content = result.Users.map(function (noti) {
return $.format(htmlNewUsers, noti.UserName, noti.Description, noti.RegisterTime, noti.ID, noti.DisplayName);
return $.format(htmlNewUsers, noti.UserName, noti.Description, noti.RegisterTime, noti.Id, noti.DisplayName);
}).join('');
$taskUsers.append(content);
$('#tasks-users').find('[role="tooltip"]').lgbTooltip();

View File

@ -10,7 +10,7 @@
callback: function (result) {
if (result) {
var content = result.map(function (task) {
return $.format(htmlTask, task.TaskName, task.UserName, task.AssignTime, task.ID);
return $.format(htmlTask, task.TaskName, task.UserName, task.AssignTime, task.Id);
}).join('');
$('#list-task').html(content);
}

View File

@ -7,7 +7,7 @@
<script src="~/Scripts/message.js"></script>
}
<div class="mail-box">
<aside class="sm-side">
<div class="sm-side">
<div class="user-head">
<a href="javascript:;" class="inbox-avatar">
<img src="../content/images/logo6.jpg" alt="">
@ -33,17 +33,15 @@
<a href="#" data-id="trash"><i class=" fa fa-trash-o"></i>垃圾箱<span class="label label-danger pull-right" id="s_trash"></span></a>
</li>
</ul>
</aside>
<aside class="lg-side">
</div>
<div class="lg-side">
<div class="inbox-head">
<h3>消息列表</h3>
</div>
<div class="inbox-body">
<table class="table table-inbox table-hover">
<tbody id="tbMsg">
</tbody>
<tbody id="tbMsg"></tbody>
</table>
</div>
</aside>
</div>
</div>

View File

@ -22,7 +22,6 @@
</div>
</div>
</form>
<input id="userId" type="text" class="hidden" value="@Model.UserId" />
}
@section toolbar {
<button id="btn_assignRole" type="button" class="btn btn-info">

View File

@ -1,4 +1,4 @@
@model LoginModel
@model LoginModel
@{
ViewBag.Title = Model.Title;
Layout = "~/Views/Shared/_Layout.cshtml";

View File

@ -97,7 +97,7 @@
<div class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<img id="headerIcon" alt="" src="@Url.Content(Model.Icon)">
<span id="userDisplayName" class="username">@Model.DisplayName</span>
<span id="userDisplayName" data-userName="@Model.UserName" class="username">@Model.DisplayName</span>
<b class="caret"></b>
</a>
<ul class="dropdown-menu">

View File

@ -1,4 +1,4 @@
@model Menu
@model Bootstrap.Security.BootstrapMenu
<li class="sub-menu">
<a href="@Url.Content(Model.Url)" class="@Model.Active" target="@Model.Target"><i class="@Model.Icon"></i>@Model.Name</a>
@if (Model.Menus.Count() > 0)

View File

@ -1,4 +1,4 @@
@model IEnumerable<Menu>
@model IEnumerable<Bootstrap.Security.BootstrapMenu>
<ul class="sub" style="display: none;">
@foreach (var menu in Model)
{

View File

@ -27,12 +27,8 @@
</connectionStrings>
<cacheManager>
<add key="MenuHelper-RetrieveMenus" interval="600" desc="所有菜单数据缓存" />
<add key="UserHelper-RetrieveNewUsers" interval="30" desc="新用户数据缓存" />
<add key="MenuHelper-RetrieveMenusByRoleId" interval="600" desc="角色菜单信息缓存" />
<add key="UserHelper-RetrieveUsers" interval="600" desc="所有用户数据缓存" />
<add key="UserHelper-RetrieveUsersByName" interval="600" desc="指定用户数据缓存" />
<add key="UserHelper-RetrieveUsersByRoleId" interval="600" desc="指定角色用户数据缓存" />
<add key="UserHelper-RetrieveUsersByGroupId" interval="600" desc="指定组用户数据缓存" />
<add key="RoleHelper-RetrieveRoles" interval="600" desc="所有角色数据缓存" />
<add key="RoleHelper-RetrieveRolesByUserId" interval="600" desc="指定用户角色数据缓存" />
<add key="RoleHelper-RetrieveRolesByMenuId" interval="600" desc="指定菜单角色数据缓存" />
@ -41,15 +37,24 @@
<add key="GroupHelper-RetrieveGroupsByUserId" interval="600" desc="指定用户组数据缓存" />
<add key="GroupHelper-RetrieveGroupsByRoleId" interval="600" desc="指定角色组数据缓存" />
<add key="LogHelper-RetrieveLogs" interval="600" desc="所有日志数据缓存" />
<add key="DictHelper-RetrieveDicts" interval="600" desc="所有字典数据缓存" />
<add key="DictHelper-RetrieveDictsCategory" interval="6000" desc="字典分类数据缓存" />
<add key="NotificationHelper-RetrieveNotifications" interval="600" desc="通知管理数据缓存" />
<add key="UserHelper-RetrieveNewUsers" interval="300" desc="新用户数据缓存" />
<add key="ExceptionHelper-RetrieveExceptions" interval="600" desc="程序异常数据缓存" />
<add key="MessageHelper-RetrieveMessages" interval="600" desc="站内消息数据缓存" />
<add key="TaskHelper-RetrieveTasks" interval="600" desc="所有任务数据缓存" />
<add key="BootstrapAdminPrincipal-RetrieveAllRoles" interval="600" desc="系统所有角色列表数据" />
<add key="BootstrapAdminPrincipal-RetrieveRolesByUrl" interval="600" desc="指定菜单的角色数据缓存" />
<add key="BootstrapAdminPrincipal-RetrieveRolesByUserName" interval="600" desc="指定用户名角色数据缓存" />
<add key="BootstrapAdminPrincipal-RetrieveAllGroups-BA" interval="600" desc="系统所有用户组列表数据" />
<add key="BootstrapAdminPrincipal-RetrieveGroupsByUserName" interval="600" desc="通过用户获得用户组数据" />
<add key="BootstrapMenu-RetrieveMenus" interval="600" desc="所有菜单数据缓存" />
<add key="BootstrapDict-RetrieveDicts" interval="600" desc="所有字典数据缓存" />
<add key="BootstrapUser-RetrieveUsers" interval="600" desc="所有用户数据缓存" />
<add key="BootstrapUser-RetrieveUsersByName" interval="600" desc="指定用户数据缓存" />
<add key="BootstrapUser-RetrieveUsersByRoleId" interval="600" desc="指定角色用户数据缓存" />
<add key="BootstrapUser-RetrieveUsersByGroupId" interval="600" desc="指定组用户数据缓存" />
<add key="WebApi" interval="21600" desc="WebApi 数据缓存" />
<add key="Token" interval="21600" desc="Token 数据缓存" />
</cacheManager>
@ -79,7 +84,7 @@
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<authentication mode="Forms">
<forms defaultUrl="~/" loginUrl="~/Home/Login" name="__bd__" protection="All" />
<forms defaultUrl="~/" loginUrl="~/Home/Login" name="__bd__" protection="All" timeout="360" />
</authentication>
<pages>
<namespaces>
@ -95,7 +100,7 @@
</httpModules>
<machineKey validation="SHA1" validationKey="78EA3850338FBADCE59D8DDF58C9E4518E75AC149C46142D7AAD7F1AD49D95D4" decryptionKey="684FC9301F404DE1B9565E7D9520AC579E823307BED44885" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
@ -131,7 +136,7 @@
<add name="ExceptionManagement" type="Longbow.ExceptionManagement.ExceptionManagementModule, Longbow.ExceptionManagement" />
</modules>
</system.webServer>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>

View File

@ -59,7 +59,6 @@
</Compile>
<Compile Include="CacheCleanUtility.cs" />
<Compile Include="DBAccessManager.cs" />
<Compile Include="Dict.cs" />
<Compile Include="DictHelper.cs" />
<Compile Include="ExceptionHelper.cs" />
<Compile Include="Exceptions.cs" />
@ -67,7 +66,6 @@
<Compile Include="GroupHelper.cs" />
<Compile Include="Log.cs" />
<Compile Include="LogHelper.cs" />
<Compile Include="Menu.cs" />
<Compile Include="MenuHelper.cs" />
<Compile Include="Message.cs" />
<Compile Include="MessageHelper.cs" />

View File

@ -1,4 +1,6 @@
using Longbow.Caching.Configuration;
using Bootstrap.Security;
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement;
using System;
using System.Collections.Generic;
@ -31,7 +33,7 @@ namespace Bootstrap.DataAccess
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByRoleIdDataKey, id));
});
cacheKeys.Add(RoleHelper.RetrieveRolesDataKey + "*");
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
}
if (userIds != null)
{
@ -39,10 +41,10 @@ namespace Bootstrap.DataAccess
{
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByUserIdDataKey, id));
cacheKeys.Add(string.Format("{0}-{1}", GroupHelper.RetrieveGroupsByUserIdDataKey, id));
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey);
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
});
cacheKeys.Add(UserHelper.RetrieveNewUsersDataKey + "*");
cacheKeys.Add(UserHelper.RetrieveUsersDataKey + "*");
cacheKeys.Add(BootstrapUser.RetrieveUsersDataKey + "*");
}
if (groupIds != null)
{
@ -52,7 +54,7 @@ namespace Bootstrap.DataAccess
cacheKeys.Add(string.Format("{0}-{1}", UserHelper.RetrieveUsersByGroupIdDataKey, id));
});
cacheKeys.Add(GroupHelper.RetrieveGroupsDataKey + "*");
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
}
if (menuIds != null)
{
@ -60,11 +62,11 @@ namespace Bootstrap.DataAccess
{
cacheKeys.Add(string.Format("{0}-{1}", RoleHelper.RetrieveRolesByMenuIdDataKey, id));
});
cacheKeys.Add(MenuHelper.RetrieveMenusDataKey + "*");
cacheKeys.Add(BootstrapMenu.RetrieveMenusDataKey + "*");
}
if (dictIds != null)
{
cacheKeys.Add(DictHelper.RetrieveDictsDataKey + "*");
cacheKeys.Add(BootstrapDict.RetrieveDictsDataKey + "*");
}
if (logIds != null)
{
@ -79,16 +81,18 @@ namespace Bootstrap.DataAccess
cacheKeys.Add(ExceptionHelper.RetrieveExceptionsDataKey + "*");
}
var section = CacheListSection.GetSection();
section.Items.Where(item => item.Enabled).AsParallel().ForAll(ele =>
cacheKeys.AsParallel().ForAll(key => CacheManager.Clear(k => key.EndsWith("*") ? k.Contains(key.TrimEnd('*')) : k.Equals(key)));
System.Threading.Tasks.Task.Factory.StartNew(() =>
{
System.Threading.Tasks.Task.Factory.StartNew(() =>
var section = CacheListSection.GetSection();
section.Items.Where(item => item.Enabled).Skip(1).AsParallel().ForAll(ele =>
{
try
{
var client = new WebClient();
cacheKeys.ForEach(k => client.OpenRead(new Uri(string.Format(ele.Url, k))));
using (var client = new WebClient())
{
cacheKeys.ForEach(k => client.OpenRead(string.Format(ele.Url, k)));
}
}
catch (Exception ex)
{

View File

@ -1,29 +0,0 @@
namespace Bootstrap.DataAccess
{
/// <summary>
/// 字典表实体
/// </summary>
public class Dict
{
/// <summary>
/// 字典主键 数据库自增
/// </summary>
public int Id { get; set; }
/// <summary>
/// 分类
/// </summary>
public string Category { get; set; }
/// <summary>
/// 名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 代号
/// </summary>
public string Code { get; set; }
/// <summary>
/// 1表示系统使用0表示用户自定义 默认为1
/// </summary>
public int Define { get; set; }
}
}

View File

@ -1,5 +1,5 @@
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Bootstrap.Security;
using Longbow.Caching;
using Longbow.ExceptionManagement;
using System;
using System.Collections.Generic;
@ -15,39 +15,17 @@ namespace Bootstrap.DataAccess
/// </summary>
public static class DictHelper
{
internal const string RetrieveDictsDataKey = "DictHelper-RetrieveDicts";
/// <summary>
///
/// </summary>
private const string RetrieveCategoryDataKey = "DictHelper-RetrieveDictsCategory";
/// <summary>
/// 查询所有字典信息
///
/// </summary>
/// <returns></returns>
public static IEnumerable<Dict> RetrieveDicts()
public static IEnumerable<BootstrapDict> RetrieveDicts()
{
return CacheManager.GetOrAdd(RetrieveDictsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveDictsDataKey), key =>
{
string sql = "select ID, Category, Name, Code, Define from Dicts";
List<Dict> dicts = new List<Dict>();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
{
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
dicts.Add(new Dict()
{
Id = (int)reader[0],
Category = (string)reader[1],
Name = (string)reader[2],
Code = (string)reader[3],
Define = (int)reader[4]
});
}
}
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return dicts;
}, CacheSection.RetrieveDescByKey(RetrieveDictsDataKey));
return BootstrapDict.RetrieveDicts();
}
/// <summary>
/// 删除字典中的数据
@ -80,7 +58,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool SaveDict(Dict p)
public static bool SaveDict(BootstrapDict p)
{
bool ret = false;
if (p.Category.Length > 50) p.Category = p.Category.Substring(0, 50);
@ -129,7 +107,7 @@ namespace Bootstrap.DataAccess
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Category", category));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
CacheManager.Clear(key => key.Contains(RetrieveDictsDataKey));
CacheCleanUtility.ClearCache(dictIds: string.Empty);
ret = true;
}
catch (DbException ex)
@ -142,11 +120,11 @@ namespace Bootstrap.DataAccess
/// 获取字典分类名称
/// </summary>
/// <returns></returns>
public static IEnumerable<Dict> RetrieveCategories()
public static IEnumerable<BootstrapDict> RetrieveCategories()
{
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, CacheSection.RetrieveIntervalByKey(RetrieveCategoryDataKey), key =>
return CacheManager.GetOrAdd(RetrieveCategoryDataKey, key =>
{
var ret = new List<Dict>();
var ret = new List<BootstrapDict>();
string sql = "select distinct Category from Dicts";
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
@ -155,13 +133,13 @@ namespace Bootstrap.DataAccess
{
while (reader.Read())
{
ret.Add(new Dict() { Category = (string)reader[0] });
ret.Add(new BootstrapDict() { Category = (string)reader[0] });
}
}
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return ret;
}, CacheSection.RetrieveDescByKey(RetrieveCategoryDataKey));
});
}
/// <summary>
///
@ -170,7 +148,7 @@ namespace Bootstrap.DataAccess
public static string RetrieveWebTitle()
{
var settings = RetrieveDicts();
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "后台管理系统" }).Code;
return (settings.FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
}
/// <summary>
///
@ -179,13 +157,13 @@ namespace Bootstrap.DataAccess
public static string RetrieveWebFooter()
{
var settings = RetrieveDicts();
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "2016 © 通用后台管理系统" }).Code;
return (settings.FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<Dict> RetrieveWebCss()
public static IEnumerable<BootstrapDict> RetrieveWebCss()
{
var data = RetrieveDicts();
return data.Where(d => d.Category == "网站样式");
@ -194,7 +172,7 @@ namespace Bootstrap.DataAccess
///
/// </summary>
/// <returns></returns>
public static IEnumerable<Dict> RetrieveActiveCss()
public static IEnumerable<BootstrapDict> RetrieveActiveCss()
{
var data = RetrieveDicts();
return data.Where(d => d.Name == "使用样式" && d.Category == "当前样式" && d.Define == 0 && !d.Code.Equals("site.css", StringComparison.OrdinalIgnoreCase));
@ -203,10 +181,10 @@ namespace Bootstrap.DataAccess
/// 获取头像路径
/// </summary>
/// <returns></returns>
public static Dict RetrieveIconFolderPath()
public static BootstrapDict RetrieveIconFolderPath()
{
var data = RetrieveDicts();
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new Dict() { Code = "~/Content/images/uploader/" };
return data.FirstOrDefault(d => d.Name == "头像路径" && d.Category == "头像地址" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Content/images/uploader/" };
}
/// <summary>
/// 获得默认的前台首页地址,默认为~/Home/Index
@ -215,7 +193,7 @@ namespace Bootstrap.DataAccess
public static string RetrieveHomeUrl()
{
var settings = RetrieveDicts();
return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new Dict() { Code = "~/Home/Index" }).Code;
return (settings.FirstOrDefault(d => d.Name == "前台首页" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "~/Home/Index" }).Code;
}
/// <summary>
///

View File

@ -1,5 +1,4 @@
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data;
using Longbow.ExceptionManagement;
using System;
@ -53,7 +52,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<Exceptions> RetrieveExceptions()
{
return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveExceptionsDataKey), key =>
return CacheManager.GetOrAdd(RetrieveExceptionsDataKey, key =>
{
string sql = "select top 1000 * from Exceptions order by LogTime desc";
List<Exceptions> exceptions = new List<Exceptions>();
@ -81,7 +80,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return exceptions;
}, CacheSection.RetrieveDescByKey(RetrieveExceptionsDataKey));
});
}
}
}

View File

@ -1,5 +1,4 @@
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data;
using Longbow.ExceptionManagement;
using System;
@ -27,7 +26,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<Group> RetrieveGroups(int id = 0)
{
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveGroupsDataKey), key =>
var ret = CacheManager.GetOrAdd(RetrieveGroupsDataKey, key =>
{
string sql = "select * from Groups";
List<Group> groups = new List<Group>();
@ -49,7 +48,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return groups;
}, CacheSection.RetrieveDescByKey(RetrieveGroupsDataKey));
});
return id == 0 ? ret : ret.Where(t => id == t.Id);
}
/// <summary>
@ -115,7 +114,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Group> RetrieveGroupsByUserId(int userId)
{
string key = string.Format("{0}-{1}", RetrieveGroupsByUserIdDataKey, userId);
var ret = CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveGroupsByUserIdDataKey), k =>
var ret = CacheManager.GetOrAdd(key, k =>
{
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>();
@ -139,7 +138,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return groups;
}, CacheSection.RetrieveDescByKey(RetrieveGroupsByUserIdDataKey));
}, RetrieveGroupsByUserIdDataKey);
return ret;
}
/// <summary>
@ -197,7 +196,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Group> RetrieveGroupsByRoleId(int roleId)
{
string k = string.Format("{0}-{1}", RetrieveGroupsByRoleIdDataKey, roleId);
return CacheManager.GetOrAdd(k, CacheSection.RetrieveIntervalByKey(RetrieveGroupsByRoleIdDataKey), key =>
return CacheManager.GetOrAdd(k, key =>
{
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";
@ -221,7 +220,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return groups;
}, CacheSection.RetrieveDescByKey(RetrieveGroupsByRoleIdDataKey));
}, RetrieveGroupsByRoleIdDataKey);
}
/// <summary>
/// 根据角色ID以及选定的部门ID保到角色部门表

View File

@ -1,5 +1,4 @@
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement;
using System;
using System.Collections.Generic;
@ -20,7 +19,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<Log> RetrieveLogs(string tId = null)
{
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveLogsDataKey), key =>
var ret = CacheManager.GetOrAdd(RetrieveLogsDataKey, key =>
{
string sql = "select top 1000 * from Logs";
List<Log> logs = new List<Log>();
@ -46,7 +45,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return logs;
}, CacheSection.RetrieveDescByKey(RetrieveLogsDataKey));
});
return string.IsNullOrEmpty(tId) ? ret : ret.Where(t => tId.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase));
}
/// <summary>

View File

@ -1,67 +0,0 @@
using System.Collections.Generic;
namespace Bootstrap.DataAccess
{
/// <summary>
///
/// </summary>
public class Menu
{
/// <summary>
/// 获得/设置 菜单主键ID
/// </summary>
public int Id { set; get; }
/// <summary>
/// 获得/设置 父级菜单ID
/// </summary>
public int ParentId { set; get; }
/// <summary>
/// 获得/设置 父级菜单名称
/// </summary>
public string ParentName { get; set; }
/// <summary>
/// 获得/设置 菜单名称
/// </summary>
public string Name { get; set; }
/// <summary>
/// 获得/设置 菜单序号
/// </summary>
public int Order { get; set; }
/// <summary>
/// 获得/设置 菜单图标
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 获得/设置 菜单URL地址
/// </summary>
public string Url { get; set; }
/// <summary>
/// 获得/设置 菜单分类
/// </summary>
public string Category { get; set; }
/// <summary>
/// 获得 菜单分类名称取字典表中的Name category="菜单"
/// </summary>
public string CategoryName { get; set; }
/// <summary>
/// 获得/设置 是否当前被选中 active为选中
/// </summary>
public string Active { get; set; }
/// <summary>
/// 获得/设置 链接目标
/// </summary>
public string Target { get; set; }
/// <summary>
/// 获得/设置 是否为资源文件
/// </summary>
public int IsResource { get; set; }
/// <summary>
/// 获得/设置 所属应用程序
/// </summary>
public string ApplicationCode { get; set; }
/// <summary>
///
/// </summary>
public IEnumerable<Menu> Menus { get; set; }
}
}

View File

@ -1,9 +1,7 @@
using Longbow;
using Bootstrap.Security;
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data;
using Longbow.ExceptionManagement;
using Longbow.Security.Principal;
using System;
using System.Collections.Generic;
using System.Data;
@ -18,96 +16,8 @@ namespace Bootstrap.DataAccess
/// </summary>
public static class MenuHelper
{
internal const string RetrieveMenusDataKey = "MenuHelper-RetrieveMenus";
private const string RetrieveMenusByRoleIdDataKey = "MenuHelper-RetrieveMenusByRoleId";
/// <summary>
/// 查询所有菜单信息
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<Menu> RetrieveMenus(string userName = null)
{
userName = LgbPrincipal.IsWebAdmin(userName) ? string.Empty : userName;
string key = string.Format("{0}-{1}", RetrieveMenusDataKey, userName);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveMenusDataKey), k =>
{
List<Menu> menus = new List<Menu>();
try
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.StoredProcedure, "Proc_RetrieveMenus"))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", DBAccess.ToDBValue(userName), ParameterDirection.Input));
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
{
while (reader.Read())
{
menus.Add(new Menu()
{
Id = (int)reader[0],
ParentId = (int)reader[1],
Name = (string)reader[2],
Order = (int)reader[3],
Icon = LgbConvert.ReadValue(reader[4], string.Empty),
Url = LgbConvert.ReadValue(reader[5], string.Empty),
Category = (string)reader[6],
Target = (string)reader[7],
IsResource = (bool)reader[8] ? 1 : 0,
ApplicationCode = reader.IsDBNull(9) ? string.Empty : (string)reader[9],
CategoryName = (string)reader[10],
ParentName = LgbConvert.ReadValue(reader[11], string.Empty)
});
}
}
}
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return menus;
}, CacheSection.RetrieveDescByKey(RetrieveMenusDataKey));
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public static IEnumerable<Menu> RetrieveAllMenusByUserName(string userName)
{
var navs = RetrieveMenus(userName);
var root = navs.Where(m => m.ParentId == 0).OrderBy(m => m.Category).ThenBy(m => m.Order);
CascadeMenu(navs, root);
return root;
}
/// <summary>
///
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<Menu> RetrieveNavigationsByUserName(string userName)
{
var navs = RetrieveMenus(userName).Where(m => m.Category == "0");
var root = navs.Where(m => m.ParentId == 0).OrderBy(m => m.Order);
CascadeMenu(navs, root);
return root;
}
/// <summary>
/// 通过当前用户名获得前台菜单
/// </summary>
/// <param name="userName">当前登陆的用户名</param>
/// <returns></returns>
public static IEnumerable<Menu> RetrieveLinksByUserName(string userName)
{
var navs = RetrieveMenus(userName).Where(m => m.Category == "1");
var root = navs.Where(m => m.ParentId == 0).OrderBy(m => m.Order);
CascadeMenu(navs, root);
return root;
}
private static void CascadeMenu(IEnumerable<Menu> navs, IEnumerable<Menu> level)
{
level.ToList().ForEach(m =>
{
m.Menus = navs.Where(sub => sub.ParentId == m.Id).OrderBy(sub => sub.Order);
CascadeMenu(navs, m.Menus);
});
}
/// <summary>
/// 删除菜单信息
/// </summary>
/// <param name="ids"></param>
@ -136,7 +46,7 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="p"></param>
/// <returns></returns>
public static bool SaveMenu(Menu p)
public static bool SaveMenu(BootstrapMenu p)
{
if (string.IsNullOrEmpty(p.Name)) return false;
bool ret = false;
@ -177,12 +87,12 @@ namespace Bootstrap.DataAccess
/// </summary>
/// <param name="roleId"></param>
/// <returns></returns>
public static IEnumerable<Menu> RetrieveMenusByRoleId(int roleId)
public static IEnumerable<BootstrapMenu> RetrieveMenusByRoleId(int roleId)
{
string key = string.Format("{0}-{1}", RetrieveMenusByRoleIdDataKey, roleId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveMenusByRoleIdDataKey), k =>
return CacheManager.GetOrAdd(key, k =>
{
List<Menu> menus = new List<Menu>();
var menus = new List<BootstrapMenu>();
try
{
string sql = "select NavigationID from NavigationRole where RoleID = @RoleID";
@ -193,7 +103,7 @@ namespace Bootstrap.DataAccess
{
while (reader.Read())
{
menus.Add(new Menu()
menus.Add(new BootstrapMenu()
{
Id = (int)reader[0]
});
@ -203,7 +113,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return menus;
}, CacheSection.RetrieveDescByKey(RetrieveMenusByRoleIdDataKey));
}, RetrieveMenusByRoleIdDataKey);
}
/// <summary>
/// 通过角色ID保存当前授权菜单

View File

@ -1,6 +1,5 @@
using Longbow;
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement;
using System;
using System.Collections.Generic;
@ -23,7 +22,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
private static IEnumerable<Message> RetrieveMessages(string userName)
{
var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, CacheSection.RetrieveIntervalByKey(RetrieveMessageDataKey), key =>
var messageRet = CacheManager.GetOrAdd(RetrieveMessageDataKey, key =>
{
string sql = "select m.*, d.Name, isnull(i.Code + u.Icon, '~/Content/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>();
@ -57,7 +56,7 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); }
return messages;
}, CacheSection.RetrieveDescByKey(RetrieveMessageDataKey));
});
return messageRet.OrderByDescending(n => n.SendTime);
}
/// <summary>

View File

@ -1,6 +1,5 @@
using Longbow;
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement;
using System;
using System.Collections.Generic;
@ -22,7 +21,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<Notification> RetrieveNotifications()
{
var notifies = CacheManager.GetOrAdd(RetrieveNotificationsDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNotificationsDataKey), key =>
var notifies = CacheManager.GetOrAdd(RetrieveNotificationsDataKey, key =>
{
string sql = "select * from Notifications";
List<Notification> notifications = new List<Notification>();
@ -51,7 +50,7 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); }
return notifications;
}, CacheSection.RetrieveDescByKey(RetrieveNotificationsDataKey));
});
notifies.AsParallel().ForAll(n =>
{
var ts = DateTime.Now - n.RegisterTime;

View File

@ -27,7 +27,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<Role> RetrieveRoles(int id = 0)
{
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, CacheSection.RetrieveIntervalByKey(RetrieveRolesDataKey), key =>
var ret = CacheManager.GetOrAdd(RetrieveRolesDataKey, key =>
{
string sql = "select * from Roles";
List<Role> roles = new List<Role>();
@ -49,7 +49,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesDataKey));
});
return id == 0 ? ret : ret.Where(t => id == t.Id);
}
/// <summary>
@ -107,7 +107,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Role> RetrieveRolesByUserId(int userId)
{
string key = string.Format("{0}-{1}", RetrieveRolesByUserIdDataKey, userId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByUserIdDataKey), k =>
return CacheManager.GetOrAdd(key, k =>
{
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";
@ -131,7 +131,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesByUserIdDataKey));
}, RetrieveRolesByUserIdDataKey);
}
/// <summary>
/// 删除角色表
@ -196,7 +196,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Role> RetrieveRolesByMenuId(int menuId)
{
string key = string.Format("{0}-{1}", RetrieveRolesByMenuIdDataKey, menuId);
var ret = CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByMenuIdDataKey), k =>
var ret = CacheManager.GetOrAdd(key, k =>
{
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>();
@ -220,7 +220,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesByMenuIdDataKey));
}, RetrieveRolesByMenuIdDataKey);
return ret;
}
public static bool SavaRolesByMenuId(int id, string roleIds)
@ -272,7 +272,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<Role> RetrieveRolesByGroupId(int groupId)
{
string key = string.Format("{0}-{1}", RetrieveRolesByGroupIdDataKey, groupId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveRolesByGroupIdDataKey), k =>
return CacheManager.GetOrAdd(key, k =>
{
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";
@ -296,7 +296,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return roles;
}, CacheSection.RetrieveDescByKey(RetrieveRolesByGroupIdDataKey));
}, RetrieveRolesByGroupIdDataKey);
}
/// <summary>

View File

@ -1,5 +1,4 @@
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.ExceptionManagement;
using System;
using System.Collections.Generic;
@ -17,7 +16,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<Task> RetrieveTasks()
{
return CacheManager.GetOrAdd(RetrieveTasksDataKey, CacheSection.RetrieveIntervalByKey(RetrieveTasksDataKey), key =>
return CacheManager.GetOrAdd(RetrieveTasksDataKey, key =>
{
string sql = "select top 1000 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>();
@ -44,7 +43,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return tasks;
}, CacheSection.RetrieveDescByKey(RetrieveTasksDataKey));
});
}
}
}

View File

@ -1,11 +1,12 @@
using System;
using Bootstrap.Security;
using System;
namespace Bootstrap.DataAccess
{
/// <summary>
/// 用户表实体类
/// </summary>
public class User : Longbow.Security.Principal.LgbUser
public class User : BootstrapUser
{
/// <summary>
/// 获得/设置 用户主键ID
@ -60,10 +61,6 @@ namespace Bootstrap.DataAccess
/// </summary>
public string RejectedTime { get; set; }
/// <summary>
/// 获得/设置 用户头像
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 获得/设置 新密码
/// </summary>
public string NewPassword { get; set; }

View File

@ -1,11 +1,9 @@
using Bootstrap.Security;
using Longbow;
using Longbow.Caching;
using Longbow.Caching.Configuration;
using Longbow.Data;
using Longbow.ExceptionManagement;
using Longbow.Security;
using Longbow.Security.Principal;
using System;
using System.Collections.Generic;
using System.Data;
@ -20,23 +18,21 @@ namespace Bootstrap.DataAccess
/// </summary>
public static class UserHelper
{
internal const string RetrieveUsersDataKey = "UserHelper-RetrieveUsers";
private const string RetrieveUsersByNameDataKey = "UserHelper-RetrieveUsersByName";
internal const string RetrieveUsersByRoleIdDataKey = "UserHelper-RetrieveUsersByRoleId";
internal const string RetrieveUsersByGroupIdDataKey = "UserHelper-RetrieveUsersByGroupId";
private const string RetrieveUsersByNameDataKey = "BootstrapUser-RetrieveUsersByName";
internal const string RetrieveUsersByRoleIdDataKey = "BootstrapUser-RetrieveUsersByRoleId";
internal const string RetrieveUsersByGroupIdDataKey = "BootstrapUser-RetrieveUsersByGroupId";
internal const string RetrieveNewUsersDataKey = "UserHelper-RetrieveNewUsers";
/// <summary>
/// 查询所有用户
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static IEnumerable<User> RetrieveUsers(int id = 0)
public static IEnumerable<User> RetrieveUsers()
{
string sql = "select ID, UserName, DisplayName, RegisterTime, ApprovedTime from Users Where ApprovedTime is not null";
var ret = CacheManager.GetOrAdd(RetrieveUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveUsersDataKey), key =>
return CacheManager.GetOrAdd(BootstrapUser.RetrieveUsersDataKey, key =>
{
List<User> users = new List<User>();
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "select ID, UserName, DisplayName, RegisterTime, ApprovedTime, ApprovedBy, Description from Users Where ApprovedTime is not null");
try
{
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
@ -49,52 +45,16 @@ namespace Bootstrap.DataAccess
UserName = (string)reader[1],
DisplayName = (string)reader[2],
RegisterTime = (DateTime)reader[3],
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue)
ApprovedTime = LgbConvert.ReadValue(reader[4], DateTime.MinValue),
ApprovedBy = reader.IsDBNull(5) ? string.Empty : (string)reader[5],
Description = (string)reader[6]
});
}
}
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return users;
}, CacheSection.RetrieveDescByKey(RetrieveUsersDataKey));
return id == 0 ? ret : ret.Where(t => id == t.Id);
}
/// <summary>
/// 根据用户名查询用户
/// </summary>
/// <param name="userName"></param>
/// <returns></returns>
public static User RetrieveUsersByName(string userName)
{
if (LgbPrincipal.IsWebAdmin(userName)) return new User() { DisplayName = "网站管理员", UserName = userName, Icon = "~/Content/images/uploader/default.jpg" };
string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, userName);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k =>
{
User user = null;
string sql = "select u.ID, UserName, DisplayName, RegisterTime, ApprovedTime, case isnull(d.Code, '') when '' then '~/Content/images/uploader/' else d.Code end + Icon from Users u left join Dicts d on d.Define = '0' and d.Category = N'头像地址' and Name = N'头像路径' where ApprovedTime is not null and UserName = @UserName";
DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql);
try
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserName", userName));
using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd))
{
if (reader.Read())
{
user = new User()
{
Id = (int)reader[0],
UserName = (string)reader[1],
DisplayName = (string)reader[2],
RegisterTime = (DateTime)reader[3],
ApprovedTime = (DateTime)reader[4],
Icon = (string)reader[5]
};
}
}
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return user;
}, CacheSection.RetrieveDescByKey(RetrieveUsersByNameDataKey));
});
}
/// <summary>
/// 查询所有的新注册用户
@ -102,7 +62,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<User> RetrieveNewUsers()
{
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNewUsersDataKey), key =>
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, key =>
{
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null and RejectedTime is null order by RegisterTime desc";
List<User> users = new List<User>();
@ -126,7 +86,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return users;
}, CacheSection.RetrieveDescByKey(RetrieveNewUsersDataKey));
});
}
/// <summary>
/// 删除用户
@ -200,7 +160,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<User> RetrieveUsersByRoleId(int roleId)
{
string key = string.Format("{0}-{1}", RetrieveUsersByRoleIdDataKey, roleId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByNameDataKey), k =>
return CacheManager.GetOrAdd(key, k =>
{
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";
@ -224,7 +184,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return users;
}, CacheSection.RetrieveDescByKey(RetrieveUsersByRoleIdDataKey));
}, RetrieveUsersByRoleIdDataKey);
}
/// <summary>
/// 通过角色ID保存当前授权用户插入
@ -278,7 +238,7 @@ namespace Bootstrap.DataAccess
public static IEnumerable<User> RetrieveUsersByGroupId(int groupId)
{
string key = string.Format("{0}-{1}", RetrieveUsersByGroupIdDataKey, groupId);
return CacheManager.GetOrAdd(key, CacheSection.RetrieveIntervalByKey(RetrieveUsersByGroupIdDataKey), k =>
return CacheManager.GetOrAdd(key, k =>
{
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";
@ -302,7 +262,7 @@ namespace Bootstrap.DataAccess
}
catch (Exception ex) { ExceptionManager.Publish(ex); }
return users;
}, CacheSection.RetrieveDescByKey(RetrieveUsersByRoleIdDataKey));
}, RetrieveUsersByRoleIdDataKey);
}
/// <summary>
/// 通过部门ID保存当前授权用户插入
@ -376,64 +336,5 @@ namespace Bootstrap.DataAccess
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
public static bool SaveUserInfoByName(User user)
{
bool ret = false;
try
{
string sql = "Update Users set DisplayName = @DisplayName where UserName = @userName";
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@DisplayName", user.DisplayName));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", user.UserName));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
CacheCleanUtility.ClearCache(userIds: string.Empty);
ret = true;
}
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="user"></param>
/// <returns></returns>
public static bool ChangePassword(User user)
{
bool ret = false;
try
{
if (BootstrapUser.Authenticate(user.UserName, user.Password))
{
string sql = "Update Users set Password = @Password, PassSalt = @PassSalt where UserName = @userName";
user.PassSalt = LgbCryptography.GenerateSalt();
user.NewPassword = LgbCryptography.ComputeHash(user.NewPassword, user.PassSalt);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Password", user.NewPassword));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@PassSalt", user.PassSalt));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@userName", user.UserName));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
string key = string.Format("{0}-{1}", RetrieveUsersByNameDataKey, user.UserName);
CacheManager.Clear(k => k == key);
ret = true;
}
}
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
return ret;
}
}
}

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<configSections>
<section name="cacheManager" type="Longbow.Caching.Configuration.CacheSection, Longbow.V4"/>
</configSections>
<connectionStrings>
<add name="SQL" providerName="System.Data.SqlClient" connectionString="Data Source=.;Initial Catalog=BootstrapAdmin;User ID=sa;Password=sa"/>
</connectionStrings>
<cacheManager>
<add key="TerminalData-CodeTerminalHelper" interval="600" desc="输入口信息缓存" />
</cacheManager>
</configuration>

View File

@ -1,103 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Bootstrap.DataAccessTests</RootNamespace>
<AssemblyName>Bootstrap.DataAccessTests</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Longbow.Data, Version=3.0.0.0, Culture=neutral, PublicKeyToken=c20f2177a7066899, processorArchitecture=MSIL" />
<Reference Include="Longbow.V4, Version=4.0.0.0, Culture=neutral, PublicKeyToken=c20f2177a7066899, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Data" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="DictHelperTests.cs" />
<Compile Include="ExceptionHelperTests.cs" />
<Compile Include="RoleHelperTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="GroupHelperTests.cs" />
<Compile Include="MenuHelperTests.cs" />
<Compile Include="LogHelperTests.cs" />
<Compile Include="NotificationHelperTest.cs" />
<Compile Include="UserHelperTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Bootstrap.DataAccess\Bootstrap.DataAccess.csproj">
<Project>{AF16CA71-B8C6-4F51-B38C-0C0300FDEBD7}</Project>
<Name>Bootstrap.DataAccess</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -1,62 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class DictHelperTests
{
private Dict Dict { get; set; }
[TestInitialize]
public void Initialized()
{
Dict = new Dict() { Category = "__测试字典__", Name = "__测试子字典1__", Code = "2", Define = 0 };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Delete from Dicts where Category = '__测试菜单__'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveDictsTest()
{
Assert.IsTrue(DictHelper.RetrieveDicts().Count() > 1, "不带参数的DictHelper.RetrieveDicts方法调用失败");
}
[TestMethod]
public void SaveDictTest()
{
// 测试插入字典记录方法 ID = 0
Assert.IsTrue(DictHelper.SaveDict(Dict), "插入字典记录操作失败,请检查 DictHelper.SaveDict 方法");
var dicts = DictHelper.RetrieveDicts();
Assert.IsTrue(dicts.Count() > 0, "插入字典记录操作失败,请检查 DictHelper.SaveDict 方法");
// 测试更新字典记录方法 ID != 0
var dict = dicts.FirstOrDefault(d => d.Category == Dict.Category);
dict.Name = "__测试子字典2__";
Assert.IsTrue(DictHelper.SaveDict(dict), string.Format("更新字典记录ID = {0} 操作失败,请检查 DictHelper.SaveDict 方法", dict.Id));
var dest = DictHelper.RetrieveDicts().Where(d => d.Id == dict.Id);
Assert.IsTrue(dest.Count() == 1, "带参数的DictHelper.RetrieveDicts方法调用失败");
Assert.AreEqual(dict.Name, dest.First().Name, string.Format("更新字典记录ID = {0} 操作失败,请检查 DictHelper.SaveDict 方法", dict.Id));
}
[TestMethod]
public void DeleteDictTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var dict = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == Dict.Category);
if (dict == null) DictHelper.SaveDict(Dict);
dict = DictHelper.RetrieveDicts().FirstOrDefault(d => d.Category == Dict.Category);
Assert.IsTrue(DictHelper.DeleteDict(dict.Id.ToString()), "DictHelper.DeleteDict 方法调用失败");
}
}
}

View File

@ -1,27 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Specialized;
namespace Bootstrap.DataAccess.Tests
{
[TestClass()]
public class ExceptionHelperTests
{
[TestMethod()]
public void LogTest()
{
try
{
throw new Exception("Just for Test", new Exception("Inner Exception"));
}
catch (Exception ex)
{
var nv = new NameValueCollection();
nv.Add("ErrorPage", "UnitTest_Page");
nv.Add("UserIp", "::1");
nv.Add("UserId", "UnitTest");
ExceptionHelper.Log(ex, nv);
}
}
}
}

View File

@ -1,114 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class GroupHelperTests
{
private Group Group { get; set; }
private User User { get; set; }
private Role Role { get; set; }
[TestInitialize]
public void IniInitialized()
{
Group = new Group() { GroupName = "_测试部门_", Description = "我是很厉害的测试部门" };
User = new User() { UserName = "_测试用户_", Password = "123", PassSalt = "123", DisplayName = "测试者", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试用户" };
Role = new Role() { RoleName = "_测试角色_", Description = "测试角色" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Delete from Groups where GroupName = '_测试部门_'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveGroupsTest()
{
Assert.IsTrue(GroupHelper.RetrieveGroups().Count() >= 0, "不带参数的GroupHelper.RetrieveGroups方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void SaveGroupTest()
{
// 测试插入部门方法 ID=0
Assert.IsTrue(GroupHelper.SaveGroup(Group), "插入部门操作失败请检查GroupHelper.SaveGroup方法");
var groups = GroupHelper.RetrieveGroups();
Assert.IsTrue(groups.Count() > 0, "插入部门操作失败请检查GroupHelper.SaveGroup方法");
//测试更新部门方法 ID!=0
var group = groups.FirstOrDefault(g => g.GroupName == Group.GroupName);
group.Description = "我是测试部门";
Assert.IsTrue(GroupHelper.SaveGroup(group), string.Format("更新部门ID={0}操作失败请检查GroupHelper.SaveGroup方法", group.Id));
var ret = GroupHelper.RetrieveGroups(group.Id);
Assert.IsTrue(ret.Count() == 1, "带参数的GroupHelper.RetrieveGroups方法失败");
Assert.AreEqual(group.Description, ret.First().Description, string.Format("更新部门ID={0}操作失败请检查GroupHelper.SaveGroup方法", group.Id));
}
[TestMethod]
public void DeleteGroupTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
Assert.IsTrue(GroupHelper.DeleteGroup(group.Id.ToString()), "GroupHelper.DeleteGroup 方法调用失败");
}
[TestMethod]
public void SaveGroupsByUserIdTest()
{
var user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
var group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
Assert.IsTrue(GroupHelper.SaveGroupsByUserId(user.Id, group.Id.ToString()), "存储用户部门信息失败");
Assert.IsTrue(GroupHelper.RetrieveGroupsByUserId(user.Id).Count() >= 1, string.Format("获取用户ID={0}的部门失败", user.Id));
//删除数据
string sql = "Delete from Users where UserName = '_测试用户_';";
sql += "Delete from Groups where GroupName='_测试部门_';";
sql += string.Format("Delete from UserGroup where UserID={0};", user.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveGroupsByRoleIdTest()
{
var group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
Assert.IsTrue(GroupHelper.SaveGroupsByRoleId(role.Id, group.Id.ToString()), "存储角色部门信息失败");
Assert.IsTrue(GroupHelper.RetrieveGroupsByRoleId(role.Id).Count() >= 1, string.Format("获取角色ID={0}的部门信息失败", role.Id));
//删除数据
string sql = "Delete from Groups where GroupName = '_测试部门_';";
sql += "Delete from Roles where RoleName='_测试角色_';";
sql += string.Format("Delete from RoleGroup where RoleID={0};", role.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
}
}

View File

@ -1,47 +0,0 @@
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data.Common;
using System.Data;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class LogHelperTests
{
private Log Log { get; set; }
[TestInitialize]
public void Initialized()
{
Log = new Log() { CRUD = "Test", RequestUrl = "Test", UserName = "_测试用户名称_", ClientIp = "0.0.0.0", ClientAgent = "Test" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "delete from Logs where UserName='_测试用户名称_'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveLogsTest()
{
Assert.IsTrue(LogHelper.RetrieveLogs().Count() >= 0, "带有参数的LogHelper.RetrieveLogs方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void SaveLogTest()
{
Assert.IsTrue(LogHelper.SaveLog(Log), "新增日志信息出错,请检查LogHelper的SaveLog 方法");
var logs = LogHelper.RetrieveLogs();
Assert.IsTrue(logs.Count() > 0, "新增日志信息出错,请检查LogHelper的SaveLog 方法");
}
[TestMethod]
public void DeleteLogTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var log = LogHelper.RetrieveLogs().FirstOrDefault(l => l.UserName == Log.UserName);
if (log == null) LogHelper.SaveLog(Log);
log = LogHelper.RetrieveLogs().FirstOrDefault(l => l.UserName == Log.UserName);
Assert.IsTrue(LogHelper.DeleteLog(log.Id.ToString()), "删除日志信息出错");
}
}
}

View File

@ -1,112 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class MenuHelperTests
{
private Menu Menu { get; set; }
private Role Role { get; set; }
[TestInitialize]
public void Initialized()
{
Menu = new Menu() { Name = "__测试菜单__", Order = 999, Category = "0" };
Role = new Role() { RoleName = "_测试角色_", Description = "这是一个测试角色", Checked = "0" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Delete from Navigations where Name = '__测试菜单__'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveMenusTest()
{
Assert.IsTrue(MenuHelper.RetrieveMenus().Count() > 1, "不带参数的MenuHelper.RetrieveMenus方法调用失败");
}
[TestMethod]
public void RetrieveMenuByRoleIDTest()
{
Assert.IsTrue(MenuHelper.RetrieveMenusByRoleId(1).Count() >= 0, "根据角色ID查询菜单的MenuHelper.RetrieveMenusByRoleId方法调用失败");
}
[TestMethod]
public void SaveMenuTest()
{
// 测试插入菜单方法 ID = 0
Assert.IsTrue(MenuHelper.SaveMenu(Menu), "插入菜单操作失败,请检查 MenuHelper.SaveMenu 方法");
var menus = MenuHelper.RetrieveMenus();
Assert.IsTrue(menus.Count() > 0, "插入菜单操作失败,请检查 MenuHelper.SaveMenu 方法");
// 测试更新菜单方法 ID != 0
var menu = menus.FirstOrDefault(m => m.Name == Menu.Name);
menu.Icon = "fa";
Assert.IsTrue(MenuHelper.SaveMenu(menu), string.Format("更新菜单ID = {0} 操作失败,请检查 MenuHelper.SaveMenu 方法", menu.Id));
}
[TestMethod]
public void DeleteMenuTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
if (menu == null) MenuHelper.SaveMenu(Menu);
menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
Assert.IsTrue(MenuHelper.DeleteMenu(menu.Id.ToString()), "MenuHelper.DeleteMenu 方法调用失败");
}
[TestMethod]
public void SavaRolesByMenuIdTest()
{
var menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
if (menu == null) MenuHelper.SaveMenu(Menu);
menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
var role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
Assert.IsTrue(RoleHelper.SavaRolesByMenuId(menu.Id, role.Id.ToString()), "保存菜单角色关系失败");
Assert.IsTrue(RoleHelper.RetrieveRolesByMenuId(menu.Id).Count() > 0, string.Format("获取菜单ID={0}的角色关系失败", menu.Id));
//删除数据
string sql = "delete from Navigations where Name='__测试菜单__';";
sql += "delete from Roles where RoleName='_测试角色_';";
sql += string.Format("delete from NavigationRole where NavigationID={0}", menu.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveMenusByRoleIdTest()
{
var menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
if (menu == null) MenuHelper.SaveMenu(Menu);
menu = MenuHelper.RetrieveMenus().FirstOrDefault(m => m.Name == Menu.Name);
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
Assert.IsTrue(MenuHelper.SaveMenusByRoleId(role.Id, menu.Id.ToString()), "存储角色菜单信息失败");
int x = MenuHelper.RetrieveMenusByRoleId(role.Id).Count();
Assert.IsTrue(x >= 1, string.Format("获取角色ID={0}的菜单信息失败", role.Id));
//删除数据
string sql = "Delete from Navigations where Name = '__测试菜单__';";
sql += "Delete from Roles where RoleName='_测试角色_';";
sql += string.Format("Delete from NavigationRole where RoleID={0};", role.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
}
}

View File

@ -1,20 +0,0 @@
using Bootstrap.DataAccess;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Linq;
namespace Bootstrap.DataAccessTests
{
[TestClass]
public class NotificationHelperTest
{
[TestMethod]
public void RetrieveNotificationsTest()
{
Assert.IsTrue(NotificationHelper.RetrieveNotifications().Count() >= 0, "带参数的NotificationHelper.RetrieveNotifications方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void ProcessRegisterUserTest()
{
Assert.IsTrue(NotificationHelper.ProcessRegisterUser("1"), "带参数的NotificationHelper.ProcessRegisterUser方法调用失败请检查数据库连接或者数据库SQL语句");
}
}
}

View File

@ -1,35 +0,0 @@
using System.Reflection;
using System.Runtime.InteropServices;
// 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: AssemblyTitle("Bootstrap.DataAccessTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Bootstrap.DataAccessTests")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 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)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("d3a9d339-6e5e-416d-bb71-d3aae105bd16")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@ -1,105 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class RoleTests
{
private Role Role { get; set; }
private User User { get; set; }
private Group Group { get; set; }
[TestInitialize]
public void Initialized()
{
Role = new Role() { RoleName = "_测试角色_", Description = "这是一个测试角色", Checked = "0" };
User = new User() { UserName = "_测试用户_", Password = "111", PassSalt = "111", DisplayName = "_测试用户_", Checked = "0", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试用户" };
Group = new Group() { GroupName = "_测试部门_", Description = "这是一个测试部门", Checked = "0" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "delete from Roles where RoleName='_测试角色_'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveRoleTest()
{
//测试添加角色方法 ID = 0
Assert.IsTrue(RoleHelper.SaveRole(Role), "添加角色操作失败请检查RoleHelper.SaveRole方法");
var roles = RoleHelper.RetrieveRoles();
Assert.IsTrue(roles.Count() > 0, "添加角色操作失败请检查RoleHelper.SaveRole方法");
//测试编辑角色方法 ID != 0
var role = roles.FirstOrDefault(m => m.RoleName == Role.RoleName);
role.Description = "这是修改后的测试角色";
Assert.IsTrue(RoleHelper.SaveRole(role), string.Format("更新角色ID={0}操作失败请检查RoleHelper.SaveRole方法", role.Id));
var ret = RoleHelper.RetrieveRoles(role.Id);
Assert.IsTrue(ret.Count() == 1, "带参数的RoleHelper.RetrieveRoles方法调用失败");
Assert.AreEqual(role.Description, ret.First().Description, string.Format("更新角色ID={0}操作失败请检查RoleHelper.SaveRole方法", role.Id));
}
[TestMethod]
public void RetrieveRoleTest()
{
var result = RoleHelper.RetrieveRoles();
Assert.IsTrue(result.Count() >= 0, "不带参数的RoleHelper.RetrieveRole方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void DeleteRoleTest()
{
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == "_测试角色_");
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == "_测试角色_");
Assert.IsTrue(RoleHelper.DeleteRole(role.Id.ToString()), "删除角色失败");
}
[TestMethod]
public void SaveRolesByUserIdTest()
{
var role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
var user = UserHelper.RetrieveUsers().FirstOrDefault(m => m.DisplayName == User.DisplayName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(m => m.DisplayName == User.DisplayName);
Assert.IsTrue(RoleHelper.SaveRolesByUserId(user.Id, role.Id.ToString()), "保存用户角色关系失败");
Assert.IsTrue(RoleHelper.RetrieveRolesByUserId(user.Id).Count() >= 1, string.Format("获取用户ID={0}的角色信息失败", user.Id));
//删除数据
string sql = "delete from Roles where RoleName='_测试角色_';";
sql += "delete from Users where UserName='_测试用户_';";
sql += string.Format("delete from UserRole where UserID={0}", user.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveRoleByGroupIDTest()
{
var role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(m => m.RoleName == Role.RoleName);
var group = GroupHelper.RetrieveGroups().FirstOrDefault(m => m.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(m => m.GroupName == Group.GroupName);
Assert.IsTrue(RoleHelper.SaveRolesByGroupId(group.Id, role.Id.ToString()), "保存部门角色关系失败");
Assert.IsTrue(RoleHelper.RetrieveRolesByGroupId(group.Id).Count() > 0, string.Format("获取部门ID={0}的角色关系失败", group.Id));
//删除数据
string sql = "delete from Roles where RoleName='_测试角色_';";
sql += "delete from Groups where GroupName='_测试部门_';";
sql += string.Format("delete from RoleGroup where GroupID={0}", group.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
}
}

View File

@ -1,116 +0,0 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using System.Data.Common;
using System.Linq;
namespace Bootstrap.DataAccess.Tests
{
[TestClass]
public class UserHelperTests
{
private User User { get; set; }
private Role Role { get; set; }
private Group Group { get; set; }
[TestInitialize]
public void Initialized()
{
User = new User() { UserName = "_测试用户_", Password = "123", PassSalt = "123", DisplayName = "测试者", RegisterTime = DateTime.Now, ApprovedTime = DateTime.Now, Description = "测试" };
Role = new Role() { RoleName = "_测试角色_", Description = "测试角色" };
Group = new Group() { GroupName = "_测试部门_", Description = "测试部门" };
}
[TestCleanup]
public void CleanUp()
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Delete from Users where UserName = '_测试用户_'"))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void RetrieveUsersTest()
{
Assert.IsTrue(UserHelper.RetrieveUsers().Count() >= 1, "不带参数的UserHelper.RetrieveUsers方法调用失败请检查数据库连接或者数据库SQL语句");
}
[TestMethod]
public void SaveUserTest()
{
// 测试插入用户方法 ID = 0
Assert.IsTrue(UserHelper.SaveUser(User), "插入用户操作失败请检查UserHelper.SaveUser 方法");
var users = UserHelper.RetrieveUsers();
Assert.IsTrue(users.Count() > 0, "插入用户操作失败请检查UserHelper.SaveUser 方法");
// 测试更新用户方法 ID != 0
var user = users.FirstOrDefault(u => u.UserName == User.UserName);
user.DisplayName = "测试者2号";
user.Description = "测试";
Assert.IsTrue(UserHelper.SaveUser(user), string.Format("更新用户ID={0}操作失败请检查UserHelper.SaveUser方法", user.Id));
var ret = UserHelper.RetrieveUsers(user.Id);
Assert.IsTrue(ret.Count() == 1, "带参数的UserHelper.RetrieveUsers方法调用失败");
Assert.AreEqual(user.DisplayName, ret.First().DisplayName, string.Format("更新用户ID={0}操作失败请检查UserHelper.SaveUser方法", user.Id));
}
[TestMethod]
public void DeleteUserTest()
{
// 先判断数据环境是否可以删除,没有数据先伪造数据
var user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
Assert.IsTrue(UserHelper.DeleteUser(user.Id.ToString()), "UserHelper.DeleteUserTest方法调用失败");
}
[TestMethod]
public void SaveUsersByRoleIdTest()
{
var user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
var role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
if (role == null) RoleHelper.SaveRole(Role);
role = RoleHelper.RetrieveRoles().FirstOrDefault(r => r.RoleName == Role.RoleName);
Assert.IsTrue(UserHelper.SaveUsersByRoleId(role.Id, user.Id.ToString()), "存储角色用户信息失败");
Assert.IsTrue(UserHelper.RetrieveUsersByRoleId(role.Id).Count() >= 1, string.Format("获取角色ID={0}的用户信息失败", role.Id));
//删除数据
string sql = "Delete from Users where UserName = '_测试用户_';";
sql += "Delete from Roles where RoleName='_测试角色_';";
sql += string.Format("Delete from UserRole where RoleID={0};", role.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
[TestMethod]
public void SaveUsersByGroupIdTest()
{
var user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
if (user == null) UserHelper.SaveUser(User);
user = UserHelper.RetrieveUsers().FirstOrDefault(u => u.UserName == User.UserName);
var group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
if (group == null) GroupHelper.SaveGroup(Group);
group = GroupHelper.RetrieveGroups().FirstOrDefault(g => g.GroupName == Group.GroupName);
Assert.IsTrue(UserHelper.SaveUsersByGroupId(group.Id, user.Id.ToString()), "存储部门用户信息失败");
Assert.IsTrue(UserHelper.RetrieveUsersByGroupId(group.Id).Count() >= 1, string.Format("获取部门ID={0}的用户失败", group.Id));
//删除数据
string sql = "Delete from Users where UserName = '_测试用户_';";
sql += "Delete from Groups where GroupName='_测试部门_';";
sql += string.Format("Delete from UserGroup where GroupID={0};", group.Id);
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
}
}
}

View File

@ -27,8 +27,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scripts", "Scripts", "{5864
Scripts\Publish.vbs = Scripts\Publish.vbs
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.DataAccessTests", "Bootstrap.DataAccessTests\Bootstrap.DataAccessTests.csproj", "{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.Client", "Bootstrap.Client\Bootstrap.Client.csproj", "{6B261B2C-9E70-467C-BE76-13C0E280A683}"
EndProject
Global
@ -45,10 +43,6 @@ Global
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7B2B7043-3CB2-4C5A-BDF2-8C47F1A5471A}.Release|Any CPU.Build.0 = Release|Any CPU
{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D3A9D339-6E5E-416D-BB71-D3AAE105BD16}.Release|Any CPU.Build.0 = Release|Any CPU
{6B261B2C-9E70-467C-BE76-13C0E280A683}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B261B2C-9E70-467C-BE76-13C0E280A683}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B261B2C-9E70-467C-BE76-13C0E280A683}.Release|Any CPU.ActiveCfg = Release|Any CPU

Binary file not shown.