diff options
| author | Michael <[email protected]> | 2017-03-23 19:45:15 -0400 |
|---|---|---|
| committer | Michael <[email protected]> | 2017-03-23 19:45:15 -0400 |
| commit | 8d7350c24ac95eb325ce9c653c4cb7c99fbcdcae (patch) | |
| tree | dd127f0dec9c0c8e9d0f46aa09213feca118956a /Project-Unite/Controllers/ProfilesController.cs | |
| parent | ca0d3dd81ac7107e57a25c0fd8e2b61bb11c5199 (diff) | |
| download | project-unite-8d7350c24ac95eb325ce9c653c4cb7c99fbcdcae.tar.gz project-unite-8d7350c24ac95eb325ce9c653c4cb7c99fbcdcae.tar.bz2 project-unite-8d7350c24ac95eb325ce9c653c4cb7c99fbcdcae.zip | |
User posts can be liked and disliked.
Diffstat (limited to 'Project-Unite/Controllers/ProfilesController.cs')
| -rw-r--r-- | Project-Unite/Controllers/ProfilesController.cs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/Project-Unite/Controllers/ProfilesController.cs b/Project-Unite/Controllers/ProfilesController.cs index a1d4235..5140296 100644 --- a/Project-Unite/Controllers/ProfilesController.cs +++ b/Project-Unite/Controllers/ProfilesController.cs @@ -27,6 +27,80 @@ namespace Project_Unite.Controllers return View(user); } + [Authorize] + public ActionResult DislikePosts(string id) + { + var db = new ApplicationDbContext(); + var topic = db.UserPosts.FirstOrDefault(x => x.Id == id); + var uid = User.Identity.GetUserId(); + if (topic == null) + return new HttpStatusCodeResult(404); + if (topic.UserId == User.Identity.GetUserId()) + return RedirectToAction("ViewProfile", new { id = ACL.UserNameRaw(uid) }); + var like = db.Likes.Where(x => x.Topic == topic.Id).FirstOrDefault(x => x.User == uid); + if (like != null) + { + if (like.IsDislike == false) + { + like.IsDislike = true; + } + else + { + db.Likes.Remove(like); + } + } + else + { + like = new Models.Like(); + like.Id = Guid.NewGuid().ToString(); + like.User = User.Identity.GetUserId(); + like.Topic = topic.Id; + like.LikedAt = DateTime.Now; + like.IsDislike = true; + db.Likes.Add(like); + } + db.SaveChanges(); + return RedirectToAction("ViewProfile", new { id = ACL.UserNameRaw(uid) }); + + } + + [Authorize] + public ActionResult LikePost(string id) + { + var db = new ApplicationDbContext(); + var topic = db.UserPosts.FirstOrDefault(x => x.Id == id); + var uid = User.Identity.GetUserId(); + if (topic == null) + return new HttpStatusCodeResult(404); + if (topic.UserId == User.Identity.GetUserId()) + return RedirectToAction("ViewProfile", new { id = ACL.UserNameRaw(uid) }); + var like = db.Likes.Where(x => x.Topic == topic.Id).FirstOrDefault(x => x.User == uid); + if (like != null) + { + if (like.IsDislike == true) + { + like.IsDislike = false; + } + else + { + db.Likes.Remove(like); + } + } + else + { + like = new Models.Like(); + like.Id = Guid.NewGuid().ToString(); + like.User = User.Identity.GetUserId(); + like.Topic = topic.Id; + like.LikedAt = DateTime.Now; + like.IsDislike = false; + db.Likes.Add(like); + } + db.SaveChanges(); + return RedirectToAction("ViewProfile", new { id = ACL.UserNameRaw(uid) }); + } + + public ActionResult PostContent(UserPost model) { var db = new ApplicationDbContext(); |
