Esempio n. 1
0
        public ActionResult SendRequest(string id)
        {
            FriendRequest FriendRequest = new FriendRequest();

            var userNameId = User.Identity.GetUserId();

            var fromUser = UserRepository.Get(userNameId);

            FriendRequest.From = fromUser;

            var toUser = UserRepository.Get(id.ToString());

            FriendRequest.To = toUser;

            var checklist = AddFriendRepository.GetAll();

            bool FriendRequestExist = false;


            foreach (var item in checklist)
            {
                if (fromUser.Id.Equals(item.To.Id) && toUser.Id.Equals(item.From.Id) || fromUser.Id.Equals(item.From.Id) && toUser.Id.Equals(item.To.Id))
                {
                    FriendRequestExist = true;
                }
            }

            if (FriendRequestExist == false)
            {
                AddFriendRepository.Add(FriendRequest);

                AddFriendRepository.Save();

                return(View("Error"));
            }

            else
            {
                return(View("AlreadyFriends"));
            }
        }
        public ActionResult DeclineFriend(int id)
        {
            var friendRequest = addFriendRepository.Get(Convert.ToInt32(id));
            var friendAccept  = userRepository.Get(User.Identity.GetUserId());

            var Friend = addFriendRepository.GetAll().Single(x => x.From.Id.Equals(friendRequest.From.Id) && x.To.Id.Equals(friendAccept.Id));

            addFriendRepository.Remove(Friend.Id);
            addFriendRepository.Save();

            return(View("Decline"));
        }