Exemple #1
0
 public ActionResult AddFriend(string username)
 {
     var service = new Service();
     User user = service.GetUser(User.Identity.Name);
     User friend = service.GetUser(username);
     if (friend == null)
     {
         TempData["message"] = new Message("The username " + username + " could not be found.", MessageType.INFORMATION);
     }
     else if (User.Identity.Name == friend.UserName)
     {
         TempData["message"] = new Message("You can't add yourself to your friend list.", MessageType.INFORMATION);
     }
     else if (service.IsFriendsWith(user.UserID, friend.UserID))
     {
         TempData["message"] = new Message(username + " is already your friend.", MessageType.INFORMATION);
     }
     else if (service.FriendRequestExists(user.UserID, friend.UserID))
     {
         TempData["message"] = new Message(username + " still has a pending friend request", MessageType.INFORMATION);
     }
     else if (service.SendFriendRequest(user.UserID, friend.UserID))
     {
         TempData["message"] = new Message(username + " has received your friend request.", MessageType.SUCCESS);
     }
     else
     {
         TempData["message"] = new Message("Could not process Add Friend request please try again later.", MessageType.ERROR);
     }
     if (Request.IsAjaxRequest())
     {
         return Json(new { message = TempData["message"] as Message }, JsonRequestBehavior.AllowGet);
     }
     return RedirectToAction("Index");
 }