重构站内消息代码
This commit is contained in:
parent
e81b21fd16
commit
b870d525fc
|
@ -21,7 +21,9 @@ namespace Bootstrap.Admin.Models
|
|||
var notis = NotificationHelper.RetrieveNotifications();
|
||||
NotifiCount = notis.Count();
|
||||
Notifications = notis.Take(6);
|
||||
Messages = MessageHelper.RetrieveMessagesHeader(HttpContext.Current.User.Identity.Name);
|
||||
var msgs = MessageHelper.RetrieveMessagesHeader(UserName);
|
||||
MessageCount = msgs.Count();
|
||||
Messages = msgs.Take(6);
|
||||
}
|
||||
public string UserName { get; protected set; }
|
||||
/// <summary>
|
||||
|
@ -53,9 +55,12 @@ namespace Bootstrap.Admin.Models
|
|||
/// </summary>
|
||||
public int NotifiCount { get; set; }
|
||||
/// <summary>
|
||||
/// 或者/设置消息列表
|
||||
/// 获得/设置 消息列表
|
||||
/// </summary>
|
||||
public IEnumerable<Message> Messages { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获得/设置 消息数量
|
||||
/// </summary>
|
||||
public int MessageCount { get; set; }
|
||||
}
|
||||
}
|
|
@ -108,22 +108,22 @@
|
|||
</li>
|
||||
<!-- settings end -->
|
||||
<!-- message dropdown start-->
|
||||
@if (Model.Messages.Count() > 0)
|
||||
@if (Model.MessageCount > 0)
|
||||
{
|
||||
<li id="header_inbox_bar" class="dropdown">
|
||||
<li class="dropdown">
|
||||
<a data-toggle="dropdown" class="dropdown-toggle" href="#">
|
||||
<i class="fa fa-envelope-o"></i>
|
||||
<span class="badge bg-important">@Model.Messages.Count()</span>
|
||||
<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.Messages.Count() 个未读的消息</p>
|
||||
<p>您有 @Model.MessageCount 个未读的消息</p>
|
||||
</li>
|
||||
@foreach(var mess in Model.Messages.Take(6))
|
||||
@foreach (var mess in Model.Messages)
|
||||
{
|
||||
<li>
|
||||
<a href="~/Admin/Messages/@mess.ID">
|
||||
<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>
|
||||
|
@ -143,7 +143,7 @@
|
|||
<!-- notification dropdown start-->
|
||||
@if (Model.NotifiCount > 0)
|
||||
{
|
||||
<li id="header_notification_bar" class="dropdown">
|
||||
<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>
|
||||
|
|
|
@ -10,8 +10,9 @@ using System.Linq;
|
|||
|
||||
namespace Bootstrap.DataAccess
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class MessageHelper
|
||||
{
|
||||
internal const string RetrieveMessageFromDataKey = "MessageHelper-RetrieveMessagesFromOthers";
|
||||
|
@ -54,10 +55,8 @@ namespace Bootstrap.DataAccess
|
|||
return messages;
|
||||
|
||||
}, CacheSection.RetrieveDescByKey(RetrieveMessageFromDataKey));
|
||||
|
||||
return messageRet.OrderByDescending(n => n.SendTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自己获取发送给其他人的消息列表
|
||||
/// </summary>
|
||||
|
@ -95,10 +94,8 @@ namespace Bootstrap.DataAccess
|
|||
return messages;
|
||||
|
||||
}, CacheSection.RetrieveDescByKey(RetrieveMessageToDataKey));
|
||||
|
||||
return messageRet.OrderByDescending(n => n.SendTime);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取Header处显示的消息列表
|
||||
/// </summary>
|
||||
|
@ -106,9 +103,7 @@ namespace Bootstrap.DataAccess
|
|||
/// <returns></returns>
|
||||
public static IEnumerable<Message> RetrieveMessagesHeader(string userName)
|
||||
{
|
||||
|
||||
var messageRet = RetrieveMessagesFromOthers(userName);
|
||||
|
||||
messageRet.AsParallel().ForAll(n =>
|
||||
{
|
||||
var ts = DateTime.Now - n.SendTime;
|
||||
|
@ -119,6 +114,5 @@ namespace Bootstrap.DataAccess
|
|||
});
|
||||
return messageRet;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -324,8 +324,8 @@ CREATE TABLE [dbo].[Messages](
|
|||
[ID] [int] IDENTITY(1,1) NOT NULL,
|
||||
[Title] [nvarchar](50) NOT NULL,
|
||||
[Content] [nvarchar](500) NOT NULL,
|
||||
[From] [nvarchar](50) NOT NULL,
|
||||
[To] [nvarchar](50) NOT NULL,
|
||||
[From] [varchar](50) NOT NULL,
|
||||
[To] [varchar](50) NOT NULL,
|
||||
[SendTime] [datetime] NOT NULL,
|
||||
[Status] [nvarchar](50) NOT NULL,
|
||||
CONSTRAINT [PK_Messages] PRIMARY KEY CLUSTERED
|
||||
|
|
Loading…
Reference in New Issue