コード例 #1
0
        internal static bool StaticClasseValid(Guid classeGuid)
        {
            using (var db = new SchoolContext())
            {
                var classe = db.Classes.Find(classeGuid);

                return(PedagogyManager.StaticSessionValid(classe.Session));
            }
        }
コード例 #2
0
        /// <summary>
        /// Inscrire Un Etudiant A une Classe
        /// </summary>
        /// <param name="myEnrollement">Objet Inscription</param>
        /// <exception cref="InvalidOperationException"></exception>
        /// <returns>True si succes</returns>
        public bool EnrollStudent(Enrollement myEnrollement)
        {
            using (var db = new SchoolContext())
            {
                var classe = db.Classes.FirstOrDefault(c => c.ClasseGuid == myEnrollement.ClasseGuid && !c.IsDeleted);
                if (classe == null)
                {
                    throw new InvalidOperationException("CLASSE_REFERENCE_NOT_FOUND");
                }

                var anneeScolaireGuid = PedagogyManager.StaticGetSessionAnneeScolaireGuid(classe.Session);

                if (anneeScolaireGuid != null)
                {
                    myEnrollement.SchoolYearGuid = (Guid)anneeScolaireGuid;
                }
                else
                {
                    throw new InvalidOperationException("ANNEE_SCOLAIRE_SESSION_NOT_ACTIVE");
                }

                if (db.Students.Find(myEnrollement.StudentGuid) == null)
                {
                    throw new InvalidOperationException("STUDENT_REFERENCE_NOT_FOUND");
                }
                if (InscExist(myEnrollement.EnrollementNum))
                {
                    throw new InvalidOperationException("INSCRIPTION_ID_ALREADY_EXIST");
                }
                if (myEnrollement.InscriptionAmount < 0)
                {
                    throw new InvalidOperationException("INSCRIPTION_AMOUNT_CAN_NOT_BE_NEGATIF");
                }
                if (myEnrollement.InstallementAmount < 0)
                {
                    throw new InvalidOperationException("INSTALLEMENT_AMOUNT_CAN_NOT_BE_NEGATIF");
                }


                if (myEnrollement.EnrollementGuid == Guid.Empty)
                {
                    myEnrollement.EnrollementGuid = Guid.NewGuid();
                }

                myEnrollement.DateAdded        = DateTime.Now;
                myEnrollement.LastEditDate     = DateTime.Now;
                myEnrollement.LastEditUserGuid = Guid.Empty;
                myEnrollement.AddUserGuid      = Guid.Empty;

                db.Enrollements.Add(myEnrollement);

                if (db.SaveChanges() <= 0)
                {
                    return(false);
                }

                foreach (var recue in SchoolFeeHelper.GenerateInscriptionReceipts(myEnrollement))
                {
                    StudentsFinanceManager.StaticAddFeeReceipt(recue);
                }
                return(true);
            }
        }