summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-03-24 12:49:56 -0400
committerMichael <[email protected]>2017-03-24 12:49:56 -0400
commit016128611cf66501e811dca74f43a35d5385679c (patch)
tree7349c14acbbb4e4aa38677fcff03d2ae4345081d
parentf7767a660c1ab2f5e98d7bf8ad0a7bc9eb801ddf (diff)
downloadproject-unite-016128611cf66501e811dca74f43a35d5385679c.tar.gz
project-unite-016128611cf66501e811dca74f43a35d5385679c.tar.bz2
project-unite-016128611cf66501e811dca74f43a35d5385679c.zip
Add notification button and db column
-rw-r--r--Project-Unite/ACL.cs9
-rw-r--r--Project-Unite/Models/IdentityModels.cs18
-rw-r--r--Project-Unite/Models/Notification.cs17
-rw-r--r--Project-Unite/Project-Unite.csproj1
-rw-r--r--Project-Unite/Views/Shared/_LoginPartial.cshtml1
5 files changed, 46 insertions, 0 deletions
diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs
index 73636c7..77e6f1d 100644
--- a/Project-Unite/ACL.cs
+++ b/Project-Unite/ACL.cs
@@ -13,6 +13,15 @@ namespace Project_Unite
{
public static class ACL
{
+ public static IHtmlString NotificationCount(this HtmlHelper hpr, string uid)
+ {
+ var db = new ApplicationDbContext();
+ var usr = db.Users.FirstOrDefault(x => x.Id == uid);
+ if (usr == null)
+ return hpr.Raw("N/A");
+ return hpr.Raw(usr.UnreadNotifications.ToString());
+ }
+
public static IHtmlString NewestUser(this HtmlHelper hpr)
{
var db = new ApplicationDbContext();
diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs
index 83ea777..a3dde10 100644
--- a/Project-Unite/Models/IdentityModels.cs
+++ b/Project-Unite/Models/IdentityModels.cs
@@ -106,6 +106,23 @@ namespace Project_Unite.Models
}
}
+ public Notification[] Notifications
+ {
+ get
+ {
+ var db = new ApplicationDbContext();
+ return db.Notifications.Where(x => x.UserId == this.Id).ToArray();
+ }
+ }
+
+ public int UnreadNotifications
+ {
+ get
+ {
+ return Notifications.Where(x => x.IsRead == false).Count();
+ }
+ }
+
public UserFollow[] Followed
{
get
@@ -149,6 +166,7 @@ namespace Project_Unite.Models
return new ApplicationDbContext();
}
+ public DbSet<Notification> Notifications { get; set; }
public DbSet<UserFollow> Follows { get; set; }
public DbSet<UserPost> UserPosts { get; set; }
public DbSet<ForumPostEdit> ForumPostEdits { get; set; }
diff --git a/Project-Unite/Models/Notification.cs b/Project-Unite/Models/Notification.cs
new file mode 100644
index 0000000..dd13e5b
--- /dev/null
+++ b/Project-Unite/Models/Notification.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Web;
+
+namespace Project_Unite.Models
+{
+ public class Notification
+ {
+ public string Id { get; set; }
+ public string UserId { get; set; }
+ public string Discriminator { get; set; }
+ public DateTime Timestamp { get; set; }
+ public bool IsRead { get; set; }
+
+ }
+} \ No newline at end of file
diff --git a/Project-Unite/Project-Unite.csproj b/Project-Unite/Project-Unite.csproj
index 5284ef2..f54b154 100644
--- a/Project-Unite/Project-Unite.csproj
+++ b/Project-Unite/Project-Unite.csproj
@@ -409,6 +409,7 @@
<Compile Include="Models\HomeViewModel.cs" />
<Compile Include="Models\IdentityModels.cs" />
<Compile Include="Models\ManageViewModels.cs" />
+ <Compile Include="Models\Notification.cs" />
<Compile Include="Models\Role.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Startup.cs" />
diff --git a/Project-Unite/Views/Shared/_LoginPartial.cshtml b/Project-Unite/Views/Shared/_LoginPartial.cshtml
index 7c49f01..e5c4b34 100644
--- a/Project-Unite/Views/Shared/_LoginPartial.cshtml
+++ b/Project-Unite/Views/Shared/_LoginPartial.cshtml
@@ -7,6 +7,7 @@
<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-bell"></span> @Html.NotificationCount(User.Identity.GetUserId())</a></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>