/// <summary>
        /// Updates spcific vehcile status
        /// </summary>
        /// <param name="vehicleId">The vehicle id to update its status</param>
        /// <param name="status">The new vehicle status</param>
        /// <returns>True if the vehcle status is updated successfully, false otherwise</returns>
        public bool UpdateVehicleStatus(string vehicleId, VehicleStatusEnum status)
        {
            try
            {
                var vehicle = _vehicleRepository.GetVehicleById(vehicleId);

                if (vehicle == null)
                {
                    return(false);
                }
                vehicle.VehicleStatus = (int)status;

                _vehicleRepository.UpdateVehicleStatus(vehicle);

                return(true);
            }
            catch (Exception ex)
            {
                //TODO: log the exception
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sends checking signal to vehicle and enqueue the result using RabbitMQ.
        /// </summary>
        /// <param name="status">Status Enum value.</param>
        /// <exception cref="NullReferenceException"></exception>
        /// /// <exception cref="ObjectDisposedException"></exception>
        /// /// <exception cref="NotSupportedException"></exception>
        /// /// <exception cref="Exception"></exception>
        public List <VehicleTransModel> PingVehicleInQueue(VehicleStatusEnum status)
        {
            var vehicleTransList = new List <VehicleTransModel>();

            try
            {
                // 1- ping vehicles of this customer/all and get signal statuses back.
                var vehiclesSignalStatuses = _genericsVehicleDbContextRepo.GetAll().Where(v => v.CustomerId != null);

                // 2- post to DB.
                foreach (var v in vehiclesSignalStatuses)
                {
                    var vse = GenerateSignal();
                    _genericsVehicleTransDbContextRepo.Add(new VehicleStatusTrans
                    {
                        PingTime  = DateTime.Now,
                        Status    = vse.ToString(),
                        VehicleId = v.Id
                    });
                    _genericsVehicleTransDbContextRepo.SaveChanges();
                    vehicleTransList.Add(new VehicleTransModel
                    {
                        VehicleId   = v.Id,
                        VehicleCode = v.Code,
                        VehicleRegistrationNumber = v.RegNumber,
                        CustomerId   = v.CustomerId,
                        CustomerName = _genericsCustomerDbContextRepo.Find(v.CustomerId).Name,
                        Status       = vse.ToString()
                    });
                }

                var vehicleTransModels = status.ToString() != "-1"
                    ? vehicleTransList.Where(vt => vt.Status.ToString() == status.ToString()).ToList()
                    : vehicleTransList;

                // Publish list to EventBus queue.
                _serviceBusQueue.Publish("PingSignal_VehicleStatusTrans", vehicleTransModels);

                return(vehicleTransModels);
            }
            catch (NullReferenceException nullExp)
            {
                _logger.Log(LogLevel.Error, nullExp.Message, nullExp.Source);
                throw;
            }
            catch (ObjectDisposedException objectDisponseExp)
            {
                _logger.Log(LogLevel.Error, objectDisponseExp.Message, objectDisponseExp.Source);
                throw;
            }
            catch (NotSupportedException notSuppExp)
            {
                _logger.Log(LogLevel.Error, notSuppExp.Message, notSuppExp.Source);
                throw;
            }
            catch (Exception exp)
            {
                _logger.Log(LogLevel.Error, exp.Message, exp.Source);
                throw;
            }
        }
 /// <summary>
 /// Returns vehicles by status
 /// </summary>
 /// <param name="customerId"> Vehicle status</param>
 /// <returns>Returns list of vehicles</returns>
 public List <Vehicle> GetVehiclesByStatus(VehicleStatusEnum status)
 {
     return(_vehicleRepository.GetVehiclesByStatus((int)status).ToList());
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns vehicles by status
 /// </summary>
 /// <param name="customerId"> Vehicle status</param>
 /// <returns>Returns list of vehicles</returns>
 public List <Vehicle> GetByStatus(VehicleStatusEnum status)
 {
     return(_repository.Query().Include(m => m.Customer).Include(m => m.VehicleStatus).Select().Where(v => v.VehicleStatusId == (int)status).ToList());
 }