Пример #1
0
        public async Task <ResultModel> EditConfigurationItem(EditConfigurationItemModel model)
        {
            try
            {
                await configurationItemService.EditConfigurationItemAsync(model);

                return(ResultModel.Success("修改成功"));
            }
            catch (AspectInvocationException ex)
            {
                return(ResultModel.Fail(ex.InnerException?.Message));
            }
            catch (MateralConfigCenterException ex)
            {
                return(ResultModel.Fail(ex.Message));
            }
        }
        public async Task EditConfigurationItemAsync(EditConfigurationItemModel model)
        {
            if (await _configurationItemRepository.ExistedAsync(m => m.Key.Equals(model.Key) && m.NamespaceID == model.NamespaceID && m.ProjectID == model.ProjectID && m.ID != model.ID))
            {
                throw new MateralConfigCenterException("Key已存在");
            }
            ConfigurationItem configurationItemFromDb = await _configurationItemRepository.FirstOrDefaultAsync(model.ID);

            if (configurationItemFromDb == null)
            {
                throw new MateralConfigCenterException("配置项不存在");
            }
            model.CopyProperties(configurationItemFromDb);
            configurationItemFromDb.UpdateTime = DateTime.Now;
            _protalServerUnitOfWork.RegisterEdit(configurationItemFromDb);
            await _protalServerUnitOfWork.CommitAsync();
        }