public override Result <TeamMember> Register(TeamMemberModel model)
        {
            try
            {
                TeamMember teamMember = _mapper.Map <TeamMember>(model);

                var result = _teamMemberValidation.Validate(teamMember);
                if (!result.Success)
                {
                    return(result);
                }

                _teamMemberDAL.Insert(teamMember);

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

                return(Result <TeamMember> .BuildSuccess(teamMember));
            }
            catch (Exception error)
            {
                return(Result <TeamMember> .BuildError("Erro no momento de registar do integrante do veículo.", 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));
            }
        }