Song's id no longer changed when updating the song #48
This commit is contained in:
@@ -836,14 +836,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
info = "Change to the song's album";
|
info = "Change to the song's album";
|
||||||
_logger.Info(info);
|
_logger.Info(info);
|
||||||
|
|
||||||
if (albumRecord.SongCount > 1)
|
if (albumRecord.SongCount <= 1)
|
||||||
{
|
|
||||||
_logger.Info("Decrementing existing album's song count");
|
|
||||||
|
|
||||||
//albumRecord.SongCount -= 1;
|
|
||||||
albumStore.UpdateAlbum(albumRecord);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_logger.Info("Deleting existing album record that no longer has any songs");
|
_logger.Info("Deleting existing album record that no longer has any songs");
|
||||||
|
|
||||||
@@ -857,8 +850,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
var newAlbumRecord = new Album
|
var newAlbumRecord = new Album
|
||||||
{
|
{
|
||||||
Title = newAlbumTitle,
|
Title = newAlbumTitle,
|
||||||
AlbumArtist = newAlbumArtist,
|
AlbumArtist = newAlbumArtist
|
||||||
SongCount = 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
albumStore.SaveAlbum(newAlbumRecord);
|
albumStore.SaveAlbum(newAlbumRecord);
|
||||||
@@ -869,7 +861,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
var existingAlbumRecord = albumStore.GetAlbum(newSongRecord);
|
var existingAlbumRecord = albumStore.GetAlbum(newSongRecord);
|
||||||
existingAlbumRecord.AlbumArtist = newAlbumArtist;
|
existingAlbumRecord.AlbumArtist = newAlbumArtist;
|
||||||
//existingAlbumRecord.SongCount += 1;
|
|
||||||
|
|
||||||
albumStore.UpdateAlbum(existingAlbumRecord);
|
albumStore.UpdateAlbum(existingAlbumRecord);
|
||||||
}
|
}
|
||||||
@@ -890,14 +881,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
_logger.Info("Change to the song's record found");
|
_logger.Info("Change to the song's record found");
|
||||||
|
|
||||||
if (oldArtistRecord.SongCount > 1)
|
if (oldArtistRecord.SongCount <= 1)
|
||||||
{
|
|
||||||
_logger.Info("Decrementing existing artist's song count");
|
|
||||||
|
|
||||||
//oldArtistRecord.SongCount -= 1;
|
|
||||||
artistStore.UpdateArtist(oldArtistRecord);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_logger.Info("Deleting artist record that no longer has any songs");
|
_logger.Info("Deleting artist record that no longer has any songs");
|
||||||
|
|
||||||
@@ -910,8 +894,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
var newArtistRecord = new Artist
|
var newArtistRecord = new Artist
|
||||||
{
|
{
|
||||||
Name = newArtistName,
|
Name = newArtistName
|
||||||
SongCount = 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
artistStore.SaveArtist(newArtistRecord);
|
artistStore.SaveArtist(newArtistRecord);
|
||||||
@@ -921,7 +904,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
_logger.Info("Updating existing artist record");
|
_logger.Info("Updating existing artist record");
|
||||||
|
|
||||||
var existingArtistRecord = artistStore.GetArtist(newSongRecord);
|
var existingArtistRecord = artistStore.GetArtist(newSongRecord);
|
||||||
//existingArtistRecord.SongCount += 1;
|
|
||||||
|
|
||||||
artistStore.UpdateArtist(existingArtistRecord);
|
artistStore.UpdateArtist(existingArtistRecord);
|
||||||
}
|
}
|
||||||
@@ -942,14 +924,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
_logger.Info("Change to the song's genre found");
|
_logger.Info("Change to the song's genre found");
|
||||||
|
|
||||||
if (oldGenreRecord.SongCount > 1)
|
if (oldGenreRecord.SongCount <= 1)
|
||||||
{
|
|
||||||
_logger.Info("Decrementing exisiting genre song count");
|
|
||||||
|
|
||||||
oldGenreRecord.SongCount -= 1;
|
|
||||||
genreStore.UpdateGenre(oldGenreRecord);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_logger.Info("Deleting genre record");
|
_logger.Info("Deleting genre record");
|
||||||
|
|
||||||
@@ -962,8 +937,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
var newGenreRecord = new Genre
|
var newGenreRecord = new Genre
|
||||||
{
|
{
|
||||||
GenreName = newGenreName,
|
GenreName = newGenreName
|
||||||
SongCount = 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
genreStore.SaveGenre(newGenreRecord);
|
genreStore.SaveGenre(newGenreRecord);
|
||||||
@@ -973,7 +947,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
_logger.Info("Updating existing genre record");
|
_logger.Info("Updating existing genre record");
|
||||||
|
|
||||||
var existingGenreRecord = genreStore.GetGenre(newSongRecord);
|
var existingGenreRecord = genreStore.GetGenre(newSongRecord);
|
||||||
//existingGenreRecord.SongCount += 1;
|
|
||||||
|
|
||||||
genreStore.UpdateGenre(existingGenreRecord);
|
genreStore.UpdateGenre(existingGenreRecord);
|
||||||
}
|
}
|
||||||
@@ -995,14 +968,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
_logger.Info("Change to the song's year found");
|
_logger.Info("Change to the song's year found");
|
||||||
|
|
||||||
if (oldYearRecord.SongCount > 1)
|
if (oldYearRecord.SongCount <= 1)
|
||||||
{
|
|
||||||
_logger.Info("Decrementing song count of year record");
|
|
||||||
|
|
||||||
oldYearRecord.SongCount -= 1;
|
|
||||||
yearStore.UpdateYear(oldYearRecord);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
_logger.Info("Deleting year record");
|
_logger.Info("Deleting year record");
|
||||||
|
|
||||||
@@ -1015,8 +981,7 @@ namespace Icarus.Controllers.Managers
|
|||||||
|
|
||||||
var newYearRecord = new Year
|
var newYearRecord = new Year
|
||||||
{
|
{
|
||||||
YearValue = newYearValue.Value,
|
YearValue = newYearValue.Value
|
||||||
SongCount = 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
yearStore.SaveYear(newYearRecord);
|
yearStore.SaveYear(newYearRecord);
|
||||||
@@ -1026,7 +991,6 @@ namespace Icarus.Controllers.Managers
|
|||||||
_logger.Info("Updating existing year record");
|
_logger.Info("Updating existing year record");
|
||||||
|
|
||||||
var existingYearRecord = yearStore.GetSongYear(newSongRecord);
|
var existingYearRecord = yearStore.GetSongYear(newSongRecord);
|
||||||
//existingYearRecord.SongCount += 1;
|
|
||||||
|
|
||||||
yearStore.UpdateYear(existingYearRecord);
|
yearStore.UpdateYear(existingYearRecord);
|
||||||
}
|
}
|
||||||
@@ -1079,6 +1043,8 @@ namespace Icarus.Controllers.Managers
|
|||||||
if (!string.IsNullOrEmpty(newSongRecord.Genre))
|
if (!string.IsNullOrEmpty(newSongRecord.Genre))
|
||||||
{
|
{
|
||||||
updatedSongRecord.Genre = newSongRecord.Genre;
|
updatedSongRecord.Genre = newSongRecord.Genre;
|
||||||
|
Console.WriteLine("Genre changed");
|
||||||
|
Console.WriteLine($"{updatedSongRecord.Genre} {newSongRecord.Genre}");
|
||||||
}
|
}
|
||||||
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
if (newSongRecord.Year != null || newSongRecord.Year > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ namespace Icarus.Controllers
|
|||||||
.RequestServices
|
.RequestServices
|
||||||
.GetService(typeof(MusicStoreContext)) as MusicStoreContext;
|
.GetService(typeof(MusicStoreContext)) as MusicStoreContext;
|
||||||
|
|
||||||
Song song = context.GetSong(id);
|
Song song = new Song { Id = id };
|
||||||
|
song = context.GetSong(song);
|
||||||
|
|
||||||
Console.WriteLine("Here");
|
Console.WriteLine("Here");
|
||||||
|
|
||||||
|
|||||||
@@ -126,7 +126,9 @@ namespace Icarus.Controllers
|
|||||||
.RequestServices
|
.RequestServices
|
||||||
.GetService(typeof(YearStoreContext)) as YearStoreContext;
|
.GetService(typeof(YearStoreContext)) as YearStoreContext;
|
||||||
|
|
||||||
var songMetaData = context.GetSong(id);
|
var songMetaData = new Song{ Id = id };
|
||||||
|
Console.WriteLine($"Id {songMetaData.Id}");
|
||||||
|
songMetaData = context.GetSong(songMetaData);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(songMetaData.Title))
|
if (string.IsNullOrEmpty(songMetaData.Title))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ namespace Icarus.Models.Context
|
|||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
|
|
||||||
var query = "DELETE FROM Song WHERE Id=@Id";
|
var query = "Delete FROM Song WHERE Id=@Id";
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
@@ -170,6 +170,7 @@ namespace Icarus.Models.Context
|
|||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
var query = "SELECT * FROM Song";
|
var query = "SELECT * FROM Song";
|
||||||
|
Console.WriteLine("ffff");
|
||||||
MySqlCommand cmd = new MySqlCommand(query, conn);
|
MySqlCommand cmd = new MySqlCommand(query, conn);
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
@@ -192,17 +193,21 @@ namespace Icarus.Models.Context
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("dddd");
|
||||||
_logger.Info("Retrieving song from database");
|
_logger.Info("Retrieving song from database");
|
||||||
|
|
||||||
using (var conn = GetConnection())
|
using (var conn = GetConnection())
|
||||||
{
|
{
|
||||||
conn.Open();
|
conn.Open();
|
||||||
var query = "SELECT * FROM Song WHERE Id=@Id";
|
var query = "SELECT * FROM Song WHERE Id=@Id";
|
||||||
|
Console.WriteLine("Transfer");
|
||||||
|
|
||||||
using (var cmd = new MySqlCommand(query, conn))
|
using (var cmd = new MySqlCommand(query, conn))
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Temperment");
|
||||||
cmd.Parameters.AddWithValue("@Id", song.Id);
|
cmd.Parameters.AddWithValue("@Id", song.Id);
|
||||||
|
|
||||||
|
Console.WriteLine("Lost");
|
||||||
using (var reader = cmd.ExecuteReader())
|
using (var reader = cmd.ExecuteReader())
|
||||||
{
|
{
|
||||||
song = ParseSingleData(reader);
|
song = ParseSingleData(reader);
|
||||||
@@ -298,27 +303,26 @@ namespace Icarus.Models.Context
|
|||||||
{
|
{
|
||||||
Song song = new Song();
|
Song song = new Song();
|
||||||
|
|
||||||
|
Console.WriteLine("ddddddddddddd");
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
song = new Song
|
song.Id = Convert.ToInt32(reader["Id"]);
|
||||||
{
|
song.Title = reader["Title"].ToString();
|
||||||
Id = Convert.ToInt32(reader["Id"]),
|
song.AlbumTitle = reader["AlbumTitle"].ToString();
|
||||||
Title = reader["Title"].ToString(),
|
song.Artist = reader["Artist"].ToString();
|
||||||
AlbumTitle = reader["AlbumTitle"].ToString(),
|
song.Year = Convert.ToInt32(reader["Year"].ToString());
|
||||||
Artist = reader["Artist"].ToString(),
|
song.Genre = reader["Genre"].ToString();
|
||||||
Year = Convert.ToInt32(reader["Year"]),
|
song.Duration = Convert.ToInt32(reader["Duration"]);
|
||||||
Genre = reader["Genre"].ToString(),
|
song.Filename = reader["Filename"].ToString();
|
||||||
Duration = Convert.ToInt32(reader["Duration"]),
|
song.SongPath = reader["SongPath"].ToString();
|
||||||
Filename = reader["Filename"].ToString(),
|
song.AlbumId = Convert.ToInt32(reader["AlbumId"].ToString());
|
||||||
SongPath = reader["SongPath"].ToString(),
|
song.ArtistId = Convert.ToInt32(reader["ArtistId"].ToString());
|
||||||
AlbumId = Convert.ToInt32(reader["AlbumId"].ToString()),
|
song.GenreId = Convert.ToInt32(reader["GenreId"].ToString());
|
||||||
ArtistId = Convert.ToInt32(reader["ArtistId"].ToString()),
|
song.YearId = Convert.ToInt32(reader["YearId"].ToString());
|
||||||
GenreId = Convert.ToInt32(reader["GenreId"].ToString()),
|
|
||||||
YearId = Convert.ToInt32(reader["YearId"].ToString())
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.WriteLine("Panic");
|
||||||
|
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,29 +28,41 @@ namespace Icarus.Models.Context
|
|||||||
.HasOne(s => s.Album)
|
.HasOne(s => s.Album)
|
||||||
.WithMany(al => al.Songs)
|
.WithMany(al => al.Songs)
|
||||||
.HasForeignKey(s => s.AlbumId)
|
.HasForeignKey(s => s.AlbumId)
|
||||||
.HasConstraintName("ForeignKey_Song_Album");
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.HasOne(sa => sa.SongArtist)
|
.HasOne(sa => sa.SongArtist)
|
||||||
.WithMany(ar => ar.Songs)
|
.WithMany(ar => ar.Songs)
|
||||||
.HasForeignKey(s => s.ArtistId)
|
.HasForeignKey(s => s.ArtistId)
|
||||||
.HasConstraintName("ForeignKey_Song_Artist");
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.HasOne(s => s.SongGenre)
|
.HasOne(s => s.SongGenre)
|
||||||
.WithMany(gnr => gnr.Songs)
|
.WithMany(gnr => gnr.Songs)
|
||||||
.HasForeignKey(s => s.GenreId)
|
.HasForeignKey(s => s.GenreId)
|
||||||
.HasConstraintName("HasForeignKey_Song_Genre");
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.HasOne(s => s.SongYear)
|
.HasOne(s => s.SongYear)
|
||||||
.WithMany(yr => yr.Songs)
|
.WithMany(yr => yr.Songs)
|
||||||
.HasForeignKey(s => s.YearId)
|
.HasForeignKey(s => s.YearId)
|
||||||
.HasConstraintName("HasForeignKey_Song_Year");
|
.OnDelete(DeleteBehavior.SetNull);
|
||||||
|
|
||||||
modelBuilder.Entity<Song>()
|
modelBuilder.Entity<Song>()
|
||||||
.Property(s => s.Year)
|
.Property(s => s.Year)
|
||||||
.IsRequired(false);
|
.IsRequired(false);
|
||||||
|
modelBuilder.Entity<Song>()
|
||||||
|
.Property(s => s.YearId)
|
||||||
|
.IsRequired(false);
|
||||||
|
modelBuilder.Entity<Song>()
|
||||||
|
.Property(s => s.GenreId)
|
||||||
|
.IsRequired(false);
|
||||||
|
modelBuilder.Entity<Song>()
|
||||||
|
.Property(s => s.ArtistId)
|
||||||
|
.IsRequired(false);
|
||||||
|
modelBuilder.Entity<Song>()
|
||||||
|
.Property(s => s.AlbumId)
|
||||||
|
.IsRequired(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -31,21 +31,21 @@ namespace Icarus.Models
|
|||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Album Album { get; set; }
|
public Album Album { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int AlbumId { get; set; }
|
public int? AlbumId { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Artist SongArtist { get; set; }
|
public Artist SongArtist { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int ArtistId { get; set; }
|
public int? ArtistId { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Genre SongGenre { get; set; }
|
public Genre SongGenre { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int GenreId { get; set; }
|
public int? GenreId { get; set; }
|
||||||
|
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public Year SongYear { get; set; }
|
public Year SongYear { get; set; }
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public int YearId { get; set; }
|
public int? YearId { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user