Beispiel #1
0
        public async Task AddAsyncTest()
        {
            var id     = Guid.NewGuid().ToString();
            var source = new Data.Entity.App
            {
                Id         = id,
                Name       = "xx",
                Secret     = "sec",
                CreateTime = DateTime.Now,
                UpdateTime = DateTime.Now,
                Enabled    = true
            };
            var result = await service.AddAsync(source);

            var app = fsq.Select <App>(new
            {
                Id = id
            }).ToOne();

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

            Assert.AreEqual(source.Id, app.Id);
            Assert.AreEqual(source.Name, app.Name);
            Assert.AreEqual(source.Secret, app.Secret);
            // Assert.AreEqual(source.CreateTime, app.CreateTime);
            //  Assert.AreEqual(source.UpdateTime, app.UpdateTime);
            Assert.AreEqual(source.Enabled, app.Enabled);
        }
Beispiel #2
0
        public async Task <IActionResult> Add([FromBody] AppVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var oldApp = await _appService.GetAsync(model.Id);

            if (oldApp != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "应用Id已存在,请重新输入。"
                }));
            }

            var app = new App();

            app.Id         = model.Id;
            app.Name       = model.Name;
            app.Secret     = model.Secret;
            app.Enabled    = model.Enabled;
            app.CreateTime = DateTime.Now;
            app.UpdateTime = null;
            app.Type       = model.Inheritanced ? AppType.Inheritance : AppType.PRIVATE;

            var inheritanceApps = new List <AppInheritanced>();

            if (!model.Inheritanced && model.inheritancedApps != null)
            {
                var sort = 0;
                model.inheritancedApps.ForEach(appId =>
                {
                    inheritanceApps.Add(new AppInheritanced
                    {
                        Id                = Guid.NewGuid().ToString("N"),
                        AppId             = app.Id,
                        InheritancedAppId = appId,
                        Sort              = sort++
                    });
                });
            }

            var result = await _appService.AddAsync(app, inheritanceApps);

            if (result)
            {
                TinyEventBus.Instance.Fire(EventKeys.ADD_APP_SUCCESS, app);
            }

            return(Json(new
            {
                data = app,
                success = result,
                message = !result ? "新建应用失败,请查看错误日志" : ""
            }));
        }
        public async Task <IActionResult> Add([FromBody] AppVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var oldApp = await _appService.GetAsync(model.Id);

            if (oldApp != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "应用Id已存在,请重新输入。"
                }));
            }

            var app = new App();

            app.Id         = model.Id;
            app.Name       = model.Name;
            app.Secret     = model.Secret;
            app.Enabled    = model.Enabled;
            app.CreateTime = DateTime.Now;
            app.UpdateTime = null;

            var result = await _appService.AddAsync(app);

            if (result)
            {
                await _sysLogService.AddSysLogAsync(new SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = SysLogType.Normal,
                    LogText = $"新增应用【AppId:{app.Id}】【AppName:{app.Name}】"
                });
            }

            return(Json(new
            {
                success = result,
                message = !result ? "新建应用失败,请查看错误日志" : ""
            }));
        }
        public async Task <MessageModel <bool> > Add([FromBody] AppInputDto model)
        {
            MessageModel <bool> response = new MessageModel <bool>();

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            var oldApp = await _appService.GetAsync(model.Id);

            if (oldApp != null)
            {
                return(new MessageModel <bool>()
                {
                    success = false,
                    msg = "应用Id已存在,请重新输入。"
                });
            }
            var app = new AppEntity();

            app.Id         = model.Id;
            app.Name       = model.Name;
            app.Enabled    = model.Enabled;
            app.CreateTime = DateTime.Now;
            app.UpdateTime = null;

            var result = await _appService.AddAsync(app);

            if (result)
            {
                response.success = true;
                response.msg     = "新增成功";
                return(response);
            }
            return(new MessageModel <bool>()
            {
                success = false,
                msg = !result ? "新建应用失败,请查看错误日志" : ""
            });
        }
Beispiel #5
0
        public async Task <IActionResult> Add([FromBody] AppVM model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            var oldApp = await _appService.GetAsync(model.Id);

            if (oldApp != null)
            {
                return(Json(new
                {
                    success = false,
                    message = "应用Id已存在,请重新输入。"
                }));
            }

            var app = new App();

            app.Id         = model.Id;
            app.Name       = model.Name;
            app.Secret     = model.Secret;
            app.Enabled    = model.Enabled;
            app.CreateTime = DateTime.Now;
            app.UpdateTime = null;
            app.Type       = model.Inheritanced ? AppType.Inheritance : AppType.PRIVATE;

            var inheritanceApps = new List <AppInheritanced>();

            if (!model.Inheritanced && model.inheritancedApps != null)
            {
                var sort = 0;
                model.inheritancedApps.ForEach(a => {
                    inheritanceApps.Add(new AppInheritanced
                    {
                        Id                = Guid.NewGuid().ToString("N"),
                        AppId             = app.Id,
                        InheritancedAppId = a.Id,
                        Sort              = sort++
                    });
                });
            }

            var result = await _appService.AddAsync(app, inheritanceApps);

            if (result)
            {
                await _sysLogService.AddSysLogAsync(new SysLog
                {
                    LogTime = DateTime.Now,
                    LogType = SysLogType.Normal,
                    LogText = $"新增应用【AppId:{app.Id}】【AppName:{app.Name}】"
                });
            }

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