public async Task <ApiResult <object> > CreateAppAsync(AddAppConfig add)
        {
            var data = await _appConfigService.CreateAppAsync(add);

            return(new ApiResult <object>()
            {
                Code = (int)ApiResultCode.Success,
                Data = data.Result,
                Message = data.Message
            });
        }
Exemple #2
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, "应用创建成功"));
        }
Exemple #3
0
 public async Task <ApiResult <object> > ReportAsync([FromBody] AddAppConfig addAppConfig)
 {
     return(await _appConfigApplication.CreateAppAsync(addAppConfig));
 }