Ejemplo n.º 1
0
 public override Result <EmergencyModel> Find(IFilter filter)
 {
     try
     {
         Emergency      emergency      = _emergencyDAL.Find((EmergencyFilter)filter);
         EmergencyModel emergencyModel = _mapper.Map <EmergencyModel>(emergency);
         return(Result <EmergencyModel> .BuildSuccess(emergencyModel));
     }
     catch (Exception error)
     {
         return(Result <EmergencyModel> .BuildError("Erro ao localizar o registro da emergência.", error));
     }
 }
Ejemplo n.º 2
0
        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));
            }
        }
Ejemplo n.º 4
0
        public override Result <EmergencyHistory> Register(EmergencyHistoryModel model)
        {
            try
            {
                EmergencyHistory emergencyHistory = _mapper.Map <EmergencyHistory>(model);

                var emergency = _emergencyDAL.Find(new EmergencyFilter {
                    Id = model.EmergencyId
                });
                emergency.EmergencyStatus = model.EmergencyStatus;
                _emergencyDAL.Update(emergency);

                //var resultEmergency = _emergencyBLL.SimpleUpdate(model.EmergencyModel);
                //if (!resultEmergency.Success)
                //    return Result<EmergencyHistory>.BuildError(resultEmergency.Messages);

                var result = _emergencyHistoryValidation.Validate(emergencyHistory);
                if (!result.Success)
                {
                    return(result);
                }

                _emergencyHistoryDAL.Insert(emergencyHistory);

                var resultSave = _emergencyHistoryDAL.Save();
                if (!resultSave.Success)
                {
                    return(Result <EmergencyHistory> .BuildError(resultSave.Messages));
                }

                return(Result <EmergencyHistory> .BuildSuccess(null));
            }
            catch (Exception error)
            {
                return(Result <EmergencyHistory> .BuildError("Erro no momento de registar o histórico de ocorrência.", error));
            }
        }