diff options
| author | Michael <[email protected]> | 2017-03-24 15:31:22 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-03-24 15:31:22 -0400 |
| commit | 7c76a963c8e2bc891c38f664c60d9daac31822ee (patch) | |
| tree | c118a8c19a993988a5a11a9c8d97eab3e97bfb52 | |
| parent | eae28fa3d278c91f2b42b8420db2dd5704d5a049 (diff) | |
| download | project-unite-7c76a963c8e2bc891c38f664c60d9daac31822ee.tar.gz project-unite-7c76a963c8e2bc891c38f664c60d9daac31822ee.tar.bz2 project-unite-7c76a963c8e2bc891c38f664c60d9daac31822ee.zip | |
Notification dropdown in navbar is done.
| -rw-r--r-- | Project-Unite/ACL.cs | 30 | ||||
| -rw-r--r-- | Project-Unite/Models/Notification.cs | 5 | ||||
| -rw-r--r-- | Project-Unite/Views/Shared/_LoginPartial.cshtml | 8 |
3 files changed, 41 insertions, 2 deletions
diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs index 77e6f1d..97131b0 100644 --- a/Project-Unite/ACL.cs +++ b/Project-Unite/ACL.cs @@ -8,6 +8,7 @@ using System.Web.Mvc; using System.Diagnostics; using System.Web.Mvc.Html; using System.Data.Entity; +using System.Text; namespace Project_Unite { @@ -32,6 +33,35 @@ namespace Project_Unite return hpr.Raw("<a href=\"/Profiles/ViewProfile/" + user.DisplayName + "\"><span class=\"glyphicon glyphicon-star\"></span> Our newest user, <strong>" + user.DisplayName + "</strong></a>"); } + public static IHtmlString GetLatestNotifications(this HtmlHelper hpr, string userName) + { + var db = new ApplicationDbContext(); + var user = db.Users.FirstOrDefault(x => x.UserName == userName); + if (user == null) + return hpr.Raw(""); + var notesOrdered = user.Notifications.Where(x => x.IsRead == false).OrderByDescending(x => x.Timestamp).ToArray(); + StringBuilder builder = new StringBuilder(); + + for (int i = 0; i < notesOrdered.Length && i < 5; i++) + { + builder.AppendLine("<li><a href=\"" + notesOrdered[i].ActionUrl + "\">"); + //Avatar holder start: + builder.AppendLine("<div style=\"width:128px;height:128px;display:inline-block;\">"); + //Avatar + builder.AppendLine("<img src=\"" + notesOrdered[i].AvatarUrl + "\" width=\"128\" height=\"128\"/>"); + //Avatar holder end: + builder.AppendLine("</div>"); + + //Notification title. + builder.AppendLine("<strong>" + notesOrdered[i].Title + "</strong><br/>"); + //Contents. + builder.AppendLine("<p>" + notesOrdered[i].Description + "</p>"); + + builder.AppendLine("</a></li>"); + } + return hpr.Raw(builder.ToString()); + } + public static IHtmlString Markdown(this HtmlHelper hpr, string md) { return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md))); diff --git a/Project-Unite/Models/Notification.cs b/Project-Unite/Models/Notification.cs index dd13e5b..5870d76 100644 --- a/Project-Unite/Models/Notification.cs +++ b/Project-Unite/Models/Notification.cs @@ -12,6 +12,9 @@ namespace Project_Unite.Models public string Discriminator { get; set; } public DateTime Timestamp { get; set; } public bool IsRead { get; set; } - + public string AvatarUrl { get; set; } + public string Title { get; set; } + public string Description { get; set; } + public string ActionUrl { get; set; } } }
\ No newline at end of file diff --git a/Project-Unite/Views/Shared/_LoginPartial.cshtml b/Project-Unite/Views/Shared/_LoginPartial.cshtml index 7abc0d1..3e20d00 100644 --- a/Project-Unite/Views/Shared/_LoginPartial.cshtml +++ b/Project-Unite/Views/Shared/_LoginPartial.cshtml @@ -7,7 +7,13 @@ <ul class="nav navbar-nav navbar-right" style="margin-right:15px;"> <li>@Html.NewestUser()</li> - <li class="dropdown"><a href="#" data-toggle="dropdown" class="dropdown-toggle"><span class="glyphicon glyphicon-bullhorn"></span> @Html.NotificationCount(User.Identity.GetUserId())</a></li> + <li class="dropdown"><a href="#" data-toggle="dropdown" class="dropdown-toggle"><span class="glyphicon glyphicon-bullhorn"></span> @Html.NotificationCount(User.Identity.GetUserId())</a> + <ul class="dropdown-menu"> + <li class="dropdown-header">Notifications (@Html.NotificationCount(User.Identity.Name) unread)</li> + @Html.GetLatestUnread(User.Identity.Name) + <li>@Html.ActionLink("View all", "Notifications", "Manage")</li> + </ul> + </li> <li class="dropdown"><a href="#" data-toggle="dropdown" class="dropdown-toggle"><span class="glyphicon glyphicon-user"></span> @Html.UserName(User.Identity.GetUserId()) <span class="caret"></span></a> <ul class="dropdown-menu"> <li><a href="@Url.Action("ViewProfile", "Profiles", new { id = ACL.UserNameRaw(User.Identity.GetUserId()) })"><span class="glyphicon glyphicon-user"></span> Profile</a></li> |
