public Doctor Create(CreateDoctorDto doctor) { var user = _service.Create(new CreateUserDto(doctor.Email, doctor.Password, doctor.Nickname, (int)EPermission.Doctor, true)); if (user.Invalid) { AddNotifications(user.Notifications); return(null); } var doctorTmp = new Doctor(0, doctor.Name, doctor.Specialty, doctor.CodeRegister, user, doctor.Enabled); if (_repository.DoctorExists(doctorTmp)) { AddNotification("Doctor", "O Médico já existe!"); } if (doctorTmp.Valid) { _repository.Save(doctorTmp); } AddNotifications(user.Notifications); return(doctorTmp); }
public IActionResult DeleteDoctor(Guid id) { if (!_doctor.DoctorExists(id)) { return(NotFound()); } var doctorsDto = _doctor.GetDoctor(id); if (_patient.PatientExistsByDoctor(id)) { ModelState.AddModelError("", "This Doctor have One or more Patients"); return(StatusCode(404, ModelState)); } if (!_doctor.DeleteDoctor(doctorsDto)) { ModelState.AddModelError("", $"Something went wrong when you trying to deleting {doctorsDto.Name}"); return(StatusCode(500, ModelState)); } return(NoContent()); }
public bool DoctorExists(int id) { return(_doctorRepo.DoctorExists(id)); }