예제 #1
0
        public async Task <ActionResult> Put([FromBody] UpdateTeacherDTO TeacherDTO)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var Teacherd = await _teacherService.GetAsync(TeacherDTO.Id);

            if (Teacherd != null)
            {
                await _teacherService.UpdateAsync(TeacherDTO);

                return(NoContent());
            }
            return(NotFound());
        }
예제 #2
0
        public async Task <IHttpActionResult> PutTeacher(int id, UpdateTeacherDTO teacher)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != teacher.TeacherId)
            {
                return(BadRequest());
            }

            var updateResult = await TeacherService.UpdateTeacherAsync(teacher);

            if (updateResult.Updated)
            {
                return(Ok(updateResult));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public async Task <UpdateTeacherResultDTO> UpdateTeacherAsync(UpdateTeacherDTO teacher)
        {
            var updateResult = new UpdateTeacherResultDTO
            {
                Updated = false,
                Teacher = null
            };

            var teacherEntity = _repository.GetTeacherByID(teacher.TeacherId);

            var user = await _userManager.FindByIdAsync(teacherEntity.UserId);

            user.FirstName = string.IsNullOrWhiteSpace(teacher.FirstName) ? user.FirstName : teacher.FirstName;
            user.LastName  = string.IsNullOrWhiteSpace(teacher.LastName) ? user.LastName : teacher.LastName;


            //TODO: zrobić ładniejszy kod
            teacherEntity.Degree   = teacher.Degree;
            teacherEntity.Pesel    = teacher.Pesel;
            teacherEntity.Position = teacher.Position;
            teacherEntity.Room     = teacher.Room;
            teacherEntity.UserId   = user.Id;
            teacherEntity.UserData = user;
            //var newTeacher = Mapper.Map<Teacher>(teacher);
            //newTeacher.UserId = user.Id;
            //newTeacher.UserData = user;

            updateResult.Teacher = Mapper.Map <GetTeacherDTO>(teacherEntity);


            _repository.UpdateTeacher(teacherEntity);
            if (_repository.Save())
            {
                updateResult.Updated = true;
                return(updateResult);
            }

            return(updateResult);
        }
예제 #4
0
 public async Task UpdateAsync(UpdateTeacherDTO TeacherDto)
 {
     var teacher = _mapper.Map <School.Domain.Teacher>(TeacherDto);
     await _repository.UpdateAsync(teacher);
 }