public Patient Create(CreatePatientDto patient) { var patientTmp = new Patient(0, patient.Name, (EGender)patient.Gender, patient.Email, patient.PhoneNumber, patient.Details, patient.BirthDate, patient.Enabled); if (_repository.PatientExists(patientTmp)) { patientTmp.AddNotification("Patient", "Paciente já existe"); } if (patientTmp.Valid) { _repository.Save(patientTmp); } return(patientTmp); }
public ResponseModel Save(Patient entity) { try { entity.Validate(); if (CpfExist(entity.CPF)) { entity.AddNotification("CPF", "Este CPF já foi cadastrado"); } if (entity.Notifications.Count > 0) { return(new ResponseModel { Status = EResultStatus.Failure, Notifications = entity.Notifications, Message = "Falha ao tentar cadastrar o paciente" }); } else { _uow.PatientRepository.Add(entity); _uow.SaveChanges(); return(new ResponseModel { Status = EResultStatus.Success, Location = $"/api/patients/{entity.Id}", Message = "Paciente cadastrado com sucesso" }); } } catch (Exception ex) { return(new ResponseModel { Status = EResultStatus.Failure, InnerException = ex.Message, Message = "Falha ao tentar cadastrar o paciente" }); } }