示例#1
0
        public async Task Create(HealthInsuranceDataModel request)
        {
            var hasHealthInsurance = await _healthInsuranceRepository.GetAsync(request.Name);

            if (hasHealthInsurance is not null)
            {
                Notify("Já existe um convênio cadastrado com este nome informado.");
                return;
            }

            var healthInsurance = new HealthInsurance(request.Name, request.Type);

            if (healthInsurance.IsValid())
            {
                await _healthInsuranceRepository.AddAsync(healthInsurance);
            }
            else
            {
                Notify(healthInsurance.ValidationResult);
                return;
            }

            if (await CommitAsync() is false)
            {
                Notify("Erro ao salvar dados.");
            }
        }
示例#2
0
        public async Task Update(PatientDataModel request)
        {
            var patient = await _patientRepository.GetAsync(request.Id);

            if (patient is null)
            {
                Notify("Dados do Paciente não encontrado.");
                return;
            }

            if (request.BirthDate == DateTime.MinValue)
            {
                Notify("Data inválida");
                return;
            }

            patient.Update(request.BirthDate, request.Cep, request.City, request.Complement, request.Cpf.Replace(".", "").Replace("-", ""), request.District, request.Email, request.Name, request.Number, request.State, request.Street, request.MaritalStatus, request.Gender, request.Occupation, request.Telephone.Replace("(", "").Replace(")", "").Replace("-", "").Trim(), request.Cellular.Replace("(", "").Replace(")", "").Replace("-", "").Trim());

            if (patient.HealthInsurance?.Id != request.HealthInsuranceId && request.HealthInsuranceId is not null)
            {
                var newHealthInsurance = await _healthInsuranceRepository.GetAsync((Guid)request.HealthInsuranceId);

                patient.SetHealthInsurance(newHealthInsurance);
            }

            if (patient.IsValid())
            {
                _patientRepository.Update(patient);
            }
            else
            {
                Notify(patient.ValidationResult);
                return;
            }

            if (await CommitAsync() is false)
            {
                Notify("Erro ao salvar dados.");
            }
        }