mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-02-02 13:07:34 +00:00
Add notification button and db column
This commit is contained in:
parent
f7767a660c
commit
016128611c
5 changed files with 46 additions and 0 deletions
|
@ -13,6 +13,15 @@ namespace Project_Unite
|
||||||
{
|
{
|
||||||
public static class ACL
|
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)
|
public static IHtmlString NewestUser(this HtmlHelper hpr)
|
||||||
{
|
{
|
||||||
var db = new ApplicationDbContext();
|
var db = new ApplicationDbContext();
|
||||||
|
|
|
@ -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
|
public UserFollow[] Followed
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -149,6 +166,7 @@ namespace Project_Unite.Models
|
||||||
return new ApplicationDbContext();
|
return new ApplicationDbContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DbSet<Notification> Notifications { get; set; }
|
||||||
public DbSet<UserFollow> Follows { get; set; }
|
public DbSet<UserFollow> Follows { get; set; }
|
||||||
public DbSet<UserPost> UserPosts { get; set; }
|
public DbSet<UserPost> UserPosts { get; set; }
|
||||||
public DbSet<ForumPostEdit> ForumPostEdits { get; set; }
|
public DbSet<ForumPostEdit> ForumPostEdits { get; set; }
|
||||||
|
|
17
Project-Unite/Models/Notification.cs
Normal file
17
Project-Unite/Models/Notification.cs
Normal file
|
@ -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; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -409,6 +409,7 @@
|
||||||
<Compile Include="Models\HomeViewModel.cs" />
|
<Compile Include="Models\HomeViewModel.cs" />
|
||||||
<Compile Include="Models\IdentityModels.cs" />
|
<Compile Include="Models\IdentityModels.cs" />
|
||||||
<Compile Include="Models\ManageViewModels.cs" />
|
<Compile Include="Models\ManageViewModels.cs" />
|
||||||
|
<Compile Include="Models\Notification.cs" />
|
||||||
<Compile Include="Models\Role.cs" />
|
<Compile Include="Models\Role.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Startup.cs" />
|
<Compile Include="Startup.cs" />
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
<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-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>
|
<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…
Add table
Reference in a new issue