Front-end for following/un-following

This commit is contained in:
Michael 2017-03-23 21:50:48 -04:00
parent 8d7350c24a
commit 0b2469ee1c
3 changed files with 47 additions and 0 deletions

View file

@ -28,6 +28,13 @@ namespace Project_Unite
return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md))); 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) public static IHtmlString UserLink(this HtmlHelper hpr, string userId)
{ {
using(var db = new ApplicationDbContext()) using(var db = new ApplicationDbContext())

View file

@ -12,6 +12,13 @@ using Microsoft.AspNet.Identity.EntityFramework;
namespace Project_Unite.Models 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. // 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 public class ApplicationUser : IdentityUser
{ {
@ -98,6 +105,24 @@ namespace Project_Unite.Models
return db.UserPosts.Where(x => x.UserId == this.Id).ToArray(); 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 public class BannedIP
@ -124,6 +149,7 @@ namespace Project_Unite.Models
return new ApplicationDbContext(); return new ApplicationDbContext();
} }
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; }
public DbSet<Like> Likes { get; set; } public DbSet<Like> Likes { get; set; }

View file

@ -14,6 +14,20 @@
</h3> </h3>
</div> </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="row">
<div class="col-xs-4"> <div class="col-xs-4">
<h4>User stats</h4> <h4>User stats</h4>