* #102: Moving Models and constants to their own library * #102: Updated sln file * #102: Updated README to include step install migration tool
This commit was merged in pull request #104.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Contexts;
|
||||
|
||||
public class AlbumContext : DbContext
|
||||
{
|
||||
public DbSet<Album>? Albums { get; set; }
|
||||
|
||||
public AlbumContext(DbContextOptions<AlbumContext> options) : base(options) { }
|
||||
public AlbumContext(string connString) : base(new DbContextOptionsBuilder<AlbumContext>()
|
||||
.UseMySQL(connString).Options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Album>()
|
||||
.ToTable("Album");
|
||||
}
|
||||
|
||||
public Album RetrieveRecord(Album album)
|
||||
{
|
||||
var albm = Albums!.FirstOrDefault(alb => alb.Id == album.Id);
|
||||
return albm!;
|
||||
}
|
||||
|
||||
public bool DoesRecordExist(Album album)
|
||||
{
|
||||
return Albums!.FirstOrDefault(alb => alb.Id == album.Id) != null ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Contexts;
|
||||
|
||||
public class ArtistContext : DbContext
|
||||
{
|
||||
public DbSet<Artist> Artists { get; set; }
|
||||
|
||||
public ArtistContext(DbContextOptions<ArtistContext> options) : base (options) { }
|
||||
public ArtistContext(string connString) : base(new DbContextOptionsBuilder<ArtistContext>()
|
||||
.UseMySQL(connString).Options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Artist>()
|
||||
.ToTable("Artist");
|
||||
}
|
||||
|
||||
public Artist RetrieveRecord(Artist artist)
|
||||
{
|
||||
|
||||
return Artists.FirstOrDefault(arst => arst.Id == artist.Id)!;
|
||||
}
|
||||
|
||||
|
||||
public bool DoesRecordExist(Artist artist)
|
||||
{
|
||||
return Artists.FirstOrDefault(arst => arst.Id == artist.Id) != null ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Contexts;
|
||||
|
||||
public class CoverArtContext : DbContext
|
||||
{
|
||||
#region Properties
|
||||
public DbSet<CoverArt>? CoverArtImages { get; set; }
|
||||
#endregion
|
||||
|
||||
public CoverArtContext(DbContextOptions<CoverArtContext> options) : base(options) { }
|
||||
public CoverArtContext(string connString) : base(new DbContextOptionsBuilder<CoverArtContext>()
|
||||
.UseMySQL(connString).Options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<CoverArt>()
|
||||
.ToTable("CoverArt");
|
||||
}
|
||||
|
||||
public CoverArt RetrieveRecord(CoverArt cover)
|
||||
{
|
||||
return CoverArtImages!.FirstOrDefault(cov => cov.Id == cover.Id)!;
|
||||
}
|
||||
|
||||
public bool DoesRecordExist(CoverArt cover)
|
||||
{
|
||||
return CoverArtImages!.FirstOrDefault(cov => cov.Id == cover.Id) != null ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Contexts;
|
||||
|
||||
public class GenreContext : DbContext
|
||||
{
|
||||
#region Properties
|
||||
public DbSet<Genre>? Genres { get; set; }
|
||||
#endregion
|
||||
|
||||
public GenreContext(DbContextOptions<GenreContext> options) : base(options) { }
|
||||
public GenreContext(string connString) : base(new DbContextOptionsBuilder<GenreContext>()
|
||||
.UseMySQL(connString).Options)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Genre>()
|
||||
.ToTable("Genre");
|
||||
}
|
||||
|
||||
|
||||
public Genre RetrieveRecord(Genre genre)
|
||||
{
|
||||
var gnre = Genres!.FirstOrDefault(gnr => gnr.Id == genre.Id);
|
||||
return gnre!;
|
||||
}
|
||||
|
||||
public bool DoesRecordExist(Genre genre)
|
||||
{
|
||||
return Genres!.FirstOrDefault(gnr => gnr.Id == genre.Id) != null ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Contexts;
|
||||
|
||||
public class SongContext : DbContext
|
||||
{
|
||||
public DbSet<Song>? Songs { get; set; }
|
||||
|
||||
public SongContext(string connString) : base(new DbContextOptionsBuilder<SongContext>()
|
||||
.UseMySQL(connString).Options)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public SongContext(DbContextOptions<SongContext> options) : base(options) { }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<Song>()
|
||||
.ToTable("Song");
|
||||
|
||||
modelBuilder.Entity<Song>()
|
||||
.Property(s => s.Year)
|
||||
.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);
|
||||
modelBuilder.Entity<Song>()
|
||||
.Property(s => s.CoverArtId)
|
||||
.IsRequired(false);
|
||||
}
|
||||
|
||||
|
||||
public Song RetrieveRecord(Song song)
|
||||
{
|
||||
var sng = Songs!.FirstOrDefault(sng => sng.Id == song.Id);
|
||||
return sng!;
|
||||
}
|
||||
|
||||
|
||||
public bool DoesRecordExist(Song song)
|
||||
{
|
||||
return Songs!.FirstOrDefault(sng => sng.Id == song.Id) != null ? true : false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
using Icarus.Models;
|
||||
|
||||
namespace Icarus.Database.Contexts;
|
||||
|
||||
public class UserContext : DbContext
|
||||
{
|
||||
public DbSet<User> Users { get; set; }
|
||||
|
||||
|
||||
#region Constructors
|
||||
public UserContext(DbContextOptions<UserContext> options) : base(options) { }
|
||||
[ActivatorUtilitiesConstructor]
|
||||
public UserContext(string connString) : base(new DbContextOptionsBuilder<UserContext>()
|
||||
.UseMySQL(connString).Options)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
modelBuilder.Entity<User>()
|
||||
.ToTable("User");
|
||||
modelBuilder.Entity<User>()
|
||||
.Property(u => u.LastLogin).IsRequired(false);
|
||||
modelBuilder.Entity<User>()
|
||||
.Property(u => u.DateCreated).HasDefaultValue(DateTime.Now);
|
||||
}
|
||||
|
||||
|
||||
public User RetrieveRecord(User user)
|
||||
{
|
||||
return Users.FirstOrDefault(usr => usr.Id == user.Id)!;
|
||||
}
|
||||
|
||||
public bool DoesRecordExist(User user)
|
||||
{
|
||||
return Users.FirstOrDefault(usr => usr.Id == user.Id) != null ? true : false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user