public override Result <EmergencyRequiredVehicle> Update(EmergencyRequiredVehicleModel model)
        {
            try
            {
                EmergencyRequiredVehicle emergencyRequiredVehicle = _mapper.Map <EmergencyRequiredVehicle>(model);

                var result = _emergencyRequiredVehicleValidation.Validate(emergencyRequiredVehicle);
                if (!result.Success)
                {
                    return(result);
                }

                _emergencyRequiredVehicleDAL.Update(emergencyRequiredVehicle);



                EmergencyHistory emergencyHistory = _mapper.Map <EmergencyHistory>(model.EmergencyHistoryModel);
                _emergencyHistoryDAL.Insert(emergencyHistory);

                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 ao alterar o registro do veículo requerido para a ocorrência.", error));
            }
        }
Exemple #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));
            }
        }
Exemple #3
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));
            }
        }