コード例 #1
0
        public async Task <TeacherFullServiceModel> UpdateTeacherAsync(TeacherFullServiceModel teacher)
        {
            ValidateTeacherId(teacher.Id);
            ValidateIfTeacherIsDeleted(teacher.Id);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.FirstName);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.MiddleName);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.LastName);

            var teacherInDb = await db.Teachers.FindAsync(teacher.Id);

            teacherInDb.FirstName      = teacher.FirstName;
            teacherInDb.MiddleName     = teacher.MiddleName;
            teacherInDb.LastName       = teacher.LastName;
            teacherInDb.Image          = teacher.Image;
            teacherInDb.Description    = teacher.Description;
            teacherInDb.Address        = teacher.Address;
            teacherInDb.Email          = teacher.Email;
            teacherInDb.Phone          = teacher.Phone;
            teacherInDb.PhoneEmergency = teacher.PhoneEmergency;

            await SetDefaultImagePathIfImagePathIsNull(teacherInDb);
            await SetDefaultDescriptionIfDescriptionIsNull(teacherInDb);

            await db.SaveChangesAsync();

            var teacherInDbUpdated = await this.db.Teachers
                                     .Include(x => x.ClassMastered)
                                     .Include(x => x.Marks)
                                     .Include(x => x.Notes)
                                     .Include(x => x.Clubs)
                                     .ThenInclude(clubTeacher => clubTeacher.Club)
                                     .Include(x => x.Subjects)
                                     .ThenInclude(subjectTeacher => subjectTeacher.Subject)
                                     .FirstOrDefaultAsync(x => x.Id == teacher.Id);

            return(this.mapper.Map <TeacherFullServiceModel>(teacherInDbUpdated));
        }
コード例 #2
0
        public async Task <TeacherFullServiceModel> CreateTeacherAsync(TeacherFullServiceModel teacher)
        {
            ValidateIfInputStringIsNotNullOrEmpty(teacher.FirstName);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.MiddleName);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.LastName);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.Email);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.Phone);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.PhoneEmergency);
            ValidateIfInputStringIsNotNullOrEmpty(teacher.Address);
            ValidateIfDateIsNotNull(teacher.DateBirth);

            Teacher teacherToAddInDb = this.mapper.Map <Teacher>(teacher);

            await SetDefaultImagePathIfImagePathIsNull(teacherToAddInDb);
            await SetDefaultDescriptionIfDescriptionIsNull(teacherToAddInDb);

            await this.db.Teachers.AddAsync(teacherToAddInDb);

            await db.SaveChangesAsync();

            Teacher teacherAddedInDb = await this.db.Teachers.FirstOrDefaultAsync(x => x.FirstName == teacher.FirstName && x.MiddleName == teacher.MiddleName && x.LastName == teacher.LastName);

            return(this.mapper.Map <TeacherFullServiceModel>(teacherAddedInDb));
        }
コード例 #3
0
        public async Task <IActionResult> Post([FromBody] TeacherFullServiceModel teacher)
        {
            var teacherCreated = await this.teacherService.CreateTeacherAsync(teacher);

            return(Ok(teacherCreated));
        }