Example #1
0
        public async Task CreateComponentAsync(int productVersionId, ComponentEditModel component)
        {
            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var exportedTypes = await exportedTypeRepository.GetExportedTypesAsync(productVersionId);

                var existsComponent = await componentRepository.GetComponentAsync(component.TagName);

                var productVersion  = productVersionRepository.QueryByKey(productVersionId);
                var exportedTypeIds = component.ExportedTypeIds.Select(x => Convert.ToInt32(x)).ToArray();
                if (existsComponent == null)
                {
                    var newComponent = new Repository.Model.Component()
                    {
                        Description   = component.Description,
                        ExportedTypes = exportedTypes.Where(x => exportedTypeIds.Contains(x.Id)).ToList(),
                        Name          = component.Name,
                        TagName       = component.TagName
                    };
                    foreach (var exportedType in newComponent.ExportedTypes)
                    {
                        exportedType.Component = newComponent;
                    }
                    newComponent.Versions.Add(new ComponentVersion()
                    {
                        Component      = newComponent,
                        ProductVersion = productVersion
                    });
                    await componentRepository.CreateAsync(newComponent);
                }
                else if (existsComponent.Versions.Any(x => x.ProductVersionId == productVersionId))
                {
                    throw new OperationException("该组件在该版本已存在");
                }
                else
                {
                    existsComponent.ExportedTypes = exportedTypes.Where(x => exportedTypeIds.Contains(x.Id)).ToList();
                    foreach (var exportedType in existsComponent.ExportedTypes)
                    {
                        exportedType.Component = existsComponent;
                    }
                    existsComponent.Name = component.Name;
                    existsComponent.Versions.Add(new ComponentVersion()
                    {
                        Component      = existsComponent,
                        ProductVersion = productVersion
                    });
                    await productVersionRepository.SaveChangesAsync();
                }
                scope.Complete();
            }
        }
Example #2
0
        protected async Task EditAsync(object arg)
        {
            if (!form.IsValid())
            {
                return;
            }
            var adminComponentModel = arg as AdminComponentModel;
            var componentEditModel  = new ComponentEditModel()
            {
                Description     = adminComponentModel.Description,
                ExportedTypeIds = (await ComponentService.GetComponentExportedTypesAsync(adminComponentModel.Id, SelectedVersionId.Value)).Select(x => x.Id.ToString()).ToList(),
                Name            = adminComponentModel.Name,
                TagName         = adminComponentModel.TagName
            };
            var parameters = new Dictionary <string, object>();

            parameters.Add(nameof(ComponentEdit.ProductId), productId);
            parameters.Add(nameof(ComponentEdit.ProductVersionId), SelectedVersionId.Value);
            parameters.Add(nameof(ComponentEdit.ComponentId), adminComponentModel.Id);
            parameters.Add(nameof(ComponentEdit.Component), componentEditModel);
            await DialogService.ShowDialogAsync <ComponentEdit>("更新组件", 800, parameters);

            Query();
        }
Example #3
0
        public async Task UpdateComponentAsync(int productVersionId, int componentId, ComponentEditModel component)
        {
            using (var scope = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
            {
                var existsComponent = await componentRepository.GetComponentAsync(componentId);

                if (existsComponent == null)
                {
                    throw new OperationException("组件不存在");
                }
                var exportedTypes = await exportedTypeRepository.GetExportedTypesAsync(productVersionId);

                var productVersion = await productVersionRepository.GetComponentsAsync(productVersionId);

                var exportedTypeIds = component.ExportedTypeIds.Select(x => Convert.ToInt32(x)).ToArray();
                if (productVersion.ComponentVersions.Any(x => x.Component.Id != componentId && (x.Component.Name == component.Name || x.Component.TagName == component.TagName)))
                {
                    throw new OperationException("该组件名称或调用标签在该版本已存在");
                }
                existsComponent.ExportedTypes = exportedTypes.Where(x => exportedTypeIds.Contains(x.Id)).ToList();
                foreach (var exportedType in existsComponent.ExportedTypes)
                {
                    exportedType.Component = existsComponent;
                }
                existsComponent.Name = component.Name;
                await productVersionRepository.SaveChangesAsync();

                scope.Complete();
            }
        }