public AcademicYear Create(AcademicYear itemToCreate)
 {
     var academicYear = _context.AcademicYears.Add(itemToCreate);
     _context.Entry(academicYear.Grade).State = EntityState.Modified;
     _context.SaveChanges();
     //CreateDefaultPensum(itemToCreate);
     return academicYear;
 }
 public void Import(DataSet oDataSet, AcademicYear academicYear)
 {
     var emails = new List<string>();
     if(oDataSet.Tables.Count == 0)
         return;
     if(oDataSet.Tables[0].Rows.Count <= 15)
         return;
     var dtDatos = oDataSet.Tables[0];
     var listStudents = new List<Student>();
     var listParents = new List<Parent>();
     for (var indice = 15; indice < dtDatos.Rows.Count; indice++)
     {
         if(dtDatos.Rows[indice][2].ToString().Trim().Length == 0)
             continue;
         var newStudents = new Student
         {
             IdNumber = dtDatos.Rows[indice][2].ToString()
             ,LastName = (dtDatos.Rows[indice][3] + " " + dtDatos.Rows[indice][4]).Trim()
             ,FirstName = dtDatos.Rows[indice][6].ToString()
             ,MyGender = Utilities.DefineGender(dtDatos.Rows[indice][8].ToString())
             ,BirthDate = DateTime.FromOADate(Double.Parse(dtDatos.Rows[indice][9].ToString())).ToShortDateString()
             ,Nationality = dtDatos.Rows[indice][13].ToString()
             ,State = dtDatos.Rows[indice][15].ToString()
         };
         newStudents.FullName = (newStudents.FirstName + " " + newStudents.LastName).Trim();
         var newParent = new Parent
         {
             Nationality = dtDatos.Rows[indice][16].ToString()
             ,IdNumber = dtDatos.Rows[indice][18].ToString()
             ,LastName = (dtDatos.Rows[indice][19] + " " + dtDatos.Rows[indice][20]).Trim()
             ,FirstName = dtDatos.Rows[indice][21].ToString()
             ,MyGender = Utilities.DefineGender(dtDatos.Rows[indice][22].ToString())
             ,BirthDate = DateTime.FromOADate(Double.Parse(dtDatos.Rows[indice][24].ToString())).ToShortDateString()
             ,State = dtDatos.Rows[indice][25].ToString()
             ,City = dtDatos.Rows[indice][26].ToString()
         };
         newParent.FullName = (newParent.FirstName + " " + newParent.LastName).Trim();
         var newContactInformation = new ContactInformation
         {
             Type = "Telefono"
             ,Value = dtDatos.Rows[indice][27].ToString()
             ,People = newParent
         };
         emails.Add(dtDatos.Rows[indice][28].ToString());
         var listContacts = new List<ContactInformation> {newContactInformation};
         newParent.Contacts = listContacts;
         //newParent.MyUser.Email
         newStudents.Tutor1 = newParent;
         listStudents.Add(newStudents);
         listParents.Add(newParent);
     }
     SaveData(listStudents, listParents, academicYear, emails);
 }
 public void CreateDefaultPensum(AcademicYear academicYear)
 {
     var pensums = GetDefaultPensum(academicYear.Grade.Id);
     var teacher = _context.Teachers.First(x => x.FirstName.Equals("Maestro"));
     foreach (var pensum in pensums)
     {
         var academicYearDetails = new AcademicYearDetail
         {
             TeacherStartDate = DateTime.Now,
             TeacherEndDate = DateTime.Now,
             Schedule = DateTime.Now,
             AcademicYear = academicYear,
             Course = pensum.Course,
             Teacher = teacher
         };
         _context.AcademicYearDetails.Add(academicYearDetails);
     }
     _context.SaveChanges();
 }
 public void Detach(AcademicYear academicYear)
 {
     _context.Entry(academicYear).State = EntityState.Detached;
 }
 public AcademicYear Update(AcademicYear itemToUpdate)
 {
     const bool updateCourse = false;
     var updateGrade = false;
     const bool updateTeacher = false;
     var ayear = GetById(itemToUpdate.Id);
     ayear.Approved = itemToUpdate.Approved;
     ayear.IsActive = itemToUpdate.IsActive;
     ayear.Section = itemToUpdate.Section;
     ayear.Year = itemToUpdate.Year;
     if (ayear.Grade.Id != itemToUpdate.Grade.Id)
     {
         ayear.Grade = itemToUpdate.Grade;
         updateGrade = true;
     }
     return Update(ayear, updateCourse, updateGrade, updateTeacher);
 }
 //Logic is weird. Lots of unused variables being thrown around these two functions.
 public AcademicYear Update(AcademicYear itemToUpdate, bool updateCourse = true, bool updateGrade = true,
     bool updateTeacher = true)
 {
     if (updateGrade)
         _context.Entry(itemToUpdate.Grade).State = EntityState.Modified;
     _context.SaveChanges();
     return itemToUpdate;
 }
        private void SaveData(IEnumerable<Student> listStudents, IEnumerable<Parent> listParents, AcademicYear academicYear, List<string> emails)
        {
            var allEnrolls = _enrollRepository.GetAllsEnrolls();
            var enrls = allEnrolls.Where(x => x.AcademicYear.Id == academicYear.Id);
            if (enrls.Any())
                throw new Exception("Ya hay alumos en este grado, borrelos e ingreselos denuevo");

            var allParents = _parentRepository.GetAllParents();
            var allStudents = _studentRepository.GetAllStudents();

            if (!(((EnrollRepository)_enrollRepository).GeContext().Equals(((ParentRepository)_parentRepository).GeContext())))
                return;
            if (!(((EnrollRepository)_enrollRepository).GeContext().Equals(((StudentRepository)_studentRepository).GeContext())))
                return;
            if (!(((EnrollRepository)_enrollRepository).GeContext().Equals(((AcademicYearRepository)_academicYearRepository).GeContext())))
                return;
            int iterator = 0;
            foreach (var pare in listParents)
            {
                var temp = allParents.Where(x => x.IdNumber == pare.IdNumber);
                if (!temp.Any())
                {
                    var newUser = new User
                    {
                        DisplayName = pare.FirstName,
                        Email = emails[iterator],
                        Password = _passwordGenerationService.GenerateTemporaryPassword(),
                        IsActive = true,
                        Role = Roles.Padre
                    };
                    //TODO: add to newUsers table.
                    newUser = _userRepository.Create(newUser);

                    pare.MyUser = newUser;
                    _parentRepository.Create(pare);
                }
                else
                {
                    pare.Id = temp.First().Id;
                }
                iterator++;
            }
            foreach (var stu in listStudents)
            {
                var temp = allStudents.Where(x => x.IdNumber == stu.IdNumber);
                if (!temp.Any())
                {
                    stu.MyUser = stu.Tutor1.MyUser;
                    _studentRepository.Create(stu);
                }
                else
                    stu.Id = temp.First().Id;
                var enr = allEnrolls.Where(x => x.AcademicYear.Id == academicYear.Id && x.Student.Id == stu.Id);
                if (enr.Any()) continue;
                var te = new Enroll();
                var academicYearTemp = _academicYearRepository.GetById(academicYear.Id);
                var studentTemp = _studentRepository.GetById(stu.Id);
                te.AcademicYear = academicYearTemp;
                te.Student = studentTemp;
                _enrollRepository.Create(te);
            }
        }
 public Notification(string subject, string message, PeopleWithUser @from, PeopleWithUser to, NotificationType personal, AcademicYear academicYear)
 {
     AcademicYear        = academicYear;
     Title               = subject;
     Message             = message;
     NotificationCreator = @from;
     To = to;
     NotificationType     = personal;
     NotificationComments = new HashSet <NotificationComment>();
     RecipientUsers       = new HashSet <User>();
     CreationDate         = DateTime.UtcNow;
 }