public async Task <bool> TryToStartDevicesDeletionAsync(string simulationId, IDevices devices) { // Fetch latest record var simulation = await this.GetAsync(simulationId); if (!simulation.DevicesDeletionStarted) { try { Dictionary <string, List <string> > deviceList = this.GetDeviceIdsByModel(simulation); var deviceIds = deviceList.SelectMany(x => x.Value); this.log.Info("Deleting devices...", () => new { simulationId }); simulation.DeviceDeletionJobId = await devices.DeleteListUsingJobsAsync(deviceIds); simulation.DevicesDeletionStarted = true; this.log.Info("Import job created for bulk device deletion", () => new { simulationId, simulation.DeviceCreationJobId }); await this.SaveAsync(simulation, simulation.ETag); } catch (Exception e) { this.log.Error("Failed to create bulk-device-deletion job", e); return(false); } } return(true); }