summaryrefslogtreecommitdiff
path: root/Project-Unite/Controllers/ProfilesController.cs
diff options
context:
space:
mode:
authorMichael <[email protected]>2017-03-24 12:25:20 -0400
committerMichael <[email protected]>2017-03-24 12:25:20 -0400
commitf7767a660c1ab2f5e98d7bf8ad0a7bc9eb801ddf (patch)
tree528ae6cf820b69d95f8fa794f2632e5d92bf925e /Project-Unite/Controllers/ProfilesController.cs
parent6418b2341e6fa1ff6f1e8e39c15e7ba0cdd375b1 (diff)
downloadproject-unite-f7767a660c1ab2f5e98d7bf8ad0a7bc9eb801ddf.tar.gz
project-unite-f7767a660c1ab2f5e98d7bf8ad0a7bc9eb801ddf.tar.bz2
project-unite-f7767a660c1ab2f5e98d7bf8ad0a7bc9eb801ddf.zip
You can now follow and unfollow users.
Diffstat (limited to 'Project-Unite/Controllers/ProfilesController.cs')
-rw-r--r--Project-Unite/Controllers/ProfilesController.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/ProfilesController.cs b/Project-Unite/Controllers/ProfilesController.cs
index 2b6ee53..4e5e436 100644
--- a/Project-Unite/Controllers/ProfilesController.cs
+++ b/Project-Unite/Controllers/ProfilesController.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
+using System.Net;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;
@@ -27,6 +28,45 @@ namespace Project_Unite.Controllers
return View(user);
}
+ public ActionResult UnfollowUser(string id)
+ {
+ var db = new ApplicationDbContext();
+ if (db.Users.FirstOrDefault(x => x.Id == id) == null)
+ return new HttpStatusCodeResult(404);
+ if (!ACL.IsFollowed(User.Identity.Name, id))
+ return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
+ var uid = User.Identity.GetUserId();
+ var userToFollow = db.Users.FirstOrDefault(x => x.Id == id);
+ var follow = db.Follows.FirstOrDefault(x=>x.Followed==userToFollow.Id&&x.Follower==uid);
+ if(follow != null)
+ db.Follows.Remove(follow);
+ db.SaveChanges();
+ return RedirectToAction("ViewProfile", new { id = userToFollow.DisplayName });
+
+
+ }
+
+
+ public ActionResult FollowUser(string id)
+ {
+ var db = new ApplicationDbContext();
+ if (db.Users.FirstOrDefault(x => x.Id == id) == null)
+ return new HttpStatusCodeResult(404);
+ if (ACL.IsFollowed(User.Identity.Name, id))
+ return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
+ var uid = User.Identity.GetUserId();
+ var userToFollow = db.Users.FirstOrDefault(x => x.Id == id);
+ var follow = new UserFollow();
+ follow.Id = Guid.NewGuid().ToString();
+ follow.Followed = id;
+ follow.Follower = uid;
+ db.Follows.Add(follow);
+ db.SaveChanges();
+ return RedirectToAction("ViewProfile", new { id = userToFollow.DisplayName });
+
+
+ }
+
[Authorize]
public ActionResult DislikePost(string id)
{