public override Result <EmergencyRequiredVehicleModel> Find(IFilter filter)
 {
     try
     {
         EmergencyRequiredVehicle      emergencyData = _emergencyRequiredVehicleDAL.Find((EmergencyRequiredVehicleFilter)filter);
         EmergencyRequiredVehicleModel emergencyRequiredVehicleModel = _mapper.Map <EmergencyRequiredVehicleModel>(emergencyData);
         return(Result <EmergencyRequiredVehicleModel> .BuildSuccess(emergencyRequiredVehicleModel));
     }
     catch (Exception error)
     {
         return(Result <EmergencyRequiredVehicleModel> .BuildError("Erro ao localizar o registro do veículo requerido para a ocorrência.", error));
     }
 }
コード例 #2
0
        public Result SendVehicle(ServiceHistoryModel serviceHistoryModel)
        {
            try
            {
                var vehicleRequerid = _emergencyRequiredVehicleDAL.Find(new EmergencyRequiredVehicleFilter {
                    Id = serviceHistoryModel.EmergencyRequiredVehicleId
                });
                vehicleRequerid.Status = VehicleRequiredStatus.Committed;
                vehicleRequerid.Emergency.EmergencyStatus = EmergencyStatus.Committed;
                _emergencyRequiredVehicleDAL.Update(vehicleRequerid);

                var vehicle = _vehicleDAL.Find(new VehicleFilter {
                    Id = serviceHistoryModel.VehicleId
                });
                vehicle.VehicleStatus = VehicleStatus.InService;
                _vehicleDAL.Update(vehicle);

                var serviceHistory = new ServiceHistory
                {
                    EmergencyId          = vehicleRequerid.EmergencyId,
                    Description          = "Veículo empenhado",
                    Date                 = serviceHistoryModel.Date,
                    ServiceHistoryStatus = ServiceHistoryStatus.InProgress,
                    VehicleId            = serviceHistoryModel.VehicleId,
                    CodeColor            = vehicleRequerid.CodeColor
                };
                _serviceHistoryDAL.Insert(serviceHistory);

                var members = _memberDAL.FindAll(new MemberFilter {
                    EmployeeStatus = EmployeeStatus.Working, VehicleId = vehicle.Id
                });
                members.ForEach(d =>
                {
                    var teamMember = new TeamMember
                    {
                        MemberId       = d.Id,
                        ServiceHistory = serviceHistory
                    };
                    _teamMemberDAL.Insert(teamMember);
                });

                var resultSave = _serviceHistoryDAL.Save();

                return(resultSave);
            }
            catch (Exception error)
            {
                return(Result.BuildError("Erro ao enviar veículo, favor tente novamente.", error));
            }
        }