// TODO: Move the method to Simulations.cs  e.g. this.simulations.AddDevicesAsync
        private async Task AddDeviceToSimulationRecordAsync(Simulation simulation, string deviceId, string modelId)
        {
            DeviceModelRef deviceModel = new DeviceModelRef();

            deviceModel.Id = modelId;
            CustomDeviceRef customDevice = new CustomDeviceRef();

            customDevice.DeviceModel = deviceModel;
            customDevice.DeviceId    = deviceId;

            try
            {
                if (!simulation.CustomDevices.ToList().Contains(customDevice))
                {
                    this.log.Info("Update simulation record");
                    simulation.CustomDevices.Add(customDevice);
                    await this.simulations.UpsertAsync(simulation);
                }
                else
                {
                    this.log.Debug("Device already exists in simulation record");
                }
            }
            catch (Exception e)
            {
                this.log.Error("Error while adding new device to simulation record", () => new { e });
                throw new Exception("Error while adding a new device to simulation record");
            }
        }
        /// <summary>Map a service model to the corresponding API model</summary>
        public SimulationApiModel(Simulation simulation)
        {
            this.DeviceModels = new List <DeviceModelRef>();

            this.Etag    = simulation.Etag;
            this.Id      = simulation.Id;
            this.Enabled = simulation.Enabled;

            foreach (var x in simulation.DeviceModels)
            {
                var dt = new DeviceModelRef
                {
                    Id    = x.Id,
                    Count = x.Count
                };
                this.DeviceModels.Add(dt);
            }

            this.version  = simulation.Version;
            this.created  = simulation.Created;
            this.modified = simulation.Modified;
        }