diff --git a/Bootstrap.Admin/Models/HeaderBarModel.cs b/Bootstrap.Admin/Models/HeaderBarModel.cs index 99f582a1..87e478df 100644 --- a/Bootstrap.Admin/Models/HeaderBarModel.cs +++ b/Bootstrap.Admin/Models/HeaderBarModel.cs @@ -17,7 +17,7 @@ namespace Bootstrap.Admin.Models UserID = user.ID; HomeUrl = "~/"; Menus = MenuHelper.RetrieveLinksByUserName(UserName); - Notifications = NotificationHelper.RetrieveNotifications(); + Notifications = NotificationHelper.RetrieveUser(); } public string UserName { get; protected set; } /// @@ -43,6 +43,6 @@ namespace Bootstrap.Admin.Models /// /// /// - public IEnumerable Notifications { get; set; } + public IEnumerable Notifications { get; set; } } } \ No newline at end of file diff --git a/Bootstrap.Admin/Views/Admin/Notifications.cshtml b/Bootstrap.Admin/Views/Admin/Notifications.cshtml index 59c16257..7fd18687 100644 --- a/Bootstrap.Admin/Views/Admin/Notifications.cshtml +++ b/Bootstrap.Admin/Views/Admin/Notifications.cshtml @@ -21,14 +21,14 @@
    - @foreach (var nofi in Model.Notifications) + @foreach (var u in Model.Notifications) {
  • - @nofi.Title + @u.DisplayName
    - @nofi.Content + @u.Description
    @@ -51,9 +51,9 @@
  • - @nofi.Title + @nofi.DisplayName
    - @nofi.Content + @nofi.Description
    @@ -76,9 +76,9 @@
  • - @nofi.Title + @nofi.DisplayName
    - @nofi.Content + @nofi.Description
    diff --git a/Bootstrap.Admin/Views/Shared/Header.cshtml b/Bootstrap.Admin/Views/Shared/Header.cshtml index df230b7b..a13f540c 100644 --- a/Bootstrap.Admin/Views/Shared/Header.cshtml +++ b/Bootstrap.Admin/Views/Shared/Header.cshtml @@ -177,22 +177,11 @@
  • 您有 @Model.Notifications.Count() 条新通知

  • - @foreach (var noti in Model.Notifications.Take(6)) + @foreach (var u in Model.Notifications.Take(6)) {
  • - - @if (noti.Category == "0") - { -
    @noti.Content
    @noti.Period - } - else if (noti.Category == "1") - { -
    @noti.Content
    @noti.Period - } - else - { -
    @noti.Content
    @noti.Period - } +
    +
    @u.DisplayName
    @u.Period
  • } diff --git a/Bootstrap.Admin/Web.config b/Bootstrap.Admin/Web.config index 40a12350..a7ff5fde 100644 --- a/Bootstrap.Admin/Web.config +++ b/Bootstrap.Admin/Web.config @@ -43,6 +43,7 @@ + diff --git a/Bootstrap.DataAccess/NotificationHelper.cs b/Bootstrap.DataAccess/NotificationHelper.cs index 6a7e5dee..be11fad5 100644 --- a/Bootstrap.DataAccess/NotificationHelper.cs +++ b/Bootstrap.DataAccess/NotificationHelper.cs @@ -14,6 +14,29 @@ namespace Bootstrap.DataAccess { internal const string RetrieveNotifyDataKey = "NotificationHelper-RetrieveNotifications"; + /// + /// 查询新注册用户 + /// + /// + public static IEnumerable RetrieveUser() + { + var ret = UserHelper.RetrieveUsersForNotify(); + if (ret != null) + { + ret.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); + }); + return ret; + } + List users = new List(); + return users; + } + /// /// 新用户注册的通知的面板显示 /// diff --git a/Bootstrap.DataAccess/User.cs b/Bootstrap.DataAccess/User.cs index 819331f9..5419a70f 100644 --- a/Bootstrap.DataAccess/User.cs +++ b/Bootstrap.DataAccess/User.cs @@ -43,5 +43,9 @@ namespace Bootstrap.DataAccess /// 获得/设置 用户当前状态 0 表示管理员注册用户 1 表示用户自己注册 2 表示管理员批复 ///
public int UserStatus { get; set; } + /// + /// 获得/设置 通知描述 2分钟内为刚刚 + /// + public string Period { get; set; } } } diff --git a/Bootstrap.DataAccess/UserHelper.cs b/Bootstrap.DataAccess/UserHelper.cs index 43fe3821..2753ddf1 100644 --- a/Bootstrap.DataAccess/UserHelper.cs +++ b/Bootstrap.DataAccess/UserHelper.cs @@ -23,6 +23,7 @@ namespace Bootstrap.DataAccess private const string RetrieveUsersByNameDataKey = "UserHelper-RetrieveUsersByName"; internal const string RetrieveUsersByRoleIDDataKey = "UserHelper-RetrieveUsersByRoleId"; internal const string RetrieveUsersByGroupIDDataKey = "UserHelper-RetrieveUsersByGroupId"; + internal const string RetrieveUsersForNotifyDataKey = "UserHelper-RetrieveUsersForNotify"; /// /// 查询所有用户 /// @@ -95,6 +96,40 @@ namespace Bootstrap.DataAccess return user; }, CacheSection.RetrieveDescByKey(RetrieveUsersByNameDataKey)); } + /// + /// 查询所有的新注册用户 + /// + /// + public static IEnumerable RetrieveUsersForNotify() + { + string sql = "select ID, UserName, DisplayName, RegisterTime, [Description] from Users Where ApprovedTime is null"; + var ret = CacheManager.GetOrAdd(RetrieveUsersForNotifyDataKey, CacheSection.RetrieveIntervalByKey(RetrieveUsersForNotifyDataKey), key => + { + List Users = new List(); + DbCommand cmd = DBAccessManager.SqlDBAccess.CreateCommand(CommandType.Text, sql); + try + { + using (DbDataReader reader = DBAccessManager.SqlDBAccess.ExecuteReader(cmd)) + { + while (reader.Read()) + { + Users.Add(new User() + { + ID = (int)reader[0], + UserName = (string)reader[1], + DisplayName = (string)reader[2], + RegisterTime = (DateTime)reader[3], + Description = (string)reader[4] + }); + } + } + } + catch (Exception ex) { ExceptionManager.Publish(ex); } + return Users; + }, CacheSection.RetrieveDescByKey(RetrieveUsersForNotifyDataKey)); + return ret; + } + /// /// 删除用户 ///