예제 #1
0
        public async Task <T> CreateTeacher <T>(TeacherInputModel inputModel)
        {
            var schoolId = int.Parse(inputModel.SchoolId);
            var school   = _schoolsRepository.All().FirstOrDefault(s => s.Id == schoolId);

            if (school != null)
            {
                var teacher = new Teacher()
                {
                    FirstName = inputModel.FirstName,
                    LastName  = inputModel.LastName,
                    School    = school,
                    UniqueId  = _idGeneratorService.GenerateTeacherId()
                };

                await _teachersRepository.AddAsync(teacher);

                await _teachersRepository.SaveChangesAsync();

                BasePersonModel baseModel = _teachersRepository.All().FirstOrDefault(t => t.UniqueId == teacher.UniqueId);

                return(AutoMapperConfig.MapperInstance.Map <T>(baseModel));
            }

            throw new ArgumentException($"Sorry, we couldn't find school with id {schoolId}");
        }
예제 #2
0
 protected void Start()
 {
     PersonModel = GetComponent<BasePersonModel>();
     PersonPhysics = GetComponent<BasePhysics>();
     PersonAnimator = GetComponent<Animator>();
     PersonPhysics.SetVelocity(PersonModel.Velocity);
 }
예제 #3
0
        public async Task <T> CreatePrincipal <T>(PrincipalInputModel inputModel)
        {
            var principal = new Principal
            {
                FirstName = inputModel.FirstName,
                LastName  = inputModel.LastName,
                UniqueId  = _idGeneratorService.GeneratePrincipalId()
            };

            await _principalsRepository.AddAsync(principal);

            await _principalsRepository.SaveChangesAsync();

            BasePersonModel baseModel = _principalsRepository.All().FirstOrDefault(p =>
                                                                                   p.FirstName == inputModel.FirstName && p.LastName == inputModel.LastName);

            return(AutoMapperConfig.MapperInstance.Map <T>(baseModel));
        }
예제 #4
0
        public async Task <T> CreateParentAsync <T>(ParentInputModel inputModel)
        {
            var studentIds = inputModel.StudentIds.Select(int.Parse);
            var students   = _studentsRepository.All().Where(s => studentIds.Contains(s.Id));

            if (students.Any())
            {
                var parent = new Parent
                {
                    FirstName   = inputModel.FirstName,
                    LastName    = inputModel.LastName,
                    PhoneNumber = inputModel.PhoneNumber,
                    UniqueId    = _idGeneratorService.GenerateParentId()
                };

                await _parentsRepository.AddAsync(parent);

                await _parentsRepository.SaveChangesAsync();

                foreach (var student in students)
                {
                    var studentParentPair = new StudentParent
                    {
                        Student = student,
                        Parent  = parent
                    };

                    await _studentParentsMappingRepository.AddAsync(studentParentPair);
                }

                await _studentParentsMappingRepository.SaveChangesAsync();

                BasePersonModel baseModel = _parentsRepository.All().FirstOrDefault(p => p.UniqueId == parent.UniqueId);

                return(AutoMapperConfig.MapperInstance.Map <T>(baseModel));
            }

            throw new ArgumentException($"Sorry, we couldn't any student with id in the following list:  [{string.Join(", ", studentIds)}]");
        }
예제 #5
0
        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}");
        }