Example #1
0
        public static void Handle(Rate temp, Socket socket)
        {
            bool VoteExist = UsersInfos.VoteExist(temp.MusicRatedMID, Program.MyServer.Clients[socket]);

            UsersInfos.AddVoteMusic(temp.MusicRatedMID, Program.MyServer.Clients[socket]);

            if (temp.Type == ElementType.Music)
            {
                var m = Indexation.GetMusicByID(temp.MusicRatedMID);
                if (m != null)
                {
                    if (VoteExist)
                    {
                        m.Rating--;
                    }
                    else
                    {
                        m.Rating++;

                        Program.MyServer.Clients.TryGetValue(socket, out string uid);
                        Program.MyServer.SendObject(new RequestAnswer(UsersInfos.GetLikedMusics(uid)), socket);
                    }
                    Program.MyServer.SendObject(new RateReport(true, temp.MusicRatedMID, m.Rating), socket);
                    MusicsInfo.SaveMusicInfo(m);
                }
            }
            else
            {
                UsersInfos.RatePlaylist(temp.MusicRatedMID, !VoteExist);
                Program.MyServer.SendObject(new RateReport(true, temp.MusicRatedMID, UsersInfos.GetPlaylist(temp.MusicRatedMID).Rating), socket);
            }
        }
        public void RatePlaylistTest()
        {
            //2e1047e01b9f0d927651f33ec8ddce63
            Authentification.AuthentificationService a = new Authentification.AuthentificationService();
            a.SetupAuth();
            User ur = new User(new Utility.Network.Users.CryptedCredentials("User1", "abc"));

            a.SignupUser(ur);

            var      m  = new Music("Music1", new Author("Albert", "path2"), new Album(new Author("Albert", "path2"), "AlbertAlum"), "path", 0);
            Playlist pl = new Playlist(ur, "Playlist1", new List <Music>()
            {
                m
            }, false)
            {
                Rating = 1
            };

            UsersInfos.SaveUserPlaylist("abc", pl);

            UsersInfos.RatePlaylist(pl.MID, false);
            Assert.AreEqual("2e1047e01b9f0d927651f33ec8ddce63", Function.GetMD5(@"users.xml"));
            UsersInfos.RatePlaylist(pl.MID, true);
            Assert.AreEqual("76fdfae945157b5ec9732d9416c080c4", Function.GetMD5(@"users.xml"));
        }