public override Result <Requester> Register(RequesterModel model) { try { Requester requester = _mapper.Map <Requester>(model); requester.Guid = Guid.NewGuid(); var resultAdress = _addressBLL.Register(model.AddressModel); if (!resultAdress.Success) { return(Result <Requester> .BuildError(resultAdress.Messages)); } requester.Address = resultAdress.Model; var result = _requesterValidation.Validate(requester); if (!result.Success) { return(result); } _requesterDAL.Insert(requester); var resultSave = _requesterDAL.Save(); if (!resultSave.Success) { return(Result <Requester> .BuildError(resultSave.Messages)); } return(Result <Requester> .BuildSuccess(requester)); } catch (Exception error) { return(Result <Requester> .BuildError("Erro no momento de registrar o solicitante.", error)); } }
public override Result <Employee> Register(EmployeeModel employeeModel) { try { var employee = _mapper.Map <Employee>(employeeModel); employee.Guid = Guid.NewGuid(); var resultAdress = _addressBLL.Register(employeeModel.AddressModel); if (!resultAdress.Success) { return(Result <Employee> .BuildError(resultAdress.Messages)); } employee.Address = resultAdress.Model; var result = _employeeValidation.Validate(employee); if (!result.Success) { return(result); } _employeeDAL.Insert(employee); var resultSave = _employeeDAL.Save(); if (!resultSave.Success) { return(Result <Employee> .BuildError(resultSave.Messages)); } return(Result <Employee> .BuildSuccess(employee)); } catch (Exception error) { return(Result <Employee> .BuildError("Erro no momento de registar o funcionário.", error)); } }
public override Result <Emergency> Update(EmergencyModel model) { try { //lógica para remover pacientes vazios var patientsRemove = model.PatientModels.Where ( d => d.Age == 0 && d.Gender == Entities.Enums.Gender.Invalido && string.IsNullOrWhiteSpace(d.Name) && d.Id == 0 ).ToList(); patientsRemove.ForEach(d => model.PatientModels.Remove(d)); Emergency emergency = _mapper.Map <Emergency>(model); var history = _emergencyHistoryDAL .Find(new EmergencyHistoryFilter { EmergencyId = emergency.Id, EmergencyStatus = EmergencyStatus.InEvaluation }); if (history == null) { if (emergency.EmergencyHistories == null) { emergency.EmergencyHistories = new List <EmergencyHistory>(); } emergency.EmergencyHistories.Add(new EmergencyHistory { Date = DateTime.Now, Description = "Ocorrência em Avaliação", Emergency = emergency, EmergencyStatus = emergency.EmergencyStatus, EmployeeGuid = model.EmployeeGuid }); } if ((model?.AddressModel?.Id ?? 0) == 0) { var resultAddress = _addressBLL.Register(model.AddressModel); if (!resultAddress.Success) { return(Result <Emergency> .BuildError(resultAddress.Messages)); } emergency.Address = resultAddress.Model; } else { var resultAddress = _addressValidation.Validate(emergency.Address); if (!resultAddress.Success) { return(Result <Emergency> .BuildError(resultAddress.Messages)); } } foreach (var patientModel in model.PatientModels) { if ((patientModel?.Id ?? 0) == 0) { patientModel.EmergencyId = emergency.Id; var resultPatient = _patientBLL.Register(patientModel); if (!resultPatient.Success) { return(Result <Emergency> .BuildError(resultPatient.Messages)); } } else { var patient = emergency.Patients.FirstOrDefault(d => d.Id == patientModel.Id); patient.EmergencyId = emergency.Id; var resultPatient = _patientValidation.Validate(patient); if (!resultPatient.Success) { return(Result <Emergency> .BuildError(resultPatient.Messages)); } } } var result = _emergencyValidation.Validate(emergency); if (!result.Success) { return(result); } _emergencyDAL.Update(emergency); var resultSave = _emergencyDAL.Save(); if (!resultSave.Success) { return(Result <Emergency> .BuildError(resultSave.Messages)); } return(Result <Emergency> .BuildSuccess(null)); } catch (Exception error) { return(Result <Emergency> .BuildError("Erro ao alterar o registro da ocorrência.", error)); } }