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 static bool AddElement(UploadMusic tmp) { if (!Indexation.IsElementExisting(tmp.MusicPart.Musics.First().Author)) { AddAuthor(tmp); } if (Indexation.IsElementExisting(tmp.MusicPart)) { if (IsElementExisting(tmp.MusicPart.Musics.First())) { return(false); } else { if (AddMusic(tmp)) { return(true); } } } else { string path = AddAlbum(tmp); var music = tmp.MusicPart.Musics.First(); string MusicPath = Path.Combine(path, music.Title + music.Format); System.IO.File.WriteAllBytes(MusicPath, tmp.MusicPart.Musics.First().FileBinary); MusicsInfo.SaveMusicInfo(tmp.MusicPart.Musics.First()); foreach (var a in ServerMusics) { if (a.MID == music.Author.MID) { music.FileBinary = null; music.ServerPath = MusicPath; music.Author = a; Album tmpAl = new Album(a, tmp.MusicPart.Name, path); music.Album = tmpAl; tmpAl.Add(music); a.Albums.Add(tmpAl); return(true); } } } return(false); }
public static bool AddMusic(UploadMusic tmp) { var music = tmp.MusicPart.Musics.First(); string path = Path.Combine(GetElementPath(tmp.MusicPart), music.Title + music.Format); System.IO.File.WriteAllBytes(path, tmp.MusicPart.Musics.First().FileBinary); MusicsInfo.SaveMusicInfo(tmp.MusicPart.Musics.First()); var album = GetAlbum(tmp.MusicPart.MID); if (album != null) { music.FileBinary = null; music.ServerPath = path; music.Author = album.Author; music.Album = album; album.Add(music); return(true); } return(false); }