private static async Task GenerateMyUserAsync(BackendDBContext context, Random random)
        {
            List <MyUser> users = new List <MyUser>();

            for (int i = 1; i < 30; i++)
            {
                MyUser MyUser = new MyUser()
                {
                    Account  = $"user{i}",
                    Name     = $"user{i}",
                    Password = "******",
                };
                users.Add(MyUser);
            }
            await context.BulkInsertAsync(users);
        }
예제 #2
0
        private async Task 建立功能表角色與項目清單Async()
        {
            #region 建立功能表角色與項目清單

            #region 建立功能表角色
            CleanTrackingHelper.Clean <MenuRole>(context);
            #region 開發者功能表角色功能表角色
            MenuRole menuRole開發者 = new MenuRole()
            {
                Name   = MagicHelper.開發者功能表角色,
                Remark = ""
            };
            context.Add(menuRole開發者);
            await context.SaveChangesAsync();

            #endregion

            #region 系統管理員功能表角色
            MenuRole menuRole系統管理員 = new MenuRole()
            {
                Name   = MagicHelper.系統管理員功能表角色,
                Remark = ""
            };
            context.Add(menuRole系統管理員);
            await context.SaveChangesAsync();

            #endregion

            #region 一般使用者功能表角色
            MenuRole menuRole使用者 = new MenuRole()
            {
                Name   = MagicHelper.使用者功能表角色,
                Remark = ""
            };
            context.Add(menuRole使用者);
            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <MenuRole>(context);
            #endregion
            #endregion

            #region 建立各角色會用到的功能表清單項目

            #region 建立系統管理員角色功能表項目清單
            CleanTrackingHelper.Clean <MenuData>(context);
            int cc = 0;

            #region 首頁功能名稱
            cc += 10;
            MenuData menuData = new MenuData()
            {
                Name       = BAL.Helpers.MagicHelper.首頁功能名稱,
                CodeName   = "/",
                Enable     = true,
                Icon       = "mdi-home",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 變更密碼
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = BAL.Helpers.MagicHelper.變更密碼,
                CodeName   = "ChangePassword",
                Enable     = true,
                Icon       = "mdi-form-textbox-password",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 系統資料管理   子功能表
            #region 系統資料管理   子功能表
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = "系統資料管理",
                CodeName   = "",
                Enable     = true,
                Icon       = "mdi-power-plug",
                IsGroup    = true,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 帳號管理功能名稱
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = BAL.Helpers.MagicHelper.帳號管理功能名稱,
                CodeName   = "MyUser",
                Enable     = true,
                Icon       = "mdi-clipboard-account",
                IsGroup    = false,
                Level      = 1,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 郵件寄送紀錄
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = MagicHelper.郵件寄送紀錄,
                CodeName   = "MailQueue",
                Enable     = true,
                Icon       = "mdi-email-send",
                IsGroup    = false,
                Level      = 1,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 系統訊息廣播
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = MagicHelper.系統訊息廣播,
                CodeName   = "Broadcast",
                Enable     = true,
                Icon       = "mdi-message-alert",
                IsGroup    = false,
                Level      = 1,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region App例外異常
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = MagicHelper.App例外異常,
                CodeName   = "ExceptionRecord",
                Enable     = true,
                Icon       = "mdi-message-alert",
                IsGroup    = false,
                Level      = 1,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion
            #endregion

            #region 基本資料管理   子功能表
            #region 基本資料管理
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = "基本資料管理",
                CodeName   = "",
                Enable     = true,
                Icon       = "mdi-database-cog",
                IsGroup    = true,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 範例程式碼,隱藏其功能表清單
            #region 商品管理功能名稱
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = BAL.Helpers.MagicHelper.商品管理功能名稱,
                CodeName   = "Product",
                Enable     = true,
                Icon       = "mdi-lightbulb-group",
                IsGroup    = false,
                Level      = 1,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 商品管理功能名稱
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = BAL.Helpers.MagicHelper.訂單管理功能名稱,
                CodeName   = "Order",
                Enable     = true,
                Icon       = "mdi-lightbulb-group",
                IsGroup    = false,
                Level      = 1,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion
            #endregion

            #endregion

            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <MenuData>(context);
            #endregion

            #region 系統管理員
            #region 移除 系統管理員 角色 不需要的 功能表項目清單
            CleanTrackingHelper.Clean <MenuData>(context);
            var defaultMenuData = await context.MenuData
                                  .AsNoTracking()
                                  .Where(x => x.MenuRoleId == menuRole開發者.Id)
                                  .ToListAsync();

            #endregion

            #region 建立 系統管理員 功能表項目清單
            foreach (var item in defaultMenuData)
            {
                item.Id         = 0;
                item.MenuRoleId = menuRole系統管理員.Id;
                item.MenuRole   = null;
            }
            await context.BulkInsertAsync(defaultMenuData);

            CleanTrackingHelper.Clean <MenuRole>(context);
            #endregion
            #endregion

            #region 一般使用者
            #region 移除 一般使用者 角色 不需要的 功能表項目清單
            CleanTrackingHelper.Clean <MenuData>(context);
            defaultMenuData = await context.MenuData
                              .AsNoTracking()
                              .Where(x => x.MenuRoleId == menuRole開發者.Id)
                              .ToListAsync();

            defaultMenuData
            .Remove(defaultMenuData
                    .FirstOrDefault(x => x.Name == "系統資料管理"));

            defaultMenuData
            .Remove(defaultMenuData
                    .FirstOrDefault(x => x.Name == "基本資料管理"));

            defaultMenuData
            .Remove(defaultMenuData
                    .FirstOrDefault(x => x.Name == "檢核計畫"));

            #endregion

            #region 建立 一般使用者 功能表項目清單
            foreach (var item in defaultMenuData)
            {
                item.Id         = 0;
                item.MenuRoleId = menuRole使用者.Id;
                item.MenuRole   = null;
            }
            await context.BulkInsertAsync(defaultMenuData);

            CleanTrackingHelper.Clean <MenuRole>(context);
            #endregion
            #endregion

            #endregion

            #endregion
        }
예제 #3
0
        async Task 建立片語分類與文字Async()
        {
            List <PhaseMessage> PhaseMessage = new List <PhaseMessage>();

            int cc = 10;

            #region 簽核表單使用的輸入片語
            var phaseCategory = new PhaseCategory()
            {
                Name         = "簽核表單使用的輸入片語",
                Enable       = true,
                OrderNumber  = cc++,
                PhaseMessage = new List <PhaseMessage>()
            };
            await context.PhaseCategory.AddAsync(phaseCategory);

            await context.SaveChangesAsync();

            PhaseMessage = new List <PhaseMessage>()
            {
                new PhaseMessage()
                {
                    Content         = "做得很好,繼續努力",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "用來形容情緒不會表露出來的人",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "像魚一樣的喝,表示喝很多,尤其指喝很多酒",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "意指非常重要、有權力或是具有影響力的人",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
            };
            await context.BulkInsertAsync(PhaseMessage);

            #endregion
            #region 改善報告的輸入片語
            phaseCategory = new PhaseCategory()
            {
                Name         = "改善報告的輸入片語",
                Enable       = true,
                OrderNumber  = cc++,
                PhaseMessage = new List <PhaseMessage>()
            };
            await context.PhaseCategory.AddAsync(phaseCategory);

            await context.SaveChangesAsync();

            PhaseMessage = new List <PhaseMessage>()
            {
                new PhaseMessage()
                {
                    Content         = "加速意見溝通",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "○○○○案,簽會意見綜合說明如下,請鑒核",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "會簽意見一略以,○○○○○○○○○…",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "會簽意見二略以,○○○○○○○○○…",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "「是否允當」?",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "……因故不克擔任…,予以改派…",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
            };
            await context.BulkInsertAsync(PhaseMessage);

            #endregion
            #region 雜項輸入片語
            phaseCategory = new PhaseCategory()
            {
                Name         = "雜項輸入片語",
                Enable       = true,
                OrderNumber  = cc++,
                PhaseMessage = new List <PhaseMessage>()
            };
            await context.PhaseCategory.AddAsync(phaseCategory);

            await context.SaveChangesAsync();

            PhaseMessage = new List <PhaseMessage>()
            {
                new PhaseMessage()
                {
                    Content         = "可以嗎?",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
                new PhaseMessage()
                {
                    Content         = "有關本校進修部學生向 鈞部「部長信箱」反映課程標準一案,本校已查明原委,謹檢陳查核報告乙份(如附件),敬請 鑒核。",
                    Enable          = true,
                    Code            = cc.ToString("D5"),
                    OrderNumber     = cc++,
                    PhaseCategoryId = phaseCategory.Id,
                },
            };
            await context.BulkInsertAsync(PhaseMessage);

            #endregion
        }
예제 #4
0
        private async Task 建立功能表角色與項目清單Async()
        {
            #region 建立功能表角色與項目清單

            #region 建立功能表角色
            CleanTrackingHelper.Clean <MenuRole>(context);
            #region 開發者功能表角色功能表角色
            MenuRole menuRole開發者 = new MenuRole()
            {
                Name   = MagicHelper.開發者功能表角色,
                Remark = ""
            };
            context.Add(menuRole開發者);
            await context.SaveChangesAsync();

            #endregion

            #region 系統管理員功能表角色
            MenuRole menuRole系統管理員 = new MenuRole()
            {
                Name   = MagicHelper.系統管理員功能表角色,
                Remark = ""
            };
            context.Add(menuRole系統管理員);
            await context.SaveChangesAsync();

            #endregion

            #region 一般使用者功能表角色
            MenuRole menuRole使用者 = new MenuRole()
            {
                Name   = MagicHelper.使用者功能表角色,
                Remark = ""
            };
            context.Add(menuRole使用者);
            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <MenuRole>(context);
            #endregion
            #endregion

            #region 建立各角色會用到的功能表清單項目

            #region 建立系統管理員角色功能表項目清單
            CleanTrackingHelper.Clean <MenuData>(context);
            int cc = 0;

            #region 首頁功能名稱
            cc += 10;
            MenuData menuData = new MenuData()
            {
                Name       = BAL.Helpers.MagicHelper.首頁功能名稱,
                CodeName   = "/",
                Enable     = true,
                Icon       = "mdi-home",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 帳號管理功能名稱
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = BAL.Helpers.MagicHelper.帳號管理功能名稱,
                CodeName   = "MyUser",
                Enable     = true,
                Icon       = "mdi-clipboard-account",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 變更密碼
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = BAL.Helpers.MagicHelper.變更密碼,
                CodeName   = "ChangePassword",
                Enable     = true,
                Icon       = "mdi-form-textbox-password",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 訂單管理功能名稱
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = MagicHelper.訂單管理功能名稱,
                CodeName   = "Order",
                Enable     = true,
                Icon       = "mdi-shopping",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 商品管理功能名稱
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = MagicHelper.商品管理功能名稱,
                CodeName   = "Product",
                Enable     = true,
                Icon       = "mdi-gift",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 管理者專用功能名稱
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = MagicHelper.管理者專用功能名稱,
                CodeName   = "OnlyAdministrator",
                Enable     = true,
                Icon       = "mdi-hand-pointing-up",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            #region 一般使用者使用功能名稱
            cc      += 10;
            menuData = new MenuData()
            {
                Name       = MagicHelper.一般使用者使用功能名稱,
                CodeName   = "OnlyUser",
                Enable     = true,
                Icon       = "mdi-head-heart",
                IsGroup    = false,
                Level      = 0,
                MenuRoleId = menuRole開發者.Id,
                Sequence   = cc,
            };
            context.Add(menuData);
            #endregion

            await context.SaveChangesAsync();

            CleanTrackingHelper.Clean <MenuData>(context);
            #endregion

            #region 系統管理員
            #region 移除 系統管理員 角色 不需要的 功能表項目清單
            CleanTrackingHelper.Clean <MenuData>(context);
            var defaultMenuData = await context.MenuData
                                  .AsNoTracking()
                                  .Where(x => x.MenuRoleId == menuRole開發者.Id)
                                  .ToListAsync();

            defaultMenuData
            .Remove(defaultMenuData
                    .FirstOrDefault(x => x.Name == MagicHelper.一般使用者使用功能名稱));
            #endregion

            #region 建立 系統管理員 功能表項目清單
            foreach (var item in defaultMenuData)
            {
                item.Id         = 0;
                item.MenuRoleId = menuRole系統管理員.Id;
                item.MenuRole   = null;
            }
            await context.BulkInsertAsync(defaultMenuData);

            CleanTrackingHelper.Clean <MenuRole>(context);
            #endregion
            #endregion

            #region 一般使用者
            #region 移除 一般使用者 角色 不需要的 功能表項目清單
            CleanTrackingHelper.Clean <MenuData>(context);
            defaultMenuData = await context.MenuData
                              .AsNoTracking()
                              .Where(x => x.MenuRoleId == menuRole開發者.Id)
                              .ToListAsync();

            defaultMenuData
            .Remove(defaultMenuData
                    .FirstOrDefault(x => x.Name == MagicHelper.帳號管理功能名稱));

            defaultMenuData
            .Remove(defaultMenuData
                    .FirstOrDefault(x => x.Name == MagicHelper.管理者專用功能名稱));

            defaultMenuData
            .Remove(defaultMenuData
                    .FirstOrDefault(x => x.Name == MagicHelper.商品管理功能名稱));

            #endregion

            #region 建立 一般使用者 功能表項目清單
            foreach (var item in defaultMenuData)
            {
                item.Id         = 0;
                item.MenuRoleId = menuRole使用者.Id;
                item.MenuRole   = null;
            }
            await context.BulkInsertAsync(defaultMenuData);

            CleanTrackingHelper.Clean <MenuRole>(context);
            #endregion
            #endregion

            #endregion

            #endregion
        }