public Result CancelServiceHistory(ServiceCancellationHistoryModel serviceCancellation) { try { var emergency = _emergencyDAL.Find(new EmergencyFilter { Id = serviceCancellation.EmergencyHistoryModel.EmergencyId }); var serviceHistory = _serviceHistoryDAL.Find(new ServiceHistoryFilter { Id = serviceCancellation.ServiceHistoryModel.Id }); EmergencyHistory emergencyHistory = new EmergencyHistory { Date = serviceCancellation.EmergencyHistoryModel.Date, EmergencyId = serviceCancellation.EmergencyHistoryModel.EmergencyId, EmployeeGuid = serviceCancellation.EmergencyHistoryModel.EmployeeGuid, Description = "Cancelamento de veículo " + serviceCancellation.ServiceHistoryModel.VehicleModel.Codename, EmergencyStatus = emergency.EmergencyStatus }; MedicalDecisionHistory medicalDecision = new MedicalDecisionHistory() { Date = DateTime.Now, EmployeeGuid = serviceCancellation.MedicalDecisionHistoryModel.EmployeeGuid, EmployeeName = serviceCancellation.MedicalDecisionHistoryModel.EmployeeName, EmergencyId = serviceCancellation.MedicalDecisionHistoryModel.EmergencyId, Description = "Cancelamento de veículo " + serviceHistory.Vehicle.Codename, CodeColor = serviceHistory.CodeColor }; serviceHistory.ServiceHistoryStatus = ServiceHistoryStatus.Canceled; var vehicle = _vehicleDAL.Find(new VehicleFilter { Id = serviceHistory.VehicleId }); vehicle.VehicleStatus = VehicleStatus.Cleared; _vehicleDAL.Update(vehicle); _medicalDecisionHistoryDAL.Insert(medicalDecision); _emergencyHistoryDAL.Insert(emergencyHistory); var resultSave = _serviceHistoryDAL.Save(); if (!resultSave.Success) { return(Result <ServiceHistory> .BuildError(resultSave.Messages)); } return(Result <ServiceHistory> .BuildSuccess(null)); } catch (Exception error) { return(Result <ServiceHistory> .BuildError("Erro ao alterar o registro do veículo empenhado na ocorrência.", error)); } }
public override Result <EmergencyRequiredVehicle> Register(EmergencyRequiredVehicleModel model) { try { EmergencyRequiredVehicle emergencyRequiredVehicle = _mapper.Map <EmergencyRequiredVehicle>(model); var result = _emergencyRequiredVehicleValidation.Validate(emergencyRequiredVehicle); if (!result.Success) { return(result); } var emergency = _emergencyDAL.Find(new EmergencyFilter { Id = model.EmergencyId }); if (emergency.EmergencyStatus != EmergencyStatus.Committed) { emergency.EmergencyStatus = EmergencyStatus.InService; _emergencyDAL.Update(emergency); } _emergencyRequiredVehicleDAL.Insert(emergencyRequiredVehicle); MedicalDecisionHistory medicalDecision = _mapper.Map <MedicalDecisionHistory>(model.MedicalDecisionHistoryModel); _medicalDecisionHistoryDAL.Insert(medicalDecision); var resultSave = _emergencyRequiredVehicleDAL.Save(); if (!resultSave.Success) { return(Result <EmergencyRequiredVehicle> .BuildError(resultSave.Messages)); } return(Result <EmergencyRequiredVehicle> .BuildSuccess(null)); } catch (Exception error) { return(Result <EmergencyRequiredVehicle> .BuildError("Erro no momento de registar do veículo requerido para a ocorrência.", error)); } }
public override Result <MedicalDecisionHistory> Register(MedicalDecisionHistoryModel model) { MedicalDecisionHistory history = _mapper.Map <MedicalDecisionHistory>(model); var result = _medicalDecisionValidation.Validate(history); if (!result.Success) { return(result); } _medicalDecisionhistoryDAL.Insert(history); var resultSave = _medicalDecisionhistoryDAL.Save(); if (!resultSave.Success) { return(Result <MedicalDecisionHistory> .BuildError(resultSave.Messages)); } return(Result <MedicalDecisionHistory> .BuildSuccess(history)); }