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()); }
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)); }
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); }
public async Task UpdateAsync(UpdateTeacherDTO TeacherDto) { var teacher = _mapper.Map <School.Domain.Teacher>(TeacherDto); await _repository.UpdateAsync(teacher); }