public async Task ImportControllerProfileAsync(Creation creation, string controllerProfileFilename) { using (await _asyncLock.LockAsync()) { var controllerProfileJson = await File.ReadAllTextAsync(controllerProfileFilename); var controllerProfile = JsonConvert.DeserializeObject <ControllerProfile>(controllerProfileJson); controllerProfile.Creation = null; controllerProfile.CreationId = 0; var controllerProfileName = controllerProfile.Name; if (!IsControllerProfileNameAvailable(creation, controllerProfileName)) { for (var suffix = 1; suffix < 1000; suffix++) { var newControllerProfileName = $"{controllerProfileName} {suffix}"; if (IsControllerProfileNameAvailable(creation, newControllerProfileName)) { controllerProfileName = newControllerProfileName; break; } } } controllerProfile.Name = controllerProfileName; await _creationRepository.InsertControllerProfileAsync(creation, controllerProfile); } }
public async Task<ControllerProfile> AddControllerProfileAsync(Creation creation, string controllerProfileName) { using (await _asyncLock.LockAsync()) { var controllerProfile = new ControllerProfile { Name = controllerProfileName }; await _creationRepository.InsertControllerProfileAsync(creation, controllerProfile); return controllerProfile; } }