2023-08-16 14:09:43 +01:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-08-08 21:03:41 +01:00
|
|
|
using OliverBooth.Data.Web.Configuration;
|
2023-08-06 15:57:23 +01:00
|
|
|
|
2023-08-13 17:33:54 +01:00
|
|
|
namespace OliverBooth.Data.Web;
|
2023-08-06 15:57:23 +01:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a session with the web database.
|
|
|
|
/// </summary>
|
2023-08-16 14:09:43 +01:00
|
|
|
internal sealed class WebContext : DbContext
|
2023-08-06 15:57:23 +01:00
|
|
|
{
|
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
2023-08-08 21:03:41 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Initializes a new instance of the <see cref="WebContext" /> class.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="configuration">The configuration.</param>
|
2023-08-06 15:57:23 +01:00
|
|
|
public WebContext(IConfiguration configuration)
|
|
|
|
{
|
|
|
|
_configuration = configuration;
|
|
|
|
}
|
|
|
|
|
2023-12-14 16:03:24 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the collection of books in the reading list.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The collection of books.</value>
|
|
|
|
public DbSet<Book> Books { get; private set; } = null!;
|
|
|
|
|
2023-12-22 14:26:18 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the collection of blacklist entries in the database.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The collection of blacklist entries.</value>
|
|
|
|
public DbSet<BlacklistEntry> ContactBlacklist { get; private set; } = null!;
|
|
|
|
|
2023-12-24 12:20:03 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the collection of programming languages in the database.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The collection of programming languages.</value>
|
|
|
|
public DbSet<ProgrammingLanguage> ProgrammingLanguages { get; private set; } = null!;
|
|
|
|
|
2023-09-24 14:36:36 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the collection of projects in the database.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The collection of projects.</value>
|
|
|
|
public DbSet<Project> Projects { get; private set; } = null!;
|
|
|
|
|
2023-08-09 21:08:57 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the set of site configuration items.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The set of site configuration items.</value>
|
|
|
|
public DbSet<SiteConfiguration> SiteConfiguration { get; private set; } = null!;
|
|
|
|
|
2023-08-13 13:27:44 +01:00
|
|
|
/// <summary>
|
|
|
|
/// Gets the collection of templates in the database.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>The collection of templates.</value>
|
|
|
|
public DbSet<Template> Templates { get; private set; } = null!;
|
|
|
|
|
2023-08-06 15:57:23 +01:00
|
|
|
/// <inheritdoc />
|
|
|
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
|
|
{
|
|
|
|
string connectionString = _configuration.GetConnectionString("Web") ?? string.Empty;
|
|
|
|
ServerVersion serverVersion = ServerVersion.AutoDetect(connectionString);
|
|
|
|
optionsBuilder.UseMySql(connectionString, serverVersion);
|
|
|
|
}
|
|
|
|
|
2023-12-24 12:20:03 +00:00
|
|
|
/// <inheritdoc />
|
2023-08-06 15:57:23 +01:00
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
{
|
2023-12-22 14:26:18 +00:00
|
|
|
modelBuilder.ApplyConfiguration(new BlacklistEntryConfiguration());
|
2023-12-14 16:03:24 +00:00
|
|
|
modelBuilder.ApplyConfiguration(new BookConfiguration());
|
2023-12-24 12:20:03 +00:00
|
|
|
modelBuilder.ApplyConfiguration(new ProgrammingLanguageConfiguration());
|
2023-09-24 14:36:36 +01:00
|
|
|
modelBuilder.ApplyConfiguration(new ProjectConfiguration());
|
2023-08-13 13:27:44 +01:00
|
|
|
modelBuilder.ApplyConfiguration(new TemplateConfiguration());
|
2023-08-09 21:08:57 +01:00
|
|
|
modelBuilder.ApplyConfiguration(new SiteConfigurationConfiguration());
|
2023-08-06 15:57:23 +01:00
|
|
|
}
|
|
|
|
}
|