Exemplo n.º 1
0
        public async Task <IActionResult> Add([FromBody] ConfigVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var app = await _appService.GetAsync(model.AppId);

            if (app == null)
            {
                return(Json(new
                {
                    success = false,
                    message = $"应用({model.AppId})不存在。"
                }));
            }

            var oldConfig = await _configService.GetByAppIdKey(model.AppId, model.Group, model.Key);

            if (oldConfig != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "配置已存在,请更改输入的信息。"
                }));
            }

            var config = new Config();

            config.Id           = string.IsNullOrEmpty(config.Id) ? Guid.NewGuid().ToString("N") : config.Id;
            config.Key          = model.Key;
            config.AppId        = model.AppId;
            config.Description  = model.Description;
            config.Value        = model.Value;
            config.Group        = model.Group;
            config.Status       = ConfigStatus.Enabled;
            config.CreateTime   = DateTime.Now;
            config.UpdateTime   = null;
            config.OnlineStatus = OnlineStatus.WaitPublish;

            var result = await _configService.AddAsync(config);

            if (result)
            {
                dynamic param = new ExpandoObject();
                param.config   = config;
                param.userName = this.GetCurrentUserName();
                TinyEventBus.Instance.Fire(EventKeys.ADD_CONFIG_SUCCESS, param);
            }

            return(Json(new
            {
                success = result,
                message = !result ? "新建配置失败,请查看错误日志" : "",
                data = config
            }));
        }
Exemplo n.º 2
0
        public async Task <ApiResult> Add([FromBody] ConfigInput input)
        {
            var model = await _configService.GetModelAsync(d => d.EnName.Equals(input.EnName));

            if (model.Id > 0)
            {
                throw new FriendlyException("英文名称已存在");
            }
            var modelInput = _mapper.Map <Config>(input);
            var res        = await _configService.AddAsync(modelInput);

            return(new ApiResult(data: res));
        }
        public async Task AddAsyncTest()
        {
            var id     = Guid.NewGuid().ToString();
            var source = new Config
            {
                AppId        = "001",
                Id           = id,
                Group        = "g",
                Key          = "k",
                Value        = "v",
                Description  = "d",
                CreateTime   = DateTime.Now,
                UpdateTime   = DateTime.Now,
                Status       = ConfigStatus.Deleted,
                OnlineStatus = OnlineStatus.Online
            };

            var result = await service.AddAsync(source);

            Assert.IsTrue(result);
            var config = fsq.Select <Config>(new
            {
                Id = id
            }).ToOne();

            Assert.IsTrue(result);
            Assert.IsNotNull(config);

            Assert.AreEqual(source.Id, config.Id);
            Assert.AreEqual(source.Group, config.Group);
            Assert.AreEqual(source.Key, config.Key);
            Assert.AreEqual(source.Value, config.Value);
            Assert.AreEqual(source.Description, config.Description);
            Assert.AreEqual(source.AppId, config.AppId);
            //  Assert.AreEqual(source.CreateTime, config.CreateTime);
            // Assert.AreEqual(source.UpdateTime, config.UpdateTime);
            Assert.AreEqual(source.Status, config.Status);
            Assert.AreEqual(source.OnlineStatus, config.OnlineStatus);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Add([FromBody] ConfigVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var oldConfig = await _configService.GetByAppIdKey(model.AppId, model.Group, model.Key);

            if (oldConfig != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "配置已存在,请更改输入的信息。"
                }));
            }

            var config = new Config();

            config.Id           = Guid.NewGuid().ToString("N");
            config.Key          = model.Key;
            config.AppId        = model.AppId;
            config.Description  = model.Description;
            config.Value        = model.Value;
            config.Group        = model.Group;
            config.Status       = ConfigStatus.Enabled;
            config.CreateTime   = DateTime.Now;
            config.UpdateTime   = null;
            config.OnlineStatus = OnlineStatus.WaitPublish;

            var result = await _configService.AddAsync(config);

            if (result)
            {
                //add syslog
                await _sysLogService.AddSysLogSync(new SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = SysLogType.Normal,
                    AppId   = config.AppId,
                    LogText = $"新增配置【Key:{config.Key}】【Value:{config.Value}】【Group:{config.Group}】【AppId:{config.AppId}】"
                });

                //add modify log
                await _modifyLogService.AddAsync(new ModifyLog
                {
                    Id         = Guid.NewGuid().ToString("N"),
                    ConfigId   = config.Id,
                    Key        = config.Key,
                    Group      = config.Group,
                    Value      = config.Value,
                    ModifyTime = config.CreateTime
                });
            }

            return(Json(new
            {
                success = result,
                message = !result ? "新建配置失败,请查看错误日志" : ""
            }));
        }