public async Task <Song> AddSongAsync(string path, string optionalInfo = "LF") { using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) { try { TagLib.File file_TAG = TagLib.File.Create(path); Music_AuthorAndTitleCheck MAaTC = new Music_AuthorAndTitleCheck(Path.GetFileName(path), file_TAG); //int ID_GlobalCounter = this.GetDBSongsCount(cnn) + 1; Song temp = new Song() { //Id = ID_GlobalCounter, Author = MAaTC.Author, Title = MAaTC.Title, //Album Year = file_TAG.Tag.Year, Duration = file_TAG.Properties.Duration.ToString(@"mm\:ss"), LocalUrl = path, UserLogin = _user.Login, OnServer = false, OnDevice = true, OptionalInfo = optionalInfo }; if (!string.IsNullOrEmpty(file_TAG.Tag.Album)) { temp.Album = file_TAG.Tag.Album; } else { temp.Album = "Неизвестный"; } string sql = $"INSERT INTO Songs (Author, Title, Album, Duration, Year," + $"PlayLists, LocalURL, UserLogin, OnServer, OnPC, OptionalInfo)" + $" VALUES(@author, @title, @album, @duration, @year," + $"@playLists, @localURL, @userLogin, @onServer, @onPC, @optionalInfo);"; await cnn.ExecuteAsync(sql, temp); return(temp); } catch (Exception) { return(null); } finally { } } }
public Song AddSong(string path, Guid optionalInfo) { using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString())) { try { var CheckSong = _musicStorage.AllSongs.FirstOrDefault(x => x.LocalUrl == path); if (CheckSong != null) { //if (optionalInfo != "") //{ // if (CheckSong.PlayLists == null) // CheckSong.PlayLists = new List<string>(); // CheckSong.PlayLists.Add(optionalInfo); // this.UpdateSong(CheckSong); // Application.Current.Dispatcher.Invoke(() => // _musicStorage.PlayLists.FirstOrDefault(x => x.Id == optionalInfo).LinkedSongs.AddLast(CheckSong)); //} return(CheckSong); } TagLib.File file_TAG = TagLib.File.Create(path); Music_AuthorAndTitleCheck MAaTC = new Music_AuthorAndTitleCheck(Path.GetFileName(path), file_TAG); //Song temp = new Song() //{ // Id = Guid.NewGuid(), // Author = MAaTC.Author, // Title = MAaTC.Title, // //Album // Year = file_TAG.Tag.Year, // Duration = file_TAG.Properties.Duration.ToString(@"mm\:ss"), // LocalUrl = path, // UserLogin = _user.Login, // OnServer = false, // OnDevice = true, // IsFavorite = false, // OptionalInfo = "" //}; //if (!string.IsNullOrEmpty(file_TAG.Tag.Album)) // temp.Album = file_TAG.Tag.Album; //else // temp.Album = "Неизвестный"; //if(!string.IsNullOrEmpty(optionalInfo)) //{ // switch(optionalInfo) // { // case "": // break; // default: // temp.PlayLists = new List<string>(); // temp.PlayLists.Add(optionalInfo); // break; // } //} string sql = $"INSERT INTO Songs (Id, Author, Title, Album, Duration, Year," + $"PlayLists, LocalURL, UserLogin, OnServer, OnDevice, IsFavorite, OptionalInfo)" + $" VALUES(@Id, @Author, @Title, @Album, @Duration, @Year," + $"@PlayLists, @LocalURL, @UserLogin, @OnServer, @OnDevice, @IsFavorite, @OptionalInfo);"; //cnn.Insert(temp as SongBase); id сбивается, по причине иди ***** //cnn.Execute(sql, temp); //SongIntegrating(temp); return(null); } catch (Exception) { return(null); } finally { } } }