public async Task <IHttpActionResult> Update([FromBody] ConsultantUpdateDto consultantUpdateDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } userRepository.Update(consultantUpdateDto.User); consultantRepository.Update(consultantUpdateDto.ConsultantUpdateDtoToConsultant()); try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { Consultant consultantToUpdate = await consultantRepository.FindByCondition(item => item.Id == consultantUpdateDto.Id).FirstOrDefaultAsync(); if (consultantToUpdate == null) { return(Content(HttpStatusCode.NotFound, "Consultant not found")); } User userToUpdate = await userRepository.FindByCondition(item => item.Id == consultantUpdateDto.User.Id).FirstOrDefaultAsync(); if (userToUpdate == null) { return(Content(HttpStatusCode.NotFound, "User not found")); } throw; } return(Ok()); }
public static Consultant ConsultantUpdateDtoToConsultant(this ConsultantUpdateDto consultantAddDto) { if (consultantAddDto != null) { return(new Consultant { Id = consultantAddDto.Id, Level = consultantAddDto.Level, Manager = null, ManagerId = consultantAddDto.ManagerId, Project = null, UserId = consultantAddDto.User.Id, ProjectId = consultantAddDto.ProjectId, SkillsFile = consultantAddDto.SkillsFile, User = null }); } return(null); }