Example #1
0
        public void Build()
        {
            // Arrange
            var expected = new AppConfigViewModel
            {
                WebApiUrl        = _settings.WebApiUrl,
                DefaultSortOrder = _settings.DefaultSortOrder,
                DefaultDescSort  = _settings.DefaultDescSort
            };

            // Act
            var result = _target.Build();

            // Assert
            result.Should().BeEquivalentTo(expected);
        }
Example #2
0
        public async Task <int> AddOrUpdateConfig(AppConfigViewModel model)
        {
            var obj = await UnitWork.ManuDbContext.PurvAppConfigs.FindAsync(model.ID);

            if (obj == null)
            {
                UnitWork.ManuDbContext.PurvAppConfigs.Add(new Purv_AppConfig()
                {
                    Description = model.Description,
                    Name        = model.Name
                });
            }
            else
            {
                obj.Name        = model.Name;
                obj.Description = model.Description;
            }
            return(await UnitWork.Commit());
        }
Example #3
0
        public async Task <ServiceInvokeResult <AppConfigViewModel> > CreateAppAsync(AddAppConfig appConfig)
        {
            var existAppInfo = await _appConfigRepository.QueryAsQueryable(a => a.AppCode == appConfig.AppCode).FirstAsync();

            if (existAppInfo != null)
            {
                return(PrintInvokeResult(new AppConfigViewModel()
                {
                    AppId = existAppInfo.AppId, AppKey = existAppInfo.AppKey
                }, "此应用已申请"));
            }

            var maxAppId = await _appConfigRepository.QueryAsQueryable(a => true).OrderBy(a => a.AppId, SqlSugar.OrderByType.Desc).Select(a => a.AppId).FirstAsync();

            var newAppId = maxAppId == 0 ? 1000 : maxAppId + 1;
            var appKey   = SecretKeyHelper.GetRandomKey();
            var unixTime = DateTime.Now.ToUnixTime(true);
            var app      = new AppConfig(newAppId, appConfig.AppCode, appKey, appConfig.AppName, unixTime);

            //领域模型验证
            var validationResult = new AppConfigValidation().Validate(app);

            if (!validationResult.IsValid)
            {
                return(PrintInvokeResult <AppConfigViewModel>(null, "模型检验失败"));
            }

            await _appConfigRepository.Add(app);

            //写入缓存
            var key             = string.Format(CacheKeyConstant.AppConfig, newAppId);
            var cacheingCommand = new CacheingCommand(key, app, 120);
            await _bus.SendCommand(cacheingCommand);

            var viewModel = new AppConfigViewModel()
            {
                AppId = newAppId, AppKey = appKey
            };

            return(PrintInvokeResult(viewModel, "应用创建成功"));
        }
        public async Task <IActionResult> AppConfig()
        {
            AppConfigViewModel model = await _demoService.AccessAppConfig();

            return(View(model));
        }