public Education_PassportBusiness SaveNewPs(string description) { Education_PassportBusiness education_PassportSafety = new Education_PassportBusiness { PassportBusiness_Name = description, }; db.Education_PassportBusiness.Add(education_PassportSafety); db.SaveChanges(); return(education_PassportSafety); }
private void btnSaveCertificate_Click(object sender, EventArgs e) { switch (dgListPassport.Name) { case "Passport Safety": int levelPs = Convert.ToInt32(tbExt_NameCertificate.Text); Education_PassportSafety itemDb = dbEntities.Education_PassportSafety .Where(x => x.PassportSafety_LevelPS == levelPs) .FirstOrDefault(); if (itemDb == null) { passportSafetyRepository.SaveNewPs(Convert.ToInt32(tbExt_NameCertificate.Text)); dgListPassport.DataSource = dbEntities.Education_PassportSafety.ToList(); tbExt_NameCertificate.Text = ""; } else { errorProvider1.SetError(tbExt_NameCertificate, "Level PS déja présent."); btnSaveCertificate.Enabled = false; } break; case "Passport Métier": Education_PassportBusiness itemBusinessDb = dbEntities.Education_PassportBusiness .Where(x => x.PassportBusiness_Name == tbExt_NameCertificate.Text) .FirstOrDefault(); if (itemBusinessDb == null) { PassportBusinessRepository.SaveNewPs(tbExt_NameCertificate.Text); dgListPassport.DataSource = dbEntities.Education_PassportBusiness.ToList(); tbExt_NameCertificate.Text = ""; } else { errorProvider1.SetError(tbExt_NameCertificate, "Nom du passport déja présent"); btnSaveCertificate.Enabled = false; } break; case "Passport Design": Education_PassportDesign itemDesignDb = dbEntities.Education_PassportDesign .Where(x => x.PassportDesign_Name == tbExt_NameCertificate.Text) .FirstOrDefault(); if (itemDesignDb == null) { PassportDesignRepository.SaveNewPs(tbExt_NameCertificate.Text); dgListPassport.DataSource = dbEntities.Education_PassportDesign.ToList(); tbExt_NameCertificate.Text = ""; } else { errorProvider1.SetError(tbExt_NameCertificate, "Nom du passport déja présent"); btnSaveCertificate.Enabled = false; } break; case "Certificat Electrique Fonction": Education_CertifElecFunc itemFuncDb = dbEntities.Education_CertifElecFunc .Where(x => x.CertifElecFunc_LevelB == tbExt_NameCertificate.Text) .FirstOrDefault(); if (itemFuncDb == null) { CertificateElecFuncRepository.SaveNewCertificatFunc(tbExt_NameCertificate.Text); dgListPassport.DataSource = dbEntities.Education_CertifElecFunc.ToList(); tbExt_NameCertificate.Text = ""; } else { errorProvider1.SetError(tbExt_NameCertificate, "Nom du certificat déja présent"); btnSaveCertificate.Enabled = false; } break; case "Certificat Electrique OPP": Education_CertifElecOPP itemOPPDb = dbEntities.Education_CertifElecOPP .Where(x => x.CertifElecOPP_LevelR == tbExt_NameCertificate.Text) .FirstOrDefault(); if (itemOPPDb == null) { CertificateElecOPPRepository.SaveNewCertificatOPP(tbExt_NameCertificate.Text); dgListPassport.DataSource = dbEntities.Education_CertifElecFunc.ToList(); tbExt_NameCertificate.Text = ""; } else { errorProvider1.SetError(tbExt_NameCertificate, "Nom du certificat déja présent"); btnSaveCertificate.Enabled = false; } break; case "Certificat Divers": Education_CertificatDivers itemDiversDb = dbEntities.Education_CertificatDivers .Where(x => x.CertificatDivers_Name == tbExt_NameCertificate.Text) .FirstOrDefault(); if (itemDiversDb == null) { CertificateDiversRepository.SaveNew(tbExt_NameCertificate.Text); dgListPassport.DataSource = dbEntities.Education_CertificatDivers.ToList(); tbExt_NameCertificate.Text = ""; } else { errorProvider1.SetError(tbExt_NameCertificate, "Nom du certificat déja présent"); btnSaveCertificate.Enabled = false; } break; } }
private void DeletePassport(object sender, EventArgs e) { switch (typeDgv) { case "Passport Safety": Education_PassportSafety itemSafety = dbEntities.Education_PassportSafety .Where(x => x.PassportSafety_Id == PassportId) .FirstOrDefault(); itemSafety.PassportSafety_Actif = false; dbEntities.SaveChanges(); dgListPassport.DataSource = passportSafetyRepository.LoadAllPassportSafety(); break; case "Passport Métier": Education_PassportBusiness itemBusiness = dbEntities.Education_PassportBusiness .Where(x => x.PassportBusiness_Id == PassportId) .FirstOrDefault(); itemBusiness.PassportBusiness_Actif = false; dbEntities.SaveChanges(); dgListPassport.DataSource = PassportBusinessRepository.LoadAllPassportBusiness(); break; case "Passport Design": Education_PassportDesign itemBDes = dbEntities.Education_PassportDesign .Where(x => x.PassportDesign_Id == PassportId) .FirstOrDefault(); itemBDes.PassportDesign_Actif = false; dbEntities.SaveChanges(); dgListPassport.DataSource = PassportDesignRepository.LoadAllPassportDesign(); break; case "Certificat Electrique Fonction": Education_CertifElecFunc itemFunc = dbEntities.Education_CertifElecFunc .Where(x => x.CertifElecFunc_Id == PassportId) .FirstOrDefault(); itemFunc.CertifElecFunc_Actif = false; dbEntities.SaveChanges(); dgListPassport.DataSource = CertificateElecFuncRepository.LoadAllCertificateFunc(); break; case "Certificat Electrique OPP": Education_CertifElecOPP itemOpp = dbEntities.Education_CertifElecOPP .Where(x => x.CertifElecOPP_Id == PassportId) .FirstOrDefault(); itemOpp.CertifElecOPP_Actif = false; dbEntities.SaveChanges(); dgListPassport.DataSource = CertificateElecOPPRepository.LoadAllCertificateOPP(); break; case "Certificat Divers": Education_CertificatDivers itemDivers = dbEntities.Education_CertificatDivers .Where(x => x.CertificatDivers_Id == PassportId) .FirstOrDefault(); itemDivers.CertificatDivers_Actif = false; dbEntities.SaveChanges(); dgListPassport.DataSource = CertificateDiversRepository.LoadAllCertificateDivers(); break; } dgListPassport.Columns[0].Visible = false; if (dgListPassport.Columns.Count > 2) { dgListPassport.Columns[2].Visible = false; } }