public IActionResult UpdateDoctor([FromBody] DoctorUpdateDto doctorsDto) { if (doctorsDto == null) { return(BadRequest(ModelState)); } var objeto = _doctor.GetDoctor(doctorsDto.Id); var doctorsObj = _mapper.Map <Doctor>(doctorsDto); doctorsObj.CRMEnd = doctorsObj.CRM + "-" + doctorsObj.CRMUF; if (_doctor.CRMEndExists(doctorsObj.CRM + doctorsObj.CRMUF)) { if (objeto.CRMEnd != doctorsObj.CRMEnd) { ModelState.AddModelError("", "This CRM already Exist"); return(StatusCode(404, ModelState)); } } if (!_doctor.UpdateDoctor(objeto)) { ModelState.AddModelError("", $"Something went wrong when you trying to updating {doctorsDto.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public ActionResult DoctorUpdateDto(int id, DoctorUpdateDto doctorUpdate) { var doctorUpdateRepo = _doctorsRepo.GetDoctorById(id); if (doctorUpdateRepo == null) { return(NotFound()); } _mapper.Map(doctorUpdate, doctorUpdateRepo); _doctorsRepo.UpdateDoctor(doctorUpdateRepo); _doctorsRepo.SaveChanges(); return(NoContent()); }
public async Task <ActionResult <Doctor> > Update(int id, [FromForm] DoctorUpdateDto doctorUpdateDto) { if (id != doctorUpdateDto.Id) { return(BadRequest()); } var mapperDoctor = _mapper.Map <Doctor>(doctorUpdateDto); var doctor = await _doctorRepository.UpdateDoctorAsync(mapperDoctor, _env.WebRootPath); if (doctor == null) { return(BadRequest()); } return(Ok(doctor)); }
public async Task <IActionResult> ModificarPerfilDoctor(int id, DoctorUpdateDto doctorUpdateDto) { if (id != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var userFromDB = await _repo.ObtenerDoctor(id); _mapper.Map(doctorUpdateDto, userFromDB); if (await _repo.SaveAll()) { return(NoContent()); } throw new Exception("No se pudo actualizar la información del usuario"); }