AnneeFactory.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. using System.Linq.Expressions;
  8. namespace CD67.FicheCollege.Factory
  9. {
  10. public partial class AnneeFactory : Internal.BaseFactory<Entity.Annee>
  11. {
  12. //public AnneeFactory(Entities dbContext) : base(dbContext) { }
  13. public Annee getByLibelle(params object[] keyValues)
  14. {
  15. string libelle = keyValues[0].ToString();
  16. Annee annee = base.getAll().Where(a=>a.Libelle == libelle).First();
  17. //si l'élément n'existe pas, on le créé
  18. if (annee == null)
  19. {
  20. annee = new Annee()
  21. {
  22. Libelle = libelle
  23. };
  24. this.add(ref annee);
  25. dbContext.Entry(annee).Reference(i => i.Colleges).Load();
  26. }
  27. return annee;
  28. }
  29. // Retourne l'id de l'année courante
  30. public int get_current_year_id()
  31. {
  32. string annee_lib;
  33. if (DateTime.Now.Month <= 7)
  34. {
  35. annee_lib = String.Format("{0}-{1}", DateTime.Now.Year - 1, DateTime.Now.Year);
  36. }
  37. else
  38. {
  39. annee_lib = String.Format("{0}-{1}", DateTime.Now.Year, DateTime.Now.Year + 1);
  40. }
  41. return dbContext.Annees.Where(a => a.Libelle == annee_lib).First().Id;
  42. }
  43. }
  44. }