mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-23 01:32:16 +00:00
Notification dropdown in navbar is done.
This commit is contained in:
parent
eae28fa3d2
commit
7c76a963c8
3 changed files with 41 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Web.Mvc.Html;
|
using System.Web.Mvc.Html;
|
||||||
using System.Data.Entity;
|
using System.Data.Entity;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
namespace Project_Unite
|
namespace Project_Unite
|
||||||
{
|
{
|
||||||
|
@ -32,6 +33,35 @@ public static IHtmlString NewestUser(this HtmlHelper hpr)
|
||||||
return hpr.Raw("<a href=\"/Profiles/ViewProfile/" + user.DisplayName + "\"><span class=\"glyphicon glyphicon-star\"></span> Our newest user, <strong>" + user.DisplayName + "</strong></a>");
|
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)
|
public static IHtmlString Markdown(this HtmlHelper hpr, string md)
|
||||||
{
|
{
|
||||||
return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md)));
|
return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md)));
|
||||||
|
|
|
@ -12,6 +12,9 @@ public class Notification
|
||||||
public string Discriminator { get; set; }
|
public string Discriminator { get; set; }
|
||||||
public DateTime Timestamp { get; set; }
|
public DateTime Timestamp { get; set; }
|
||||||
public bool IsRead { 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; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,7 +7,13 @@
|
||||||
|
|
||||||
<ul class="nav navbar-nav navbar-right" style="margin-right:15px;">
|
<ul class="nav navbar-nav navbar-right" style="margin-right:15px;">
|
||||||
<li>@Html.NewestUser()</li>
|
<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>
|
<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">
|
<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>
|
<li><a href="@Url.Action("ViewProfile", "Profiles", new { id = ACL.UserNameRaw(User.Identity.GetUserId()) })"><span class="glyphicon glyphicon-user"></span> Profile</a></li>
|
||||||
|
|
Loading…
Reference in a new issue