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

292 lines
12 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> Objectif { get; set; }
public DbSet<ObjectifPrecedent> ObjectifPrecedent { get; set; }
public DbSet<RdvEntretien> RdvEntretien { get; set; }
public DbSet<TypeEntretien> TypeEntretien { get; set; }
//Formation
public DbSet<DemandeFormation> DemandeFormation { get; set; }
public DbSet<Formation> Formation { get; set; }
public DbSet<ModeFormation> ModeFormation { get; set; }
public DbSet<OrigineDemandeFormation> OrigineDemandeFormation { get; set; }
public DbSet<OrigineFormation> OrigineFormation { get; set; }
public DbSet<ParticipationFormation> ParticipationFormation { get; set; }
public DbSet<StatutFormation> StatutFormation { get; set; }
public DbSet<Theme> Theme { get; set; }
public DbSet<TypeFormation> TypeFormation { 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);
entity.HasIndex(e => e.Libelle).IsUnique();
});
//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<ModeFormation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
entity.HasIndex(e => e.Libelle).IsUnique();
});
modelBuilder.Entity<OrigineDemandeFormation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
entity.HasIndex(e => e.Libelle).IsUnique();
});
modelBuilder.Entity<OrigineFormation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
entity.HasIndex(e => e.Libelle).IsUnique();
});
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();
entity.HasIndex(e => e.Libelle).IsUnique();
});
modelBuilder.Entity<Theme>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
entity.HasIndex(e => e.Libelle).IsUnique();
});
modelBuilder.Entity<TypeFormation>(entity =>
{
entity.HasKey(e => e.Id);
entity.Property(e => e.Id).ValueGeneratedOnAdd();
entity.HasIndex(e => e.Libelle).IsUnique();
});
//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();
});
}
public void AjoutTheme() //Les thèmes pourront être ajoutés et conservés
{
Theme management, securite, developpement, gestionprojet;
management = new Theme { Libelle = "Management" };
this.Theme.Add(management);
securite = new Theme { Libelle = "Sécurité" };
this.Theme.Add(securite);
developpement = new Theme { Libelle = "Développement" };
this.Theme.Add(developpement);
gestionprojet = new Theme { Libelle = "Gestion de projet" };
this.Theme.Add(gestionprojet);
this.SaveChanges();
}
/*Les informations ajou
* */
public void AjoutInformationsDeBase() //Les statuts pourront être ajoutés et conservés
{
//StatutFormation
StatutFormation s;
s = new StatutFormation { Libelle = "Planifiée" };
this.StatutFormation.Add(s);
s = new StatutFormation { Libelle = "Replanifié" };
this.StatutFormation.Add(s);
s = new StatutFormation { Libelle = "Réalisée" };
this.StatutFormation.Add(s);
s = new StatutFormation { Libelle = "Annulée" };
this.StatutFormation.Add(s);
//ModeFormation
ModeFormation m;
m = new ModeFormation { Libelle = "Externe" };
this.ModeFormation.Add(m);
m = new ModeFormation { Libelle = "Interne" };
this.ModeFormation.Add(m);
m = new ModeFormation { Libelle = "Présentiel" };
this.ModeFormation.Add(m);
m = new ModeFormation { Libelle = "E-learning" };
this.ModeFormation.Add(m);
//TypeFormation
TypeFormation type;
type = new TypeFormation { Libelle = "Externe" };
this.TypeFormation.Add(type);
type = new TypeFormation { Libelle = "Interne" };
this.TypeFormation.Add(type);
type = new TypeFormation { Libelle = "E-learning" };
this.TypeFormation.Add(type);
type = new TypeFormation { Libelle = "Academy by Apside" };
this.TypeFormation.Add(type);
//OrigineFormation
OrigineFormation of;
of = new OrigineFormation { Libelle = "Demande collaborateur" };
this.OrigineFormation.Add(of);
of = new OrigineFormation { Libelle = "Exigence client" };
this.OrigineFormation.Add(of);
of = new OrigineFormation { Libelle = "Exigence Apside" };
this.OrigineFormation.Add(of);
of = new OrigineFormation { Libelle = "Formation réglementaire" };
this.OrigineFormation.Add(of);
//OrigineDemandeFormation
OrigineDemandeFormation o;
o = new OrigineDemandeFormation { Libelle = "Demande collaborateur" };
this.OrigineDemandeFormation.Add(o);
o = new OrigineDemandeFormation { Libelle = "Demande EP" };
this.OrigineDemandeFormation.Add(o);
o = new OrigineDemandeFormation { Libelle = "Exigence Client" };
this.OrigineDemandeFormation.Add(o);
o = new OrigineDemandeFormation { Libelle = "Formation réglementaire" };
this.OrigineDemandeFormation.Add(o);
o = new OrigineDemandeFormation { Libelle = "Demande Apside" };
this.OrigineDemandeFormation.Add(o);
//TypeEntretien
TypeEntretien t;
t = new TypeEntretien { Libelle = "Sur site" };
this.TypeEntretien.Add(t);
t = new TypeEntretien { Libelle = "Chez le client" };
this.TypeEntretien.Add(t);
t = new TypeEntretien { Libelle = "Visioconférence" };
this.TypeEntretien.Add(t);
t = new TypeEntretien { Libelle = "Téléphonique" };
this.TypeEntretien.Add(t);
this.SaveChanges();
}
}
}