/// <summary> /// update customer vehicle with the lastest connection status /// </summary> /// <param name="customerVehiclesEventMessage">current vehicle message</param> /// <returns></returns> public async Task UpdateCustomerVehicleStatus(CustomerVehicleChangedIntegrationEvent customerVehiclesEventMessage) { try { //get customer vehicle row var customerVehicleEntity = customerVehiclesRepo.GetAll() .Where(c => c.VehicleId == customerVehiclesEventMessage.VIN && c.CustomerId == customerVehiclesEventMessage.CustomerId && c.RegNo == customerVehiclesEventMessage.RegNo).FirstOrDefault(); if (customerVehicleEntity == null) { _logger.LogError($"Invalid customer vehicle with customerID: {customerVehiclesEventMessage.CustomerId} " + $"- vehicleId: {customerVehiclesEventMessage.VIN} - registeration#: {customerVehiclesEventMessage.RegNo} "); throw new Exception("Invalid Message"); } //update required customer vehicle (connection status & last modification date) customerVehicleEntity.IsConnectedStatus = customerVehiclesEventMessage.ConnectionStatus; customerVehicleEntity.LastStatusModificationTime = customerVehiclesEventMessage.ModificationStatus; customerVehiclesRepo.Update(customerVehicleEntity); await customerVehiclesRepo.SaveChangesAsync(); } catch (Exception ex) { _logger.LogError(ex.Message); throw ex; } }
public static CustomerVehicle GetCustomerVehicleEntity(CustomerVehicleChangedIntegrationEvent customerVehicleEventMessage) { return(Mapping.Mapper.Map <CustomerVehicleChangedIntegrationEvent, CustomerVehicle>(customerVehicleEventMessage));; }