mirror of
https://gitlab.com/Hukuta47/cartrix.git
synced 2026-12-05 12:30:55 +00:00
69 lines
3.5 KiB
C#
69 lines
3.5 KiB
C#
using Microsoft.EntityFrameworkCore;
|
||
using CartriX.Api.Entities;
|
||
|
||
namespace CartriX.Api
|
||
{
|
||
|
||
public class AppDbContext : DbContext
|
||
{
|
||
public AppDbContext(DbContextOptions options) : base(options) { }
|
||
|
||
public DbSet<Article> Articles { get; set; }
|
||
public DbSet<RecordPrintedPages> RecordPrintedPages { get; set; }
|
||
public DbSet<Cartridge> Cartridges { get; set; }
|
||
public DbSet<RequestToReplaceCartridge> RequestsToReplaceCartridge { get; set; }
|
||
public DbSet<CauseFoReplace> CausesFoReplace { get; set; }
|
||
public DbSet<CartridgeModel> CartridgeModels { get; set; }
|
||
public DbSet<PrinterStatus> PrinterStatuses { get; set; }
|
||
public DbSet<Location> Locations { get; set; }
|
||
public DbSet<Manufacturer> Manufacturers { get; set; }
|
||
public DbSet<Printer> Printers { get; set; }
|
||
public DbSet<PrinterConnetctionType> PrinterConnetctionTypes { get; set; }
|
||
public DbSet<PrinterModel> PrinterModels { get; set; }
|
||
public DbSet<PrinterPrintType> PrinterPrintTypes { get; set; }
|
||
public DbSet<CartridgeStatus> CartridgeStatuses { get; set; }
|
||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||
{
|
||
base.OnModelCreating(modelBuilder);
|
||
|
||
modelBuilder.Entity<Location>().HasIndex(l => l.Name).IsUnique();
|
||
modelBuilder.Entity<Printer>().HasIndex(l => l.Name).IsUnique();
|
||
|
||
modelBuilder.Entity<PrinterPrintType>().HasData(
|
||
new { Id = 1, Name = "Лазерный" },
|
||
new { Id = 2, Name = "Струйный" }
|
||
);
|
||
modelBuilder.Entity<CartridgeStatus>().HasData(
|
||
new { Id = 1, Name = "Установлен" },
|
||
new { Id = 2, Name = "На складе" },
|
||
new { Id = 3, Name = "На заправке" },
|
||
new { Id = 4, Name = "Очередь на заправку" },
|
||
new { Id = 5, Name = "В ремонте" }
|
||
);
|
||
modelBuilder.Entity<PrinterStatus>().HasData(
|
||
new { Id = 1, Name = "Активный" },
|
||
new { Id = 2, Name = "Недоступен" },
|
||
new { Id = 3, Name = "В ремонте" }
|
||
);
|
||
modelBuilder.Entity<PrinterConnetctionType>().HasData(
|
||
new { Id = 1, Name = "Сетевой" },
|
||
new { Id = 2, Name = "USB" }
|
||
);
|
||
modelBuilder.Entity<Manufacturer>().HasData(
|
||
new Manufacturer { Id = 1, Name = "Неизвестен" }
|
||
);
|
||
modelBuilder.Entity<CauseFoReplace>().HasData(
|
||
new { Id = 1, Name = "Закончился", Description="Картридж истратил свой тоннер и требует заправки." },
|
||
new { Id = 2, Name = "Полосит", Description="Картридж работает не корректно, оставляет полосы на распечатанной бумаге. \nТребуется диагностика." },
|
||
new { Id = 3, Name = "Бледнит", Description="Картридж работает не корректно, тоннер наноситься на бумагу бледно. \nТребуется диагностика." }
|
||
);
|
||
|
||
modelBuilder.Entity<Printer>()
|
||
.HasOne(p => p.InstalledCartridge)
|
||
.WithOne(c => c.InstalledInPrinter)
|
||
.HasForeignKey<Cartridge>(c => c.InstalledInPrinterId);
|
||
}
|
||
}
|
||
}
|