diff options
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(); |
