拆分通知管理功能,页头分为5块通知,改由jQuery调用,减少服务器响应时间

This commit is contained in:
Argo-Lenovo 2016-11-18 10:18:41 +08:00
parent ad4408f9e3
commit 04f778b322
14 changed files with 309 additions and 263 deletions

View File

@ -441,7 +441,7 @@
padding-top: 2px;
}
.notify-row .dropdown-menu.notification > li > a > div {
.notify-row .dropdown-menu.notification li a div {
position: absolute;
left: 36px;
right: 44px;

View File

@ -45,4 +45,19 @@
// custom scrollbar
if (!$.browser.versions.ios) $("#sidebar").niceScroll({ styler: "fb", cursorcolor: "#e8403f", cursorwidth: '3', cursorborderradius: '10px', background: '#404040', spacebarenabled: false, cursorborder: '', scrollspeed: 60 });
// load widget data
Notifications.retrieveAllNotifies(function (result) {
$('#logoutNoti').text(result.NewUsersCount);
// new users
$('#msgHeaderUser').text(result.NewUsersCount);
$('#msgHeaderUserBadge').text(result.NewUsersCount);
var htmlUserTemplate = '<li><a href="../Admin/Notifications"><span class="label label-success"><i class="fa fa-plus"></i></span><div title="{1}">{0}({1})</div><span class="small italic">{2}</span></a></li>';
var html = result.Users.map(function (u) {
return $.format(htmlUserTemplate, u.UserName, u.DisplayName, u.Period);
}).join('');
$(html).insertAfter($('#msgHeaderUserContent'));
console.log(result);
});
});

View File

@ -255,7 +255,7 @@
var htmlTemplate = '<div class="form-group checkbox col-lg-3 col-xs-4"><label class="tooltips" data-placement="top" data-original-title="{3}" title="{3}"><input type="checkbox" value="{0}" {2}/>{1}</label></div>';
var processData = function (options) {
var data = $.extend({ data: { type: "" }, remote: true, method: "POST", Id: "", url: this.url, title: this.title, html: this.html, swal: true }, options);
var data = $.extend({ data: {}, remote: true, method: "POST", Id: "", url: this.url, title: this.title, html: this.html, swal: true }, options);
if (data.remote) {
$.ajax({
@ -288,7 +288,7 @@
else { swal("失败", data.title, "error"); }
}
}
}
};
// Roles
Role = {
url: '../api/Roles/',
@ -310,10 +310,10 @@
};
Role.saveRolesByUserId = function (userId, roleIds, callback) {
processData.call(this, { Id: userId, callback: callback, method: "PUT", data: { type: "user", roleIds: roleIds } });
}
};
Role.saveRolesByGroupId = function (groupId, roleIds, callback) {
processData.call(this, { Id: groupId, callback: callback, method: "PUT", data: { type: "group", roleIds: roleIds } });
}
};
Role.saveRolesByMenuId = function (menuId, roleIds, callback) {
processData.call(this, { Id: menuId, callback: callback, method: "PUT", data: { type: "menu", roleIds: roleIds } });
};
@ -326,7 +326,7 @@
return $.format(htmlTemplate, element.ID, element.DisplayName, element.Checked, element.UserName);
}).join('');
}
}
};
User.getUsersByRoleId = function (roleId, callback) {
processData.call(this, { Id: roleId, callback: callback, data: { type: "role" } });
};
@ -340,12 +340,14 @@
processData.call(this, { Id: groupId, callback: callback, method: "PUT", data: { type: "group", userIds: userIds } });
};
User.saveUserDisplayName = function (user, callback) {
processData.call(this, { Id: '', callback: callback, method: "PUT", data: user,title:"修改用户显示名称" });
processData.call(this, { Id: '', callback: callback, method: "PUT", data: user, title: "修改用户显示名称" });
};
User.changePassword = function (user) {
processData.call(this, { Id: '', method: "PUT", data: user, title: "修改密码" });
}
processData.call(this, { Id: '', method: "PUT", data: user });
};
User.processUser = function (id, result, callback) {
processData.call(this, { Id: id, callback: callback, method: "PUT", data: { type: "user", userIds: result }, title: result == "1" ? "授权用户" : "拒绝用户" });
};
// Groups
Group = {
url: '../api/Groups/',
@ -380,7 +382,7 @@
}
return htmlString;
}
}
};
Menu.cascadeMenu = function (menus) {
var html = "";
$.each(menus, function (index, menu) {
@ -392,7 +394,7 @@
}
});
return html;
}
};
Menu.getMenus = function (callback) {
processData.call(this, { Id: 0, callback: callback, data: { type: "user" } });
};
@ -407,10 +409,10 @@
Profiles = {
url: '../api/Profiles/',
title: "个性化维护"
}
};
Profiles.saveWebSite = function (options) {
processData.call(this, { data: options });
}
};
// Exceptions
Exceptions = {
@ -421,19 +423,30 @@
return $.format('<div class="form-group col-lg-3 col-md-3 col-sm-4 col-xs-6"><a class="logfile" href="#"><i class="fa fa-file-text-o"></i><span>{0}</span></a></div>', ele);
}).join('');
}
}
};
Exceptions.getFiles = function (callback) {
processData.call(this, { Id: "", callback: callback, swal: false });
}
Exceptions.getFileByName = function (fileName, callback) {
processData.call(this, { Id: "", callback: callback, method: "PUT", swal: false, data: { "": fileName } });
}
};
// Dicts
Dicts = {
url: '../api/Dicts/'
}
};
Dicts.retrieveCategories = function (callback) {
processData.call(this, { Id: 1, callback: callback, swal: false, data: { type: 'category' } });
};
// Notifi
Notifications = {
url: '../api/Notifications/'
};
Notifications.retrieveNotifies = function (category, callback) {
processData.call(this, { Id: category, callback: callback, method: "GET", swal: false });
};
Notifications.retrieveAllNotifies = function (callback) {
processData.call(this, { Id: "", callback: callback, method: "GET", swal: false });
}
})(jQuery);

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Web.Http;
using System.Linq;
using System;
namespace Bootstrap.Admin.Controllers
{
@ -15,12 +16,20 @@ namespace Bootstrap.Admin.Controllers
public Notifications Get()
{
var ret = new Notifications();
NotificationHelper.RetrieveNotifications().AsParallel().ForAll(n =>
{
if (n.Category == "0") ret.Users.Add(n);
else if (n.Category == "1") ret.Apps.Add(n);
else if (n.Category == "2") ret.Dbs.Add(n);
});
// New Users
var user = UserHelper.RetrieveNewUsers();
ret.Users = user.Take(6).OrderByDescending(u => u.RegisterTime).ToList();
ret.Users.AsParallel().ForAll(n =>
{
var ts = DateTime.Now - n.RegisterTime;
if (ts.TotalMinutes < 5) n.Period = "刚刚";
else if (ts.Days > 0) n.Period = string.Format("{0}天", ts.Days);
else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours);
else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes);
});
ret.NewUsersCount = user.Count();
// Tasks
return ret;
}
/// <summary>
@ -32,13 +41,9 @@ namespace Bootstrap.Admin.Controllers
public Notifications Get(string id)
{
var ret = new Notifications();
NotificationHelper.RetrieveNotifications().AsParallel().ForAll(n =>
{
if (id != n.Category) return;
if (n.Category == "0") ret.Users.Add(n);
else if (n.Category == "1") ret.Apps.Add(n);
else if (n.Category == "2") ret.Dbs.Add(n);
});
if (id == "newusers" || id == "all") ret.Users = UserHelper.RetrieveNewUsers().OrderByDescending(u => u.RegisterTime).ToList();
else if (id == "apps" || id == "all") ret.Apps = new List<Exceptions>();
else if (id == "dbs" || id == "all") ret.Dbs = new List<Exceptions>();
return ret;
}
@ -46,15 +51,52 @@ namespace Bootstrap.Admin.Controllers
{
public Notifications()
{
Users = new List<Notification>();
Apps = new List<Notification>();
Dbs = new List<Notification>();
Users = new List<User>();
Apps = new List<Exceptions>();
Dbs = new List<Exceptions>();
Tasks = new List<Task>();
Messages = new List<Message>();
}
public List<Notification> Users { get; set; }
public List<Notification> Apps { get; set; }
public List<Notification> Dbs { get; set; }
/// <summary>
///
/// </summary>
public List<User> Users { get; set; }
/// <summary>
///
/// </summary>
public List<Exceptions> Apps { get; set; }
/// <summary>
///
/// </summary>
public List<Exceptions> Dbs { get; set; }
/// <summary>
///
/// </summary>
public List<Task> Tasks { get; set; }
/// <summary>
///
/// </summary>
public List<Message> Messages { get; set; }
/// <summary>
/// 获得/设置 消息数量
/// </summary>
public int MessagesCount { get; set; }
/// <summary>
/// 获得/设置 新用户数量
/// </summary>
public int NewUsersCount { get; set; }
/// <summary>
/// 获取/设置 任务数量
/// </summary>
public int TasksCount { get; set; }
/// <summary>
/// 获取/设置 应用程序错误数量
/// </summary>
public int AppExceptionsCount { get; set; }
/// <summary>
/// 获取/设置 数据库错误数量
/// </summary>
public int DbExceptionsCount { get; set; }
}
}
}

View File

@ -2,7 +2,6 @@
using Bootstrap.DataAccess;
using Longbow.Security.Principal;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
@ -66,7 +65,6 @@ namespace Bootstrap.Admin.Controllers
}
return ret;
}
/// <summary>
///
/// </summary>
@ -88,7 +86,12 @@ namespace Bootstrap.Admin.Controllers
value.ApprovedBy = User.Identity.Name;
return UserHelper.SaveUser(value);
}
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <returns></returns>
[HttpPut]
public bool Put(int id, [FromBody]JObject value)
{
@ -122,7 +125,6 @@ namespace Bootstrap.Admin.Controllers
}
return ret;
}
/// <summary>
///
/// </summary>

View File

@ -1,6 +1,5 @@
using Bootstrap.DataAccess;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Bootstrap.Admin.Models
@ -19,16 +18,6 @@ namespace Bootstrap.Admin.Models
UserID = user.ID;
HomeUrl = "~/";
Menus = MenuHelper.RetrieveLinksByUserName(UserName);
var notis = NotificationHelper.RetrieveNotifications();
NotifiCount = notis.Count();
Notifications = notis.Take(6);
var msgs = MessageHelper.RetrieveMessagesHeader(UserName);
MessageCount = msgs.Count();
Messages = msgs.Take(6);
MessageList = MessageHelper.RetrieveMessages(UserName);
var tasks = TaskHelper.RetrieveTasks();
TaskCount = tasks.Count();
Tasks = tasks.Take(6);
}
public string UserName { get; protected set; }
/// <summary>
@ -52,37 +41,12 @@ namespace Bootstrap.Admin.Models
/// </summary>
public IEnumerable<Menu> Menus { get; private set; }
/// <summary>
/// 获得/设置 通知内容集合
/// </summary>
public IEnumerable<Notification> Notifications { get; set; }
/// <summary>
/// 获得/设置 通知数量
/// </summary>
public int NotifiCount { get; set; }
/// <summary>
/// 获得/设置 消息列表
/// </summary>
public IEnumerable<Message> Messages { get; set; }
/// <summary>
/// 获得/设置 消息数量
/// </summary>
public int MessageCount { get; set; }
/// <summary>
/// 获得/设置 消息列表
/// </summary>
public IEnumerable<Message> MessageList { get; set; }
/// <summary>
///
/// 获得/设置 用户头像地址
/// </summary>
public string Icon { get; set; }
/// <summary>
/// 获取/设置 任务数量
/// </summary>
public int TaskCount { get; set; }
/// <summary>
/// 获取/设置 任务内容集合
/// </summary>
public IEnumerable<Task> Tasks { get; set; }
}
}

View File

@ -1,43 +1,34 @@
$(function () {
var url = '../api/Notifications/';
var htmlNewUsers = '<li class="list-primary"><i class="fa fa-ellipsis-v"></i><div class="task-title notifi"><span class="task-title-sp">{0}</span><span class="task-value">{1}</span><span class="task-time">{2}</span><div class="pull-right hidden-phone"><button class="btn btn-success btn-xs fa fa-check" data-id="{3}" data-result="1"></button><button class="btn btn-danger btn-xs fa fa-remove" data-id="{3}" data-result="0" data-placement="left" data-original-title="拒绝授权"></button></div></div></li>';
var htmlApp = '<li class="list-warning"><i class="fa fa-ellipsis-v"></i><div class="task-title notifi"><span class="task-title-sp">{0}</span><span class="task-value">{1}</span><span class="task-time">{2}</span><div class="pull-right hidden-phone"><a href="../Admin/Exceptions?id={3}" class="btn btn-warning btn-xs fa fa-bug"></a></div></div></li>';
var htmlDb = '<li class="list-danger"><i class="fa fa-ellipsis-v"></i><div class="task-title notifi"><span class="task-title-sp">{0}</span><span class="task-value">{1}</span><span class="task-time">{2}</span><div class="pull-right hidden-phone"><a href="../Admin/Exceptions?id={3}" class="btn btn-danger btn-xs fa fa-database"></a></div></div></li>';
function listData(options) {
options = $.extend({ url: url, animation: true, ctl: $('a.fa-refresh') }, options);
var category = options.ctl.length == 1 ? options.ctl.attr('data-category') : "";
options = $.extend({ animation: true, ctl: $('a.fa-refresh') }, options);
var category = options.ctl.length == 1 ? options.ctl.attr('data-category') : "all";
if (options.animation) options.ctl.toggleClass('fa-spin');
$.ajax({
url: options.url + category,
type: 'GET',
success: function (result) {
if (result) {
if (category == '0' || category == '') {
var content = result.Users.map(function (noti) {
return $.format(htmlNewUsers, noti.Title, noti.Content, noti.RegisterTime, noti.ID);
}).join('');
$('#tasks-users').html(content);
}
if (category == '1' || category == '') {
var content = result.Apps.map(function (noti) {
return $.format(htmlApp, noti.Title, noti.Content, noti.RegisterTime, noti.ID);
}).join('');
$('#tasks-app').html(content);
}
if (category == '2' || category == '') {
var content = result.Dbs.map(function (noti) {
return $.format(htmlDb, noti.Title, noti.Content, noti.RegisterTime, noti.ID);
}).join('');
$('#tasks-db').html(content);
}
Notifications.retrieveNotifies(category, function (result) {
if (result) {
if (category == 'newusers' || category == 'all') {
var content = result.Users.map(function (noti) {
return $.format(htmlNewUsers, noti.UserName, noti.Description, noti.RegisterTime, noti.ID);
}).join('');
$('#tasks-users').html(content);
}
if (category == 'apps' || category == 'all') {
var content = result.Apps.map(function (noti) {
return $.format(htmlApp, noti.Title, noti.Content, noti.RegisterTime, noti.ID);
}).join('');
$('#tasks-app').html(content);
}
if (category == 'dbs' || category == 'all') {
var content = result.Dbs.map(function (noti) {
return $.format(htmlDb, noti.Title, noti.Content, noti.RegisterTime, noti.ID);
}).join('');
$('#tasks-db').html(content);
}
if (options.animation) options.ctl.toggleClass('fa-spin');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (options.animation) options.ctl.toggleClass('fa-spin');
}
if (options.animation) options.ctl.toggleClass('fa-spin');
});
}
listData();
@ -49,21 +40,9 @@
$('#tasks-users').on('click', 'button', function () {
var id = $(this).attr('data-id');
var result = $(this).attr('data-result');
var data = { type: "user", userIds: result };
var title = result == "1" ? "授权用户" : "拒绝用户";
$.ajax({
url: '../api/Users/' + id,
data: data,
type: 'PUT',
success: function (result) {
if (result) swal("成功!", title, "success");
else swal("失败", title, "error");
var refresh = $('#tasks-users').parentsUntil('div.panel').last().prev().find('a.fa-refresh');
listData(refresh);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
swal("失败", title, "error");
}
User.processUser(id, result, function (result) {
var refresh = $('#tasks-users').parentsUntil('div.panel').last().prev().find('a.fa-refresh');
listData(refresh);
});
});
});

View File

@ -18,7 +18,7 @@
@Html.Partial("Navigator", Model)
}
<div class="panel panel-default">
<div class="panel-heading">用户注册<span class="pull-right"><a href="javascript:;" class="fa fa-refresh" data-category="0"></a></span></div>
<div class="panel-heading">用户注册<span class="pull-right"><a href="javascript:;" class="fa fa-refresh" data-category="newusers"></a></span></div>
<div class="panel-body">
<div class="tasks-widget">
<ul id="tasks-users" class="task-list ui-sortable">
@ -27,7 +27,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">程序错误<a href="javascript:;" class="pull-right fa fa-refresh" data-category="1"></a></div>
<div class="panel-heading">程序错误<a href="javascript:;" class="pull-right fa fa-refresh" data-category="apps"></a></div>
<div class="panel-body">
<div class="tasks-widget">
<ul id="tasks-app" class="task-list ui-sortable">
@ -36,7 +36,7 @@
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">数据库错误<span class="pull-right"><a href="javascript:;" class="fa fa-refresh" data-category="2"></a></span></div>
<div class="panel-heading">数据库错误<span class="pull-right"><a href="javascript:;" class="fa fa-refresh" data-category="dbs"></a></span></div>
<div class="panel-body">
<div class="tasks-widget">
<ul id="tasks-db" class="task-list ui-sortable">

View File

@ -23,119 +23,95 @@
}
@if (!Model.ShowMenu)
{
<!-- notification start -->
<!-- notification start -->
<ul class="notify-row">
<!-- settings start -->
@if (Model.TaskCount > 0)
{
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="fa fa-tasks"></i>
<span class="badge bg-success">@Model.TaskCount</span>
</a>
<ul class="dropdown-menu tasks-bar">
<div class="notify-arrow notify-arrow-green"></div>
<li>
<p>您有 @Model.TaskCount 个未读的消息</p>
</li>
@foreach (var task in Model.Tasks)
{
var TaskProgress = task.TaskProgress * 100;
<li>
<a href="~/Admin/Tasks?id=@task.ID">
<div>
<div class="desc">@task.TaskName</div>
<div class="percent">@TaskProgress%</div>
</div>
<div class="progress progress-striped">
<div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="@TaskProgress" aria-valuemin="0" aria-valuemax="100" style="width: @TaskProgress%">
<span class="sr-only">@TaskProgress% Complete</span>
</div>
</div>
</a>
</li>
}
<li>
<a href="~/Admin/Tasks">查看所有消息</a>
</li>
</ul>
</li>
}
<!-- settings end -->
<!-- tasks start -->
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="fa fa-tasks"></i>
<span class="badge bg-success"></span>
</a>
<ul class="dropdown-menu tasks-bar">
<div class="notify-arrow notify-arrow-green"></div>
<li>
<p>您有 0 个未读的消息</p>
</li>
<li>
<a href="~/Admin/Tasks">查看所有消息</a>
</li>
</ul>
</li>
<!-- tasks end -->
<!-- message dropdown start-->
@if (Model.MessageCount > 0)
{
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="fa fa-envelope-o"></i>
<span class="badge bg-important">@Model.MessageCount</span>
</a>
<ul class="dropdown-menu inbox">
<div class="notify-arrow notify-arrow-red"></div>
<li>
<p>您有 @Model.MessageCount 个未读的消息</p>
</li>
@foreach (var mess in Model.Messages)
{
<li>
<a href="~/Admin/Messages?id=@mess.ID">
<span class="photo"><img alt="avatar" src="~/content/images/logo6.jpg"></span>
<span class="subject">
<span class="from">@mess.From</span>
<span class="time">@mess.Period</span>
</span>
<span class="message">@mess.Title</span>
</a>
</li>
}
<li>
<a href="~/Admin/Messages">查看所有消息</a>
</li>
</ul>
</li>
}
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="fa fa-envelope"></i>
<span class="badge bg-important"></span>
</a>
<ul class="dropdown-menu inbox">
<div class="notify-arrow notify-arrow-red"></div>
<li>
<p>您有 0 个未读的消息</p>
</li>
<li>
<a href="~/Admin/Messages">查看所有消息</a>
</li>
</ul>
</li>
<!-- message dropdown end -->
<!-- notification dropdown start-->
@if (Model.NotifiCount > 0)
{
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="fa fa-bell-o"></i>
<span class="badge bg-warning">@Model.NotifiCount</span>
</a>
<ul class="dropdown-menu notification">
<div class="notify-arrow notify-arrow-yellow"></div>
<li>
<p>您有 @Model.NotifiCount 条新通知</p>
</li>
@foreach (var noti in Model.Notifications)
{
<li>
<a href="~/Admin/Notifications?id=@noti.ID&category=@noti.Category">
@if (noti.Category == "0")
{
<span class="label label-success"><i class="fa fa-plus"></i></span><div>@noti.Content</div><span class="small italic">@noti.Period</span>
}
else if (noti.Category == "1")
{
<span class="label label-warning"><i class="fa fa-bell"></i></span><div>@noti.Content</div><span class="small italic">@noti.Period</span>
}
else
{
<span class="label label-danger"><i class="fa fa-bolt"></i></span><div>@noti.Content</div><span class="small italic">@noti.Period</span>
}
</a>
</li>
}
<li>
<a href="~/Admin/Notifications">查看所有通知</a>
</li>
</ul>
</li>
}
<!-- notification dropdown end -->
<!-- users dropdown start-->
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="fa fa-user-plus"></i>
<span id="msgHeaderUserBadge" class="badge bg-warning"></span>
</a>
<ul class="dropdown-menu notification">
<div class="notify-arrow notify-arrow-yellow"></div>
<li id="msgHeaderUserContent">
<p>您有 <span id="msgHeaderUser">0</span> 条新通知</p>
</li>
<li id="msgHeaderUserFooter">
<a href="~/Admin/Notifications">查看所有通知</a>
</li>
</ul>
</li>
<!-- users dropdown end -->
<!-- apps dropdown start-->
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="fa fa-bug"></i>
<span class="badge bg-warning"></span>
</a>
<ul class="dropdown-menu notification">
<div class="notify-arrow notify-arrow-yellow"></div>
<li>
<p>您有 0 条新通知</p>
</li>
<li>
<a href="~/Admin/Notifications">查看所有通知</a>
</li>
</ul>
</li>
<!-- apps dropdown end -->
<!-- db dropdown start-->
<li class="dropdown">
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
<i class="fa fa-database"></i>
<span class="badge bg-warning"></span>
</a>
<ul class="dropdown-menu notification">
<div class="notify-arrow notify-arrow-yellow"></div>
<li>
<p>您有 0 条新通知</p>
</li>
<li>
<a href="~/Admin/Notifications">查看所有通知</a>
</li>
</ul>
</li>
<!-- db dropdown end -->
</ul>
<!-- notification end -->
<!-- notification end -->
}
<!--search & user info start-->
<ul class="pull-right top-menu">
@ -154,7 +130,7 @@
<div class="arrow-up"></div>
<li><a href="~/Admin/Infos"><i class=" fa fa-suitcase"></i>个人中心</a></li>
<li><a href="~/Admin/Index"><i class="fa fa-cog"></i>设置</a></li>
<li><a href="~/Admin/Notifications"><i class="fa fa-bell"></i>通知<span class="badge bg-success">@Model.NotifiCount</span></a></li>
<li><a href="~/Admin/Notifications"><i class="fa fa-bell"></i>通知<span id="logoutNoti" class="badge bg-success"></span></a></li>
<li><a href="~/Home/Logout"><i class="fa fa-key"></i>注销</a></li>
</ul>
</li>

View File

@ -18,22 +18,23 @@ namespace Bootstrap.DataAccess
bool ret = false;
try
{
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @Message, @StackTrace, GetDate())";
var sql = "insert into Exceptions (AppDomainName, ErrorPage, UserID, UserIp, ExceptionType, Message, StackTrace, LogTime) values (@AppDomainName, @ErrorPage, @UserID, @UserIp, @ExceptionType, @Message, @StackTrace, GetDate())";
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@AppDomainName", AppDomain.CurrentDomain.FriendlyName, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ErrorPage", additionalInfo["ErrorPage"], ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserID", DBAccess.ToDBValue(additionalInfo["UserId"]), ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@UserIp", additionalInfo["UserIp"], ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@ExceptionType", ex.GetType().FullName, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Message", ex.Message, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@StackTrace", DBAccess.ToDBValue(ex.StackTrace), ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
ret = true;
}
catch
catch (Exception e)
{
throw new Exception("Excetion Log Error");
throw new Exception("Excetion Log Error", e);
}
return ret;
}

View File

@ -1,15 +1,46 @@
using System;
namespace Bootstrap.DataAccess
{
public class Exceptions
{
public int ID { get; set; }
public string AppDomainName { get; set; }
public string ErrorPage { get; set; }
public string UserID { get; set; }
public string UserIp { get; set; }
public string Message { get; set; }
public string StackTrace { get; set; }
public DateTime LogTime { get; set; }
}
}
using System;
namespace Bootstrap.DataAccess
{
/// <summary>
///
/// </summary>
public class Exceptions
{
/// <summary>
///
/// </summary>
public int ID { get; set; }
/// <summary>
///
/// </summary>
public string AppDomainName { get; set; }
/// <summary>
///
/// </summary>
public string ErrorPage { get; set; }
/// <summary>
///
/// </summary>
public string UserID { get; set; }
/// <summary>
///
/// </summary>
public string UserIp { get; set; }
/// <summary>
///
/// </summary>
public string Message { get; set; }
/// <summary>
///
/// </summary>
public string StackTrace { get; set; }
/// <summary>
///
/// </summary>
public DateTime LogTime { get; set; }
/// <summary>
///
/// </summary>
public string ExceptionType { get; set; }
}
}

View File

@ -51,9 +51,7 @@ namespace Bootstrap.DataAccess
return notifications;
}, CacheSection.RetrieveDescByKey(RetrieveNotificationsDataKey));
var users = UserHelper.RetrieveNewUsers().Select(u => new Notification() { ID = u.ID, Category = "0", Content = u.Description, Title = u.DisplayName, RegisterTime = u.RegisterTime }).ToList();
var ret = users.Union(notifies);
ret.AsParallel().ForAll(n =>
notifies.AsParallel().ForAll(n =>
{
var ts = DateTime.Now - n.RegisterTime;
if (ts.TotalMinutes < 5) n.Period = "刚刚";
@ -61,9 +59,8 @@ namespace Bootstrap.DataAccess
else if (ts.Hours > 0) n.Period = string.Format("{0}小时", ts.Hours);
else if (ts.Minutes > 0) n.Period = string.Format("{0}分钟", ts.Minutes);
});
return ret.OrderByDescending(n => n.RegisterTime);
return notifies.OrderByDescending(n => n.RegisterTime);
}
/// <summary>
/// 点击某一行用户注册通知的处理成功操作
/// </summary>
@ -89,5 +86,31 @@ namespace Bootstrap.DataAccess
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="noti"></param>
/// <returns></returns>
public static bool SaveNotification(Notification noti)
{
bool ret = false;
if (string.IsNullOrEmpty(noti.Title) || string.IsNullOrEmpty(noti.Content)) return ret;
try
{
using (DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, "Insert into Notifications (Category, Title, Content, RegisterTime) values (N'2', @Title, @Content, GetDate())"))
{
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Title", noti.Title, ParameterDirection.Input));
cmd.Parameters.Add(DBAccessManager.SqlDBAccess.CreateParameter("@Content", noti.Content, ParameterDirection.Input));
DBAccessManager.SqlDBAccess.ExecuteNonQuery(cmd);
}
CacheCleanUtility.ClearCache(notifyIds: string.Empty);
ret = true;
}
catch (Exception ex)
{
ExceptionManager.Publish(ex);
}
return ret;
}
}
}

View File

@ -103,7 +103,7 @@ namespace Bootstrap.DataAccess
/// <returns></returns>
public static IEnumerable<User> RetrieveNewUsers()
{
var ret = CacheManager.GetOrAdd(RetrieveNewUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNewUsersDataKey), key =>
return CacheManager.GetOrAdd(RetrieveNewUsersDataKey, CacheSection.RetrieveIntervalByKey(RetrieveNewUsersDataKey), key =>
{
string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null and RejectedTime is null";
List<User> Users = new List<User>();
@ -128,7 +128,6 @@ namespace Bootstrap.DataAccess
catch (Exception ex) { ExceptionManager.Publish(ex); }
return Users;
}, CacheSection.RetrieveDescByKey(RetrieveNewUsersDataKey));
return ret;
}
/// <summary>

View File

@ -257,6 +257,7 @@ CREATE TABLE [dbo].[Exceptions](
[ErrorPage] [varchar](50) NOT NULL,
[UserID] [varchar](50) NOT NULL,
[UserIp] [varchar](15) NOT NULL,
[ExceptionType] [nvarchar](max) NOT NULL,
[Message] [nvarchar](max) NOT NULL,
[StackTrace] [nvarchar](max) NOT NULL,
[LogTime] [datetime] NOT NULL,