Пример #1
0
        /// <summary>
        /// Update container
        /// </summary>
        /// <param name="input"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task UpdateAsync(UpdateContainerDto input, CancellationToken cancellationToken = default)
        {
            var valuesValidator = GetFileProviderValuesValidator(input.Provider);

            var dict   = input.Items.ToDictionary(x => x.Name, y => y.Value);
            var result = valuesValidator.Validate(dict);

            if (result.Errors.Any())
            {
                throw new AbpValidationException("Create Container validate failed.", result.Errors);
            }


            var container = await FileStoringContainerRepository.GetAsync(input.Id, true);

            if (container == null)
            {
                throw new AbpException($"Could not find Container when update by id:'{input.Id}'.");
            }

            await CheckContainer(container.TenantId, input.Name, container.Id, cancellationToken);

            //Update
            container.Update(input.IsMultiTenant, input.Provider, input.Name, input.Title, input.HttpAccess);

            var deleteItems = new List <FileStoringContainerItem>();

            foreach (var item in container.Items)
            {
                var inputItem = input.Items.FirstOrDefault(x => x.Id == item.Id);
                if (inputItem != null)
                {
                    //Update
                    item.Name  = inputItem.Name;
                    item.Value = inputItem.Value;
                }
                else
                {
                    //Delete
                    deleteItems.Add(item);
                }
            }

            //Remove
            container.Items.RemoveAll(deleteItems);

            //Create
            var createInputItems = input.Items.Where(x => !x.Id.HasValue).ToList();

            foreach (var item in createInputItems)
            {
                var containerItem = new FileStoringContainerItem(GuidGenerator.Create(), item.Name, item.Value, container.Id);
                container.Items.Add(containerItem);
            }
        }
Пример #2
0
        public virtual async Task UpdateAsync(UpdateContainerDto input)
        {
            var keyValuePairs = input.Items.ToDictionary(x => x.Name, y => y.Value);

            ContainerManager.ValidateProviderValues(input.Provider, keyValuePairs);

            var container = await FileStoringContainerRepository.GetAsync(input.Id, true);

            if (container == null)
            {
                throw new AbpException($"Could not find Container when update by id:'{input.Id}'.");
            }

            //Validate name
            await ContainerManager.ValidateNameAsync(container.TenantId, input.Name, container.Id);

            //Update
            container.Update(input.IsMultiTenant, input.Provider, input.Name, input.Title, input.HttpAccess);

            var deleteItems = new List <FileStoringContainerItem>();

            foreach (var item in container.Items)
            {
                var inputItem = input.Items.FirstOrDefault(x => x.Id == item.Id);
                if (inputItem != null)
                {
                    //Update
                    item.Name  = inputItem.Name;
                    item.Value = inputItem.Value;
                }
                else
                {
                    //Delete
                    deleteItems.Add(item);
                }
            }

            //Remove
            container.Items.RemoveAll(deleteItems);

            //Create
            foreach (var item in input.Items)
            {
                var containerItem = new FileStoringContainerItem(GuidGenerator.Create(), item.Name, item.Value, container.Id);
                container.Items.Add(containerItem);
            }
        }
Пример #3
0
 public async Task UpdateAsync([FromBody] UpdateContainerDto input)
 {
     await _containerAppService.UpdateAsync(input);
 }
Пример #4
0
 public async Task UpdateAsync(Guid id, UpdateContainerDto input)
 {
     await _containerAppService.UpdateAsync(id, input);
 }