private async Task <TagFunction> CreateNewTagFunctionAsync(string tagFunctionCode, string registerCode) { var pcsTagFunction = await _tagFunctionApiService.TryGetTagFunctionAsync(_plantProvider.Plant, tagFunctionCode, registerCode); if (pcsTagFunction == null) { return(null); } var tagFunction = new TagFunction(_plantProvider.Plant, tagFunctionCode, pcsTagFunction.Description, registerCode); _tagFunctionRepository.Add(tagFunction); return(tagFunction); }
private async Task CloneTagFunctions(string sourcePlant, string targetPlant) { var originalPlant = _plantProvider.Plant; _plantSetter.SetPlant(sourcePlant); var sourceTagFunctions = await _tagFunctionRepository.GetAllAsync(); var sourceRTs = await _requirementTypeRepository.GetAllAsync(); var sourceRDs = sourceRTs.SelectMany(rt => rt.RequirementDefinitions).ToList(); _plantSetter.SetPlant(originalPlant); var targetTagFunctions = await _tagFunctionRepository.GetAllAsync(); var targetRTs = await _requirementTypeRepository.GetAllAsync(); var targetRDs = targetRTs.SelectMany(rt => rt.RequirementDefinitions).ToList(); foreach (var sourceTagFunction in sourceTagFunctions) { var mainTagFunction = await _tagFunctionApiService.TryGetTagFunctionAsync( targetPlant, sourceTagFunction.Code, sourceTagFunction.RegisterCode); if (mainTagFunction == null) { continue; } var targetTagFunction = targetTagFunctions.SingleOrDefault( t => t.Code == sourceTagFunction.Code && t.RegisterCode == sourceTagFunction.RegisterCode); if (targetTagFunction == null) { targetTagFunction = new TagFunction( targetPlant, sourceTagFunction.Code, sourceTagFunction.Description, sourceTagFunction.RegisterCode); _tagFunctionRepository.Add(targetTagFunction); } CloneRequirements(sourceRDs, sourceTagFunction, targetRDs, targetTagFunction); } }