public void GetAllFriendPairs_GetAllFriendPairsFromDatabase_FriendPairsList()
        {
            string salt1   = Player.MakeSalt();
            Hash   hash1   = new Hash("password", salt1);
            Player player1 = new Player("thebigtaco", hash1.Result, salt1);

            player1.Save();
            string salt2   = Player.MakeSalt();
            Hash   hash2   = new Hash("password", salt2);
            Player player2 = new Player("duhbigotaku", hash2.Result, salt2);

            player2.Save();
            string salt3   = Player.MakeSalt();
            Hash   hash3   = new Hash("password", salt3);
            Player player3 = new Player("draguni", hash3.Result, salt3);

            player3.Save();

            FriendPair friend1 = new FriendPair(player1.Id, player2.Id);

            friend1.Save();
            FriendPair friend2 = new FriendPair(player1.Id, player3.Id);

            friend2.Save();

            List <FriendPair> result = FriendPair.GetAllFriendPairs();
            List <FriendPair> test   = new List <FriendPair> {
                friend1, friend2
            };

            CollectionAssert.AreEqual(test, result);
        }
        public async Task <IHttpActionResult> Get()
        {
            List <FriendPair> pairs = new List <FriendPair>();

            try
            {
                using (SqlConnection con = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBCS"].ConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("Select FriendMail1, FriendMail2 from Friends Where FriendMail1 = @mail OR FriendMail2 = @mail Union Select SenderMail as FriendMail1, RecipientMail as FriendMail2 from FriendRequests Where RecipientMail = @mail", con);
                    cmd.Parameters.AddWithValue("@mail", User.Identity.Name);

                    con.Open();
                    using (SqlDataReader rdr = await cmd.ExecuteReaderAsync())
                    {
                        while (rdr.Read())
                        {
                            FriendPair p = new FriendPair()
                            {
                                FriendMail1 = rdr["FriendMail1"].ToString(),
                                FriendMail2 = rdr["FriendMail2"].ToString()
                            };

                            pairs.Add(p);
                        }
                    }
                }

                return(Ok(pairs));
            }
            catch (Exception e)
            {
                return(InternalServerError(e));
            }
        }
        public void CheckForFriend_ChecksIfFriendsAlready_Null()
        {
            string salt1   = Player.MakeSalt();
            Hash   hash1   = new Hash("password", salt1);
            Player player1 = new Player("thebigtaco", hash1.Result, salt1);

            player1.Save();
            string salt2   = Player.MakeSalt();
            Hash   hash2   = new Hash("password", salt2);
            Player player2 = new Player("duhbigotaku", hash2.Result, salt2);

            player2.Save();
            string salt3   = Player.MakeSalt();
            Hash   hash3   = new Hash("password", salt3);
            Player player3 = new Player("draguni", hash3.Result, salt3);

            player3.Save();

            FriendPair friend1 = new FriendPair(player1.Id, player2.Id);

            friend1.Save();
            FriendPair friend2 = new FriendPair(player1.Id, player3.Id);

            friend2.Save();

            bool?result = FriendPair.CheckForFriend(player2.Id, player2.Id);

            Assert.AreEqual(null, result);
        }
Example #4
0
        public ActionResult AddFriend(Guid id)
        {
            var        userId     = User.Identity.GetUserId();
            Member     member     = db.Members.FirstOrDefault(m => m.ApplicationUserId == userId);
            FriendList friendList = db.FriendLists.FirstOrDefault(l => l.Id == member.Id);

            if (friendList == null)
            {
                friendList = new FriendList {
                    Member = member
                };
                db.FriendLists.Add(friendList);
                db.SaveChanges();
            }
            if (db.FriendPairs.FirstOrDefault(p => p.ListId == friendList.Id && p.FriendId == id) != null)
            {
                return(RedirectToAction("Details", new { id = id }));
            }
            FriendPair pair = new FriendPair
            {
                Friend = db.Members.Find(id),
                List   = friendList
            };

            db.FriendPairs.Add(pair);
            db.SaveChanges();
            return(RedirectToAction("Details", new { id = id }));
        }
Example #5
0
        public ActionResult UnfollowFriend(int id)
        {
            var sessionId      = Request.Cookies["sessionId"];
            int loggedInPlayer = Session.FindById(sessionId).PlayerId;

            FriendPair.Unfollow(loggedInPlayer, id);
            return(new EmptyResult());
        }
Example #6
0
        public ActionResult AddFriend(int id)
        {
            var        sessionId      = Request.Cookies["sessionId"];
            int        loggedInPlayer = Session.FindById(sessionId).PlayerId;
            FriendPair newFriendPair  = new FriendPair(loggedInPlayer, id);

            newFriendPair.Save();
            return(new EmptyResult());
        }
Example #7
0
 public ProfileModel(int profileId, string sessionId) : base(sessionId)
 {
     Highscore             = GameStats.GetPlayerHighScore(profileId);
     TotalEnemiesDestroyed = GameStats.GetPlayerTotalEnemiesDestroyed(profileId);
     TotalPlayTime         = new TimeSpan(GameStats.GetPlayerTotalTimePlayed(profileId) * 10000).ToString(@"hh\:mm\:ss");
     TotalScore            = GameStats.GetPlayerTotalScore(profileId);
     MostRecentStats       = GameStats.GetPlayerMostRecentStats(profileId);
     Player  = Player.FindById(profileId);
     Friends = Friend.GetFriendList(profileId);
     Follow  = FriendPair.CheckForFriend(base.CurrentSession.PlayerId, profileId);
 }
        public void Equals_Same_True()
        {
            string salt1   = Player.MakeSalt();
            Hash   hash1   = new Hash("password", salt1);
            Player player1 = new Player("thebigtaco", hash1.Result, salt1);

            player1.Save();
            string salt2   = Player.MakeSalt();
            Hash   hash2   = new Hash("password", salt2);
            Player player2 = new Player("duhbigotaku", hash2.Result, salt2);

            player2.Save();

            FriendPair friend1 = new FriendPair(player1.Id, player2.Id);
            FriendPair friend2 = new FriendPair(player1.Id, player2.Id);

            Assert.AreEqual(friend1, friend2);
        }
Example #9
0
        public void GetAllFriendsForPlayer_GetFriendsForASinglePlayer_FriendsList()
        {
            string salt1   = Player.MakeSalt();
            Hash   hash1   = new Hash("password", salt1);
            Player player1 = new Player("thebigtaco", hash1.Result, salt1);

            player1.Save();
            string salt2   = Player.MakeSalt();
            Hash   hash2   = new Hash("password", salt2);
            Player player2 = new Player("duhbigotaku", hash2.Result, salt2);

            player2.Save();
            FriendPair friendpair1 = new FriendPair(player1.Id, player2.Id);

            friendpair1.Save();

            Friend test   = new Friend(player1.Username, player1.Id);
            Friend result = Friend.GetAllFriendsForPlayer(player1.Id)[0];

            Assert.AreEqual(test, result);
        }
        public async Task Accept(FriendInvitation friendInvitation, long editUserId)
        {
            friendInvitation.Accept(editUserId, _friendInvitationPolicy);

            await _friendPairRepository.InsertAsync(FriendPair.Create(friendInvitation.Owner, friendInvitation.Invitee));
        }