Esempio n. 1
0
        public string GetModelStr(string ikey)
        {
            StringBuilder   resultStr = new StringBuilder("");
            AppNavItemModel model     = manager.GetOneModel(new AppNavItemCriteria()
            {
                Ikey = Convert.ToInt32(ikey)
            });

            if (model != null)
            {
                resultStr.Append(GetNotNullString(model.ItemId) + "<*>");
                resultStr.Append(GetNotNullString(model.Text) + "<*>");
                resultStr.Append(GetNotNullString(model.ToolTip) + "<*>");
                resultStr.Append(GetNotNullString(model.NavigateUrl) + "<*>");
                resultStr.Append(GetNotNullString(model.Target) + "<*>");
                resultStr.Append(GetVisible(model.Visible) + "<*>");
                resultStr.Append(model.VisibleIndex + "<*>");
                resultStr.Append(GetNotNullString(model.ImageUrl) + "<*>");
                resultStr.Append(GetModuleName(model.ModuleId) + "<*>");
                resultStr.Append(GetNotNullString(model.AssemblyName) + "<*>");
                resultStr.Append(GetNotNullString(model.ClassName) + "<*>");
                resultStr.Append((model.Active?"有效":"無效") + "<*>");
                resultStr.Append(GetNotNullString(model.RoleIds) + "<*>");
                resultStr.Append(GetNotNullString(manager.GetUser(model.Creator)) + "<*>");
                resultStr.Append(model.CreateTime == DateTime.MinValue?"0":model.CreateTime.ToString() + "<*>");
                resultStr.Append(GetNotNullString(manager.GetUser(model.Updator)) + "<*>");
                resultStr.Append(model.UpdateTime == DateTime.MinValue ? "0" : model.UpdateTime.ToString());

                return(resultStr.ToString());
            }
            return("NoModel");
        }
Esempio n. 2
0
 public void UpdateModel(AppNavItemModel model)
 {
     try
     {
         model.Updator = AppUser.Ikey;
         manager.UpdateModel(model);
     }
     catch (Exception exc)
     {
         // throw GetError(exc);
     }
 }
Esempio n. 3
0
 public void DeleteModel(string ikey)
 {
     try
     {
         AppNavItemModel model = new AppNavItemModel();
         model.Ikey = Convert.ToInt32(ikey);
         manager.DeleteModel(model);
     }
     catch (Exception exc)
     {
         // throw GetError(exc);
     }
 }
Esempio n. 4
0
        public async Task <ActionResult <AppNavItemModel> > Create(
            [FromBody] AppNavItemModel model
            )
        {
            try {
                await repository.SaveAsync(model, User.Identity.Name);

                return(model);
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not save {model.ToJson()} to app_nav_items.");
                return(this.InternalServerError(ex));
            }
        }
Esempio n. 5
0
        public void AddModel(AppNavItemModel model)
        {
            try
            {
                return;

                model.Creator = AppUser.Ikey;
                manager.AddModel(model);
                RemoveCache();
            }
            catch (Exception exc)
            {
                // throw GetError(exc);
            }
        }
Esempio n. 6
0
        public async Task _02_CanDoSoftDelete()
        {
            var entity = new AppNavItemModel {
                Title    = "Test Item",
                Tooltip  = "Test Nav item",
                Icon     = null,
                Url      = "/test",
                ParentId = "0",
                Sequence = 0
            };
            await Target.SaveAsync(entity);

            Assert.IsNotEmpty(entity.Id);
            await Target.DeleteAsync(long.Parse(entity.Id));

            entity = await Target.GetByIdAsync(long.Parse(entity.Id));

            Assert.IsNull(entity);
        }
Esempio n. 7
0
        public async Task <ActionResult <AppNavItemModel> > Update(
            [FromRoute] long id,
            [FromBody] AppNavItemModel model
            )
        {
            try {
                var exists = await repository.ExistAsync(id);

                if (!exists)
                {
                    return(NotFound());
                }
                model.Id = id.ToString();
                await repository.UpdateAsync(id, model, User.Identity.Name);

                return(model);
            }
            catch (Exception ex) {
                logger.LogError(ex, $"Can not update app_nav_items by {id} with {model.ToJson()} .");
                return(this.InternalServerError(ex));
            }
        }
Esempio n. 8
0
    private async Task CreateSystemMenuAsync(string userName, string adminRoleName, string anonymousRoleName)
    {
        var repo = ServiceProvider.GetService <IAppNavItemRepository>();

        if (await repo.CountAllAsync() > 0)
        {
            return;
        }
        // 根应用
        var rootNavItem = new AppNavItemModel {
            Title    = ".NET Core App",
            Icon     = "bi/app-indicator",
            Url      = "/",
            Sequence = 0,
            Roles    = new [] { adminRoleName, anonymousRoleName }
        };
        await repo.SaveAsync(rootNavItem, userName);

        Assert.IsNotEmpty(rootNavItem.Id);
        // 首页
        var homeItem = new AppNavItemModel {
            ParentId = rootNavItem.Id,
            Title    = "首页",
            Url      = "/home",
            Sequence = 1,
            Roles    = new [] { adminRoleName, anonymousRoleName }
        };
        await repo.SaveAsync(homeItem, userName);

        Assert.IsNotEmpty(homeItem.Id);
        // 管理
        var adminItem = new AppNavItemModel {
            ParentId = rootNavItem.Id,
            Title    = "管理",
            Url      = "/admin",
            Sequence = 2,
            Roles    = new [] { adminRoleName }
        };
        await repo.SaveAsync(adminItem, userName);

        Assert.IsNotEmpty(adminItem.Id);
        // 关于
        var aboutItem = new AppNavItemModel {
            ParentId = rootNavItem.Id,
            Title    = "关于",
            Url      = "/about",
            Sequence = 3,
            Roles    = new [] { adminRoleName, anonymousRoleName }
        };
        await repo.SaveAsync(aboutItem, userName);

        Assert.IsNotEmpty(aboutItem.Id);
        // 导航管理
        var menuManageItem = new AppNavItemModel {
            ParentId = adminItem.Id,
            Title    = "导航菜单",
            Icon     = "bi/compass",
            Url      = "/admin/nav-items",
            Sequence = 1,
            Roles    = new [] { adminRoleName }
        };
        await repo.SaveAsync(menuManageItem, userName);

        Assert.IsNotEmpty(menuManageItem.Id);
        // 用户管理
        var userManageItem = new AppNavItemModel {
            ParentId = adminItem.Id,
            Title    = "用户管理",
            Icon     = "bi/person",
            Url      = "/admin/users",
            Sequence = 2,
            Roles    = new [] { adminRoleName }
        };
        await repo.SaveAsync(userManageItem, userName);

        Assert.IsNotEmpty(userManageItem.Id);
        // 角色管理
        var roleManageItem = new AppNavItemModel {
            ParentId = adminItem.Id,
            Title    = "角色管理",
            Icon     = "bi/shield-lock",
            Url      = "/admin/roles",
            Sequence = 3,
            Roles    = new [] { adminRoleName }
        };
        await repo.SaveAsync(roleManageItem, userName);

        Assert.IsNotEmpty(roleManageItem.Id);
        // 权限管理
        var privilegesManageItem = new AppNavItemModel {
            ParentId = adminItem.Id,
            Title    = "权限管理",
            Icon     = "bi/shield-shaded",
            Url      = "/admin/privileges",
            Sequence = 4,
            Roles    = new [] { adminRoleName }
        };
        await repo.SaveAsync(privilegesManageItem, userName);

        Assert.IsNotEmpty(privilegesManageItem.Id);
        // 权限管理
        var auditLogsItem = new AppNavItemModel {
            ParentId = adminItem.Id,
            Title    = "审计日志",
            Icon     = "bi/list-check",
            Url      = "/admin/audit-logs",
            Sequence = 5,
            Roles    = new [] { adminRoleName }
        };
        await repo.SaveAsync(auditLogsItem, userName);

        Assert.IsNotEmpty(auditLogsItem.Id);
    }