|
1 |
| -using Blog.Core.Common.Helper; |
| 1 | +using Blog.Core.Common; |
| 2 | +using Blog.Core.Common.Helper; |
2 | 3 | using Blog.Core.Model.Models;
|
3 | 4 | using SqlSugar;
|
4 | 5 | using System;
|
@@ -65,126 +66,129 @@ public static async Task SeedAsync(MyContext myContext)
|
65 | 66 | Console.WriteLine("Database:WMBlog created success!");
|
66 | 67 | Console.WriteLine();
|
67 | 68 |
|
68 |
| - Console.WriteLine("Seeding database..."); |
69 |
| - |
70 |
| - #region BlogArticle |
71 |
| - if (!await myContext.Db.Queryable<BlogArticle>().AnyAsync()) |
72 |
| - { |
73 |
| - myContext.GetEntityDB<BlogArticle>().InsertRange(JsonHelper.ParseFormByJson<List<BlogArticle>>(GetNetData.Get(string.Format(GitJsonFileFormat, "BlogArticle")))); |
74 |
| - Console.WriteLine("Table:BlogArticle created success!"); |
75 |
| - } |
76 |
| - else |
77 |
| - { |
78 |
| - Console.WriteLine("Table:BlogArticle already exists..."); |
79 |
| - } |
80 |
| - #endregion |
81 |
| - |
82 |
| - |
83 |
| - #region Module |
84 |
| - if (!await myContext.Db.Queryable<Module>().AnyAsync()) |
85 |
| - { |
86 |
| - myContext.GetEntityDB<Module>().InsertRange(JsonHelper.ParseFormByJson<List<Module>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Module")))); |
87 |
| - Console.WriteLine("Table:Module created success!"); |
88 |
| - } |
89 |
| - else |
90 |
| - { |
91 |
| - Console.WriteLine("Table:Module already exists..."); |
92 |
| - } |
93 |
| - #endregion |
94 |
| - |
95 |
| - |
96 |
| - #region Permission |
97 |
| - if (!await myContext.Db.Queryable<Permission>().AnyAsync()) |
98 |
| - { |
99 |
| - myContext.GetEntityDB<Permission>().InsertRange(JsonHelper.ParseFormByJson<List<Permission>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Permission")))); |
100 |
| - Console.WriteLine("Table:Permission created success!"); |
101 |
| - } |
102 |
| - else |
103 |
| - { |
104 |
| - Console.WriteLine("Table:Permission already exists..."); |
105 |
| - } |
106 |
| - #endregion |
107 |
| - |
108 |
| - |
109 |
| - #region Role |
110 |
| - if (!await myContext.Db.Queryable<Role>().AnyAsync()) |
111 |
| - { |
112 |
| - myContext.GetEntityDB<Role>().InsertRange(JsonHelper.ParseFormByJson<List<Role>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Role")))); |
113 |
| - Console.WriteLine("Table:Role created success!"); |
114 |
| - } |
115 |
| - else |
116 |
| - { |
117 |
| - Console.WriteLine("Table:Role already exists..."); |
118 |
| - } |
119 |
| - #endregion |
120 |
| - |
121 |
| - |
122 |
| - #region RoleModulePermission |
123 |
| - if (!await myContext.Db.Queryable<RoleModulePermission>().AnyAsync()) |
124 |
| - { |
125 |
| - myContext.GetEntityDB<RoleModulePermission>().InsertRange(JsonHelper.ParseFormByJson<List<RoleModulePermission>>(GetNetData.Get(string.Format(GitJsonFileFormat, "RoleModulePermission")))); |
126 |
| - Console.WriteLine("Table:RoleModulePermission created success!"); |
127 |
| - } |
128 |
| - else |
129 |
| - { |
130 |
| - Console.WriteLine("Table:RoleModulePermission already exists..."); |
131 |
| - } |
132 |
| - #endregion |
133 |
| - |
134 |
| - |
135 |
| - #region Topic |
136 |
| - if (!await myContext.Db.Queryable<Topic>().AnyAsync()) |
137 |
| - { |
138 |
| - myContext.GetEntityDB<Topic>().InsertRange(JsonHelper.ParseFormByJson<List<Topic>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Topic")))); |
139 |
| - Console.WriteLine("Table:Topic created success!"); |
140 |
| - } |
141 |
| - else |
142 |
| - { |
143 |
| - Console.WriteLine("Table:Topic already exists..."); |
| 69 | + if (Appsettings.app(new string[] { "AppSettings", "SeedDBDataEnabled" }).ObjToBool()) |
| 70 | + { |
| 71 | + Console.WriteLine("Seeding database..."); |
| 72 | + |
| 73 | + #region BlogArticle |
| 74 | + if (!await myContext.Db.Queryable<BlogArticle>().AnyAsync()) |
| 75 | + { |
| 76 | + myContext.GetEntityDB<BlogArticle>().InsertRange(JsonHelper.ParseFormByJson<List<BlogArticle>>(GetNetData.Get(string.Format(GitJsonFileFormat, "BlogArticle")))); |
| 77 | + Console.WriteLine("Table:BlogArticle created success!"); |
| 78 | + } |
| 79 | + else |
| 80 | + { |
| 81 | + Console.WriteLine("Table:BlogArticle already exists..."); |
| 82 | + } |
| 83 | + #endregion |
| 84 | + |
| 85 | + |
| 86 | + #region Module |
| 87 | + if (!await myContext.Db.Queryable<Module>().AnyAsync()) |
| 88 | + { |
| 89 | + myContext.GetEntityDB<Module>().InsertRange(JsonHelper.ParseFormByJson<List<Module>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Module")))); |
| 90 | + Console.WriteLine("Table:Module created success!"); |
| 91 | + } |
| 92 | + else |
| 93 | + { |
| 94 | + Console.WriteLine("Table:Module already exists..."); |
| 95 | + } |
| 96 | + #endregion |
| 97 | + |
| 98 | + |
| 99 | + #region Permission |
| 100 | + if (!await myContext.Db.Queryable<Permission>().AnyAsync()) |
| 101 | + { |
| 102 | + myContext.GetEntityDB<Permission>().InsertRange(JsonHelper.ParseFormByJson<List<Permission>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Permission")))); |
| 103 | + Console.WriteLine("Table:Permission created success!"); |
| 104 | + } |
| 105 | + else |
| 106 | + { |
| 107 | + Console.WriteLine("Table:Permission already exists..."); |
| 108 | + } |
| 109 | + #endregion |
| 110 | + |
| 111 | + |
| 112 | + #region Role |
| 113 | + if (!await myContext.Db.Queryable<Role>().AnyAsync()) |
| 114 | + { |
| 115 | + myContext.GetEntityDB<Role>().InsertRange(JsonHelper.ParseFormByJson<List<Role>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Role")))); |
| 116 | + Console.WriteLine("Table:Role created success!"); |
| 117 | + } |
| 118 | + else |
| 119 | + { |
| 120 | + Console.WriteLine("Table:Role already exists..."); |
| 121 | + } |
| 122 | + #endregion |
| 123 | + |
| 124 | + |
| 125 | + #region RoleModulePermission |
| 126 | + if (!await myContext.Db.Queryable<RoleModulePermission>().AnyAsync()) |
| 127 | + { |
| 128 | + myContext.GetEntityDB<RoleModulePermission>().InsertRange(JsonHelper.ParseFormByJson<List<RoleModulePermission>>(GetNetData.Get(string.Format(GitJsonFileFormat, "RoleModulePermission")))); |
| 129 | + Console.WriteLine("Table:RoleModulePermission created success!"); |
| 130 | + } |
| 131 | + else |
| 132 | + { |
| 133 | + Console.WriteLine("Table:RoleModulePermission already exists..."); |
| 134 | + } |
| 135 | + #endregion |
| 136 | + |
| 137 | + |
| 138 | + #region Topic |
| 139 | + if (!await myContext.Db.Queryable<Topic>().AnyAsync()) |
| 140 | + { |
| 141 | + myContext.GetEntityDB<Topic>().InsertRange(JsonHelper.ParseFormByJson<List<Topic>>(GetNetData.Get(string.Format(GitJsonFileFormat, "Topic")))); |
| 142 | + Console.WriteLine("Table:Topic created success!"); |
| 143 | + } |
| 144 | + else |
| 145 | + { |
| 146 | + Console.WriteLine("Table:Topic already exists..."); |
| 147 | + } |
| 148 | + #endregion |
| 149 | + |
| 150 | + |
| 151 | + #region TopicDetail |
| 152 | + if (!await myContext.Db.Queryable<TopicDetail>().AnyAsync()) |
| 153 | + { |
| 154 | + myContext.GetEntityDB<TopicDetail>().InsertRange(JsonHelper.ParseFormByJson<List<TopicDetail>>(GetNetData.Get(string.Format(GitJsonFileFormat, "TopicDetail")))); |
| 155 | + Console.WriteLine("Table:TopicDetail created success!"); |
| 156 | + } |
| 157 | + else |
| 158 | + { |
| 159 | + Console.WriteLine("Table:TopicDetail already exists..."); |
| 160 | + } |
| 161 | + #endregion |
| 162 | + |
| 163 | + |
| 164 | + #region UserRole |
| 165 | + if (!await myContext.Db.Queryable<UserRole>().AnyAsync()) |
| 166 | + { |
| 167 | + myContext.GetEntityDB<UserRole>().InsertRange(JsonHelper.ParseFormByJson<List<UserRole>>(GetNetData.Get(string.Format(GitJsonFileFormat, "UserRole")))); |
| 168 | + Console.WriteLine("Table:UserRole created success!"); |
| 169 | + } |
| 170 | + else |
| 171 | + { |
| 172 | + Console.WriteLine("Table:UserRole already exists..."); |
| 173 | + } |
| 174 | + #endregion |
| 175 | + |
| 176 | + |
| 177 | + #region sysUserInfo |
| 178 | + if (!await myContext.Db.Queryable<sysUserInfo>().AnyAsync()) |
| 179 | + { |
| 180 | + myContext.GetEntityDB<sysUserInfo>().InsertRange(JsonHelper.ParseFormByJson<List<sysUserInfo>>(GetNetData.Get(string.Format(GitJsonFileFormat, "sysUserInfo")))); |
| 181 | + Console.WriteLine("Table:sysUserInfo created success!"); |
| 182 | + } |
| 183 | + else |
| 184 | + { |
| 185 | + Console.WriteLine("Table:sysUserInfo already exists..."); |
| 186 | + } |
| 187 | + #endregion |
| 188 | + |
| 189 | + Console.WriteLine("Done seeding database."); |
144 | 190 | }
|
145 |
| - #endregion |
146 |
| - |
147 |
| - |
148 |
| - #region TopicDetail |
149 |
| - if (!await myContext.Db.Queryable<TopicDetail>().AnyAsync()) |
150 |
| - { |
151 |
| - myContext.GetEntityDB<TopicDetail>().InsertRange(JsonHelper.ParseFormByJson<List<TopicDetail>>(GetNetData.Get(string.Format(GitJsonFileFormat, "TopicDetail")))); |
152 |
| - Console.WriteLine("Table:TopicDetail created success!"); |
153 |
| - } |
154 |
| - else |
155 |
| - { |
156 |
| - Console.WriteLine("Table:TopicDetail already exists..."); |
157 |
| - } |
158 |
| - #endregion |
159 |
| - |
160 |
| - |
161 |
| - #region UserRole |
162 |
| - if (!await myContext.Db.Queryable<UserRole>().AnyAsync()) |
163 |
| - { |
164 |
| - myContext.GetEntityDB<UserRole>().InsertRange(JsonHelper.ParseFormByJson<List<UserRole>>(GetNetData.Get(string.Format(GitJsonFileFormat, "UserRole")))); |
165 |
| - Console.WriteLine("Table:UserRole created success!"); |
166 |
| - } |
167 |
| - else |
168 |
| - { |
169 |
| - Console.WriteLine("Table:UserRole already exists..."); |
170 |
| - } |
171 |
| - #endregion |
172 |
| - |
173 |
| - |
174 |
| - #region sysUserInfo |
175 |
| - if (!await myContext.Db.Queryable<sysUserInfo>().AnyAsync()) |
176 |
| - { |
177 |
| - myContext.GetEntityDB<sysUserInfo>().InsertRange(JsonHelper.ParseFormByJson<List<sysUserInfo>>(GetNetData.Get(string.Format(GitJsonFileFormat, "sysUserInfo")))); |
178 |
| - Console.WriteLine("Table:sysUserInfo created success!"); |
179 |
| - } |
180 |
| - else |
181 |
| - { |
182 |
| - Console.WriteLine("Table:sysUserInfo already exists..."); |
183 |
| - } |
184 |
| - #endregion |
185 |
| - |
186 | 191 |
|
187 |
| - Console.WriteLine("Done seeding database."); |
188 | 192 | Console.WriteLine();
|
189 | 193 |
|
190 | 194 | }
|
|
0 commit comments