public ActionResult AcceptFriendRequest(int requesterId) { var service = new Service(); User user = service.GetUser(User.Identity.Name); User friend = service.GetUser(requesterId); if (service.IsFriendsWith(user.UserID, requesterId)) { TempData["message"] = new Message(friend.DisplayName + " is already your friend", MessageType.INFORMATION); } else if (service.AnswerFriendRequest(friend.UserID, user.UserID, true)) { TempData["message"] = new Message("You are now friends with " + friend.DisplayName, MessageType.SUCCESS); } else { TempData["message"] = new Message("The friend request you are trying to access no longer exists.", MessageType.INFORMATION); } if (Request.IsAjaxRequest()) { return Json(new { message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet); } return RedirectToAction("Index"); }
public ActionResult DeclineFriendRequest(int requesterId) { var service = new Service(); User user = service.GetUser(User.Identity.Name); User friend = service.GetUser(requesterId); if (service.AnswerFriendRequest(requesterId, user.UserID, false)) { TempData["message"] = new Message("You declined a friend request from " + friend.DisplayName, MessageType.SUCCESS); } else { TempData["message"] = new Message("Could not find that specific friend request, maybe the other user withdrew it.", MessageType.ERROR); } if (Request.IsAjaxRequest()) { return Json(new { friend = friend, message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet); } return RedirectToAction("Index"); }