AnneeFactory.cs 938 B

12345678910111213141516171819202122232425262728293031323334
  1. using CD67.FicheCollege.Entity;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Data.Entity;
  7. namespace CD67.FicheCollege.Factory
  8. {
  9. public partial class AnneeFactory : Internal.BaseFactory<Entity.Annee>
  10. {
  11. public AnneeFactory(Entities dbContext) : base(dbContext) { }
  12. public Annee getByLibelle(params object[] keyValues)
  13. {
  14. string libelle = keyValues[0].ToString();
  15. Annee annee = base.getAll().Where(a=>a.Libelle == libelle).First();
  16. //si l'élément n'existe pas, on le créé
  17. if (annee == null)
  18. {
  19. annee = new Annee()
  20. {
  21. Libelle = libelle
  22. };
  23. this.add(ref annee);
  24. dbContext.Entry(annee).Reference(i => i.Colleges).Load();
  25. }
  26. return annee;
  27. }
  28. }
  29. }