You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Digitalisation_EPA_Serveur/Context/EpContext.cs

168 lines
6.3 KiB

using EPAServeur.Models.EP;
using EPAServeur.Models.Formation;
using EPAServeur.Models.Notes;
using EPAServeur.Models.SaisieChamp;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace EPAServeur.Context
{
public class EpContext : DbContext
{
//EP
public DbSet<AugmentationSalaire> AugmentationSalaire { get; set; }
public DbSet<Autorisation> Autorisation { get; set; }
public DbSet<ChoixTypeEntretien> ChoixTypeEntretien { get; set; }
public DbSet<Document> Document { get; set; }
public DbSet<Engagement> Engagement { get; set; }
public DbSet<Ep> Ep { get; set; }
public DbSet<Objectif> Objectifs { get; set; }
public DbSet<ObjectifPrecedent> ObjectifPrecedents { get; set; }
public DbSet<RdvEntretien> RdvEntretiens { get; set; }
public DbSet<TypeEntretien> TypeEntretien { get; set; }
//Formation
public DbSet<DemandeFormation> DemandeFormation { get; set; }
public DbSet<Formation> Formation { get; set; }
public DbSet<ParticipationFormation> ParticipationFormation { get; set; }
public DbSet<StatutFormation> StatutFormation { get; set; }
public DbSet<Theme> Theme { get; set; }
//Note
public DbSet<Note> Note { get; set; }
//SaisieChamp
public DbSet<Champ> Champ { get; set; }
public DbSet<Saisie> Saisie { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySQL("server=localhost;database=server_ep;user=root;password=root");//PENSER A METTRE DANS UN FICHIER DE CONFIG
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
//EP
modelBuilder.Entity<AugmentationSalaire>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<Autorisation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<Document>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<Engagement>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<Ep>(entity =>
{
entity.HasKey(e => e.Id);
entity.HasOne<AugmentationSalaire>(e => e.AugmentationSalaire).WithOne(a => a.Ep).HasForeignKey<AugmentationSalaire>(a => a.EpId);
entity.HasOne<Autorisation>(e => e.Autorisation).WithOne( a => a.Ep).HasForeignKey<Autorisation>(a => a.EpId);
entity.HasMany<ChoixTypeEntretien>(e => e.ChoixTypeEntretien).WithOne(c => c.Ep);
entity.HasOne<Delegation>(e => e.Delegation).WithOne(d => d.Ep).HasForeignKey<Delegation>(d => d.EpId);
entity.HasMany<DemandeFormation>(e => e.DemandesFormation).WithOne(d => d.Ep);
entity.HasMany<Document>(e => e.Documents).WithOne(d => d.Ep);
entity.HasMany<Engagement>(e => e.Engagements).WithOne(e => e.Ep);
entity.HasMany<Objectif>(e => e.Objectifs).WithOne(o => o.Ep);
entity.HasMany<ObjectifPrecedent>(e => e.ObjectifsPrecedents).WithOne(o => o.Ep);
entity.HasMany<ParticipantEP>(e => e.Participants).WithOne(p => p.Ep);
entity.HasOne<RdvEntretien>(e => e.RdvEntretien).WithOne(r => r.EpChoixFinal).HasForeignKey<RdvEntretien>(r => r.EpId);
entity.HasMany<RdvEntretien>(e => e.PropositionsRDV).WithOne(r => r.EpProposition);
});
modelBuilder.Entity<Objectif>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<ObjectifPrecedent>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<RdvEntretien>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<TypeEntretien>(entity =>
{
entity.HasKey(e => e.Id);
});
//Formation
modelBuilder.Entity<DemandeFormation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<Formation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<ParticipationFormation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<StatutFormation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<Theme>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
//Notes
modelBuilder.Entity<Note>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
//SaisieChamp
modelBuilder.Entity<Champ>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
modelBuilder.Entity<Saisie>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
});
}
}
}