summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-03-23 21:50:48 -0400
committerMichael <[email protected]>2017-03-23 21:50:48 -0400
commit0b2469ee1c836c0022f1d10d24dbd0055011c43a (patch)
tree1fcfe2eaa8b87e18436da602f1faeb6487467062
parent8d7350c24ac95eb325ce9c653c4cb7c99fbcdcae (diff)
downloadproject-unite-0b2469ee1c836c0022f1d10d24dbd0055011c43a.tar.gz
project-unite-0b2469ee1c836c0022f1d10d24dbd0055011c43a.tar.bz2
project-unite-0b2469ee1c836c0022f1d10d24dbd0055011c43a.zip
Front-end for following/un-following
-rw-r--r--Project-Unite/ACL.cs7
-rw-r--r--Project-Unite/Models/IdentityModels.cs26
-rw-r--r--Project-Unite/Views/Profiles/ViewProfile.cshtml14
3 files changed, 47 insertions, 0 deletions
diff --git a/Project-Unite/ACL.cs b/Project-Unite/ACL.cs
index dc12487..73636c7 100644
--- a/Project-Unite/ACL.cs
+++ b/Project-Unite/ACL.cs
@@ -28,6 +28,13 @@ namespace Project_Unite
return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md)));
}
+ public static bool IsFollowed(string you, string fId)
+ {
+ var db = new ApplicationDbContext();
+ var uid = db.Users.FirstOrDefault(x => x.UserName == you).Id;
+ return db.Follows.FirstOrDefault(x => x.Follower == uid && x.Followed == fId) != null;
+ }
+
public static IHtmlString UserLink(this HtmlHelper hpr, string userId)
{
using(var db = new ApplicationDbContext())
diff --git a/Project-Unite/Models/IdentityModels.cs b/Project-Unite/Models/IdentityModels.cs
index 8d368ed..83ea777 100644
--- a/Project-Unite/Models/IdentityModels.cs
+++ b/Project-Unite/Models/IdentityModels.cs
@@ -12,6 +12,13 @@ using Microsoft.AspNet.Identity.EntityFramework;
namespace Project_Unite.Models
{
+ public class UserFollow
+ {
+ public string Id { get; set; }
+ public string Follower { get; set; }
+ public string Followed { get; set; }
+ }
+
// You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
public class ApplicationUser : IdentityUser
{
@@ -98,6 +105,24 @@ namespace Project_Unite.Models
return db.UserPosts.Where(x => x.UserId == this.Id).ToArray();
}
}
+
+ public UserFollow[] Followed
+ {
+ get
+ {
+ var db = new ApplicationDbContext();
+ return db.Follows.Where(x => x.Follower == this.Id).ToArray();
+ }
+ }
+
+ public UserFollow[] Followers
+ {
+ get
+ {
+ var db = new ApplicationDbContext();
+ return db.Follows.Where(x => x.Followed == this.Id).ToArray();
+ }
+ }
}
public class BannedIP
@@ -124,6 +149,7 @@ namespace Project_Unite.Models
return new ApplicationDbContext();
}
+ public DbSet<UserFollow> Follows { get; set; }
public DbSet<UserPost> UserPosts { get; set; }
public DbSet<ForumPostEdit> ForumPostEdits { get; set; }
public DbSet<Like> Likes { get; set; }
diff --git a/Project-Unite/Views/Profiles/ViewProfile.cshtml b/Project-Unite/Views/Profiles/ViewProfile.cshtml
index bee2ed9..b5ed038 100644
--- a/Project-Unite/Views/Profiles/ViewProfile.cshtml
+++ b/Project-Unite/Views/Profiles/ViewProfile.cshtml
@@ -14,6 +14,20 @@
</h3>
</div>
+<ul class="nav nav-pills">
+ @if (Model.UserName != User.Identity.Name)
+ {
+ if (ACL.IsFollowed(User.Identity.Name, Model.Id))
+ {
+ <li><a href="@Url.Action("UnfollowUser", "Profiles", new { id = Model.Id })"><span class="glyphicon glyphicon-eye-close"></span> Unfollow</a></li>
+ }
+ else
+ {
+ <li><a href="@Url.Action("FollowUser", "Profiles", new { id = Model.Id })"><span class="glyphicon glyphicon-eye-open"></span> Follow</a></li>
+ }
+ }
+</ul>
+
<div class="row">
<div class="col-xs-4">
<h4>User stats</h4>