예제 #1
0
        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());
        }
예제 #2
0
        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());
        }
예제 #3
0
        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");
        }