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