public async Task <T> CreateStudent <T>(StudentInputModel inputModel) { var schoolId = int.Parse(inputModel.SchoolId); var school = _schoolsRepository.All().FirstOrDefault(s => s.Id == schoolId); if (school != null) { var classId = int.Parse(inputModel.ClassId); if (school.Classes.Any(c => c.Id == classId)) { var student = new Student { FirstName = inputModel.FirstName, LastName = inputModel.LastName, BirthDate = inputModel.BirthDate, PersonalIdentificationNumber = inputModel.PersonalIdentificationNumber, School = school, Class = school.Classes.FirstOrDefault(c => c.Id == classId), UniqueId = _idGeneratorService.GenerateStudentId() }; await _studentsRepository.AddAsync(student); await _studentsRepository.SaveChangesAsync(); BasePersonModel baseModel = _studentsRepository.All().FirstOrDefault(p => p.FirstName == inputModel.FirstName && p.LastName == inputModel.LastName && p.PersonalIdentificationNumber == inputModel.PersonalIdentificationNumber); //ToDo: Just change to uniqueId from student above return(AutoMapperConfig.MapperInstance.Map <T>(baseModel)); } throw new ArgumentException($"Sorry, school with id {schoolId} doesn't contain class with id {classId}"); } throw new ArgumentException($"Sorry, we couldn't find school with id {schoolId}"); }
private async Task SeedStudents(ApplicationDbContext dbContext) { if (dbContext.Students.Any()) { return; } var primarySchoolStudents5A = new List <Student>() { new Student { FirstName = "Dafincho", LastName = "Dafidov", BirthDate = new DateTime(2010, 12, 15), PersonalIdentificationNumber = "1012150000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Slavka", LastName = "Slavkova", BirthDate = new DateTime(2010, 1, 10), PersonalIdentificationNumber = "1001101111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() } }; var primarySchoolStudents7A = new List <Student>() { new Student { FirstName = "Rumen", LastName = "Rumenov", BirthDate = new DateTime(2008, 12, 15), PersonalIdentificationNumber = "0812150000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Boyko", LastName = "Boykov", BirthDate = new DateTime(2008, 1, 10), PersonalIdentificationNumber = "0801101111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Cvetko", LastName = "Cvetkov", BirthDate = new DateTime(2008, 10, 29), PersonalIdentificationNumber = "0810291111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, }; var primarySchoolStudents7B = new List <Student>() { new Student { FirstName = "Albena", LastName = "Litstein", BirthDate = new DateTime(2008, 11, 11), PersonalIdentificationNumber = "0811110000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Rosko", LastName = "Roskov", BirthDate = new DateTime(2008, 5, 15), PersonalIdentificationNumber = "0805151111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Alberto", LastName = "Svqtkov", BirthDate = new DateTime(2008, 10, 18), PersonalIdentificationNumber = "0810101111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, }; var primarySchoolStudents7C = new List <Student>() { new Student { FirstName = "Rosalinda", LastName = "Balareva", BirthDate = new DateTime(2008, 11, 11), PersonalIdentificationNumber = "0811110000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Andrew", LastName = "Feshuna", BirthDate = new DateTime(2008, 8, 15), PersonalIdentificationNumber = "0808151111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Alex", LastName = "Svqtkov", BirthDate = new DateTime(2008, 10, 1), PersonalIdentificationNumber = "0810011111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, }; var elsStudents8A = new List <Student>() { new Student { FirstName = "Rumen", LastName = "Radoychev", BirthDate = new DateTime(2007, 12, 15), PersonalIdentificationNumber = "0712150000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Big", LastName = "Boykov", BirthDate = new DateTime(2007, 1, 10), PersonalIdentificationNumber = "0701101111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Cece", LastName = "Cvetkov", BirthDate = new DateTime(2007, 10, 29), PersonalIdentificationNumber = "0710291111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, }; var elsStudents12A = new List <Student>() { //ToDo }; var elsStudents12B = new List <Student>() { //ToDo }; var elsStudents12C = new List <Student>() { //ToDo }; var ntbgStudents8A = new List <Student>() { new Student { FirstName = "Samoten", LastName = "Voin", BirthDate = new DateTime(2007, 12, 12), PersonalIdentificationNumber = "0712120000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() } }; var ntbgStudents8C = new List <Student>() { new Student { FirstName = "Bala", LastName = "Rosalindova", BirthDate = new DateTime(2007, 11, 11), PersonalIdentificationNumber = "0711110000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Freddy", LastName = "Feshuna", BirthDate = new DateTime(2007, 8, 15), PersonalIdentificationNumber = "0708151111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Alex", LastName = "Alexandrov", BirthDate = new DateTime(2007, 10, 1), PersonalIdentificationNumber = "0710011111", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, }; var ntbgStudents12A = new List <Student>() { //ToDo }; var ntbgStudents12B = new List <Student>() { //ToDo }; var nbuStudents = new List <Student>() { new Student { FirstName = "Noviqt", LastName = "Bulgarin", BirthDate = new DateTime(1991, 11, 11), PersonalIdentificationNumber = "9111110000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Radomitko", LastName = "Mitkoradov", BirthDate = new DateTime(1995, 12, 11), PersonalIdentificationNumber = "9521110000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Peter", LastName = "Peterov", BirthDate = new DateTime(1999, 5, 5), PersonalIdentificationNumber = "9905050000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() }, new Student { FirstName = "Edmund", LastName = "Shwartz", BirthDate = new DateTime(1988, 1, 31), PersonalIdentificationNumber = "8801310000", Username = "******", Email = "*****@*****.**", UniqueId = _idGeneratoService.GenerateStudentId() } }; if (nbuStudents.Any(s => s.UniqueId == null)) { var exampleStudent = nbuStudents.FirstOrDefault(s => s.UniqueId == null); Console.WriteLine($"NBU student with null id: {exampleStudent.Email}"); } var primarySchoolStudents = new List <Student>(); primarySchoolStudents.AddRange(primarySchoolStudents5A); primarySchoolStudents.AddRange(primarySchoolStudents7A); primarySchoolStudents.AddRange(primarySchoolStudents7B); primarySchoolStudents.AddRange(primarySchoolStudents7C); if (primarySchoolStudents.Any(s => s.UniqueId == null)) { var exampleStudent = primarySchoolStudents.FirstOrDefault(s => s.UniqueId == null); Console.WriteLine($"Primary school student with null id: {exampleStudent.Email}"); } // 142 OU students relations var primarySchool = await dbContext.Schools.Include(s => s.Classes).FirstOrDefaultAsync(s => s.Type == SchoolType.PrimarySchool); if (primarySchool != null) { primarySchool.Students = primarySchoolStudents; dbContext.Update(primarySchool); var class5A = primarySchool.Classes.FirstOrDefault(c => c.Letter == 'A' && c.Year == 5); class5A.Students = primarySchoolStudents5A; dbContext.Update(class5A); var class7A = primarySchool.Classes.FirstOrDefault(c => c.Letter == 'A' && c.Year == 7); class7A.Students = primarySchoolStudents7A; dbContext.Update(class7A); var class7B = primarySchool.Classes.FirstOrDefault(c => c.Letter == 'B' && c.Year == 7); class7B.Students = primarySchoolStudents7B; dbContext.Update(class7B); var class7C = primarySchool.Classes.FirstOrDefault(c => c.Letter == 'C' && c.Year == 7); class7C.Students = primarySchoolStudents7C; dbContext.Update(class7C); } var secondEnglishLanguageSchoolStudents = new List <Student>(); secondEnglishLanguageSchoolStudents.AddRange(elsStudents8A); secondEnglishLanguageSchoolStudents.AddRange(elsStudents12A); secondEnglishLanguageSchoolStudents.AddRange(elsStudents12B); secondEnglishLanguageSchoolStudents.AddRange(elsStudents12C); if (secondEnglishLanguageSchoolStudents.Any(s => s.UniqueId == null)) { var exampleStudent = secondEnglishLanguageSchoolStudents.FirstOrDefault(s => s.UniqueId == null); Console.WriteLine($"2ELS student with null id: {exampleStudent.Email}"); } // 2 els students relations var secondEnglishLanguageSchool = await dbContext.Schools.Include(s => s.Classes).FirstOrDefaultAsync(s => s.Type == SchoolType.HighSchool && s.Name.Contains("Second English Language High School")); if (secondEnglishLanguageSchool != null) { secondEnglishLanguageSchool.Students = secondEnglishLanguageSchoolStudents; dbContext.Update(secondEnglishLanguageSchool); var elsClass8A = secondEnglishLanguageSchool.Classes.FirstOrDefault(c => c.Letter == 'A' && c.Year == 8); elsClass8A.Students = elsStudents8A; dbContext.Update(elsClass8A); var elsClass12A = secondEnglishLanguageSchool.Classes.FirstOrDefault(c => c.Letter == 'A' && c.Year == 12); elsClass12A.Students = elsStudents12A; dbContext.Update(elsClass12A); var elsClass12B = secondEnglishLanguageSchool.Classes.FirstOrDefault(c => c.Letter == 'B' && c.Year == 12); elsClass12B.Students = elsStudents12B; dbContext.Update(elsClass12B); var elsClass12C = secondEnglishLanguageSchool.Classes.FirstOrDefault(c => c.Letter == 'C' && c.Year == 12); elsClass12C.Students = elsStudents12C; dbContext.Update(elsClass12C); } var ntbgStudents = new List <Student>(); ntbgStudents.AddRange(ntbgStudents8A); ntbgStudents.AddRange(ntbgStudents8C); ntbgStudents.AddRange(ntbgStudents12A); ntbgStudents.AddRange(ntbgStudents12B); if (ntbgStudents.Any(s => s.UniqueId == null)) { var exampleStudent = ntbgStudents.FirstOrDefault(s => s.UniqueId == null); Console.WriteLine($"NTBG student with null id: {exampleStudent.Email}"); } // 2 els students relations var nationalTradingAndBankingSchool = await dbContext.Schools.Include(s => s.Classes).FirstOrDefaultAsync(s => s.Type == SchoolType.HighSchool && s.Name.Contains("National Trade and Banking High School")); if (nationalTradingAndBankingSchool != null) { nationalTradingAndBankingSchool.Students = ntbgStudents; dbContext.Update(nationalTradingAndBankingSchool); var ntbgClass8A = nationalTradingAndBankingSchool.Classes.FirstOrDefault(c => c.Letter == 'A' && c.Year == 8); ntbgClass8A.Students = ntbgStudents8A; dbContext.Update(ntbgClass8A); var ntbgClass8C = nationalTradingAndBankingSchool.Classes.FirstOrDefault(c => c.Letter == 'C' && c.Year == 8); ntbgClass8C.Students = ntbgStudents8C; dbContext.Update(ntbgClass8C); var ntbgClass12A = nationalTradingAndBankingSchool.Classes.FirstOrDefault(c => c.Letter == 'A' && c.Year == 12); ntbgClass12A.Students = ntbgStudents12A; dbContext.Update(ntbgClass12A); var ntbgClass12B = nationalTradingAndBankingSchool.Classes.FirstOrDefault(c => c.Letter == 'B' && c.Year == 12); ntbgClass12B.Students = ntbgStudents12B; dbContext.Update(ntbgClass12B); } var nbu = await dbContext.Schools.FirstOrDefaultAsync(s => s.Type == SchoolType.University && s.Name.Contains("New Bulgarian University")); if (nbu != null) { nbu.Students = nbuStudents; dbContext.Update(nbu); } await dbContext.SaveChangesAsync(); }
public void GenerateStudentId_WithSingleId_ShouldGenerateIdForStudent() { var id = _idGeneratorService.GenerateStudentId(); id.Should().StartWith(GlobalConstants.StudentIdPrefix.ToString()); }