8000 repository pattern · githubsunyf/cms@6310bd0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6310bd0

Browse files
committed
repository pattern
1 parent e35196e commit 6310bd0

36 files changed

+185
-255
lines changed

SiteServer.BackgroundPages/BasePage.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public class BasePage : Page
1616

1717
protected virtual bool IsSinglePage => false; // 是否为单页(即是否需要放在框架页内运行,false表示需要)
1818

19-
protected virtual bool IsInstallerPage => false; // 是否为系统安装页面
20-
2119
public string IsNightly => WebConfigUtils.IsNightlyUpdate.ToString().ToLower(); // 系统是否允许升级到最新的开发版本
2220

2321
public string Version => SystemManager.PluginVersion; // 系统采用的插件API版本号
@@ -42,23 +40,6 @@ protected override void OnInit(EventArgs e)
4240
AuthRequest = new RequestImpl(Request);
4341
#pragma warning restore CS0612 // '“RequestImpl”已过时
4442

45-
if (!IsInstallerPage)
46-
{
47-
if (string.IsNullOrEmpty(WebConfigUtils.ConnectionString))
48-
{
49-
PageUtils.Redirect(PageUtils.GetAdminUrl("Installer"));
50-
return;
51-
}
52-
53-
#if !DEBUG
54-
if (ConfigManager.Instance.IsInitialized && ConfigManager.Instance.DatabaseVersion != SystemManager.Version)
55-
{
56-
PageUtils.Redirect(PageSyncDatabase.GetRedirectUrl());
57-
return;
58-
}
59-
#endif
60-
}
61-
6243
if (!IsAccessable) // 如果页面不能直接访问且又没有登录则直接跳登录页
6344
{
6445
if (!AuthRequest.IsAdminLoggin || AuthRequest.AdminInfo == null || AuthRequest.AdminInfo.Locked) // 检测管理员是否登录,检测管理员帐号是否被锁定

SiteServer.BackgroundPages/Cms/ModalContentTidyUp.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public class ModalContentTidyUp : BasePageCms
1414
public DropDownList DdlAttributeName;
1515
public DropDownList DdlIsDesc;
1616

17-
private string _tableName;
1817
private string _returnUrl;
1918

2019
public static string GetOpenWindowString(int siteId, int channelId, string returnUrl)

SiteServer.BackgroundPages/PageInstaller.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ public class PageInstaller : BasePage
5757

5858
protected override bool IsAccessable => true;
5959

60-
protected override bool IsInstallerPage => true;
61-
6260
public static string GetRedirectUrl()
6361
{
6462
return PageUtils.GetSiteServerUrl("installer/default", null);

SiteServer.CMS.Tests/Core/Database/TestTableRepository.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ public class TestTableRepository : GenericRepository<TestTableInfo>
6767
{
6868
public new Query Q => base.Q;
6969

70-
public new int Insert(TestTableInfo dataInfo)
70+
public int Insert(TestTableInfo dataInfo)
7171
{
72-
return base.InsertObject(dataInfo);
72+
return InsertObject(dataInfo);
7373
}
7474

7575
public new bool Exists(int id)
@@ -107,33 +107,33 @@ public class TestTableRepository : GenericRepository<TestTableInfo>
107107
return base.GetValueList<TValue>(query);
108108
}
109109

110-
public new TestTableInfo First(int id)
110+
public TestTableInfo First(int id)
111111
{
112-
return base.GetObjectById(id);
112+
return GetObjectById(id);
113113
}
114114

115-
public new TestTableInfo First(string guid)
115+
public TestTableInfo First(string guid)
116116
{
117-
return base.GetObjectByGuid(guid);
117+
return GetObjectByGuid(guid);
118118
}
119119

120120

121-
public new TestTableInfo First(Query query = null)
121+
public TestTableInfo First(Query query = null)
122122
{
123-
return base.GetObject(query);
123+
return GetObject(query);
124124
}
125125

126126

127127

128-
public new IList<TestTableInfo> GetAll(Query query = null)
128+
public IList<TestTableInfo> GetAll(Query query = null)
129129
{
130-
return base.GetObjectList(query);
130+
return GetObjectList(query);
131131
}
132132

133133

134-
public new bool Update(TestTableInfo dataInfo)
134+
public bool Update(TestTableInfo dataInfo)
135135
{
136-
return base.UpdateObject(dataInfo);
136+
return UpdateObject(dataInfo);
137137
}
138138

139139

@@ -143,14 +143,14 @@ public class TestTableRepository : GenericRepository<TestTableInfo>
143143
}
144144

145145

146-
public new bool Delete(int id)
146+
public bool Delete(int id)
147147
{
148-
return base.DeleteById(id);
148+
return DeleteById(id);
149149
}
150150

151-
public new bool Delete(string guid)
151+
public bool Delete(string guid)
152152
{
153-
return base.DeleteByGuid(guid);
153+
return DeleteByGuid(guid);
154154
}
155155

156156
public new int DeleteAll(Query query = null)

SiteServer.CMS/Database/Core/GenericRepositoryAbstract.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ private IDbConnection GetConnection()
7070
return SqlDifferences.GetIDbConnection(WebConfigUtils.DatabaseType, WebConfigUtils.ConnectionString);
7171
}
7272

73-
protected Query Q => new Query();
73+
protected Query Q => NewQuery();
74+
75+
public Query NewQuery()
76+
{
77+
return new Query();
78+
}
7479

7580
protected int InsertObject<T>(T dataInfo) where T : class, IDataInfo
7681
{

SiteServer.CMS/Database/Repositories/AccessTokenRepository.cs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,25 @@ private static class Attr
1414
public const string Title = nameof(AccessTokenInfo.Title);
1515
}
1616

17-
public new int Insert(AccessTokenInfo accessTokenInfo)
17+
public void Insert(AccessTokenInfo accessTokenInfo)
1818
{
1919
accessTokenInfo.Token = TranslateUtils.EncryptStringBySecretKey(StringUtils.GetGuid());
2020
accessTokenInfo.AddDate = DateTime.Now;
2121

22-
var identity = base.InsertObject(accessTokenInfo);
22+
InsertObject(accessTokenInfo);
2323
AccessTokenManager.ClearCache();
24-
return identity;
2524
}
2625

27-
public new bool Update(AccessTokenInfo accessTokenInfo)
26+
public bool Update(AccessTokenInfo accessTokenInfo)
2827
{
29-
var updated = base.UpdateObject(accessTokenInfo);
28+
var updated = UpdateObject(accessTokenInfo);
3029
AccessTokenManager.ClearCache();
3130
return updated;
3231
}
3332

34-
public new bool Delete(int id)
33+
public bool Delete(int id)
3534
{
36-
var deleted = base.DeleteById(id);
35+
var deleted = DeleteById(id);
3736
AccessTokenManager.ClearCache();
3837
return deleted;
3938
}
@@ -52,14 +51,9 @@ public AccessTokenInfo Get(int id)
5251
return GetObjectById(id);
5352
}
5453

55-
public AccessTokenInfo Get()
56-
{
57-
return GetObject();
58-
}
59-
6054
public IList<AccessTokenInfo> GetAll()
6155
{
62-
return base.GetObjectList();
56+
return GetObjectList();
6357
}
6458

6559
public bool IsTitleExists(string title)

SiteServer.CMS/Database/Repositories/AdministratorRepository.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ private static class Attr
3030
public const string IsLockedOut = "IsLockedOut";
3131
}
3232

33-
public Query GetQuery()
34-
{
35-
return Q;
36-
}
37-
3833
public int GetCount(Query query)
3934
{
4035
return Count(query);
@@ -45,9 +40,9 @@ public int GetCount()
4540
return Count();
4641
}
4742

48-
public new IList<AdministratorInfo> GetAll(Query query)
43+
public IList<AdministratorInfo> GetAll(Query query)
4944
{
50-
return base.GetObjectList(query);
45+
return GetObjectList(query);
5146
}
5247

5348
public int Insert(AdministratorInfo adminInfo, out string errorMessage)
@@ -61,7 +56,7 @@ public int Insert(AdministratorInfo adminInfo, out string errorMessage)
6156
adminInfo.Password = EncodePassword(adminInfo.Password, EPasswordFormatUtils.GetEnumType(adminInfo.PasswordFormat), out var passwordSalt);
6257
adminInfo.PasswordSalt = passwordSalt;
6358

64-
var identity = base.InsertObject(adminInfo);
59+
var identity = InsertObject(adminInfo);
6560

6661
//IDataParameter[] parameters =
6762
//{
@@ -116,7 +111,7 @@ public bool Update(AdministratorInfo administratorInfo, out string errorMessage)
116111

117112
if (!UpdateValidate(administratorInfo, adminInfo.UserName, adminInfo.Email, adminInfo.Mobile, out errorMessage)) return false;
118113

119-
var updated = base.UpdateObject(administratorInfo);
114+
var updated = UpdateObject(administratorInfo);
120115

121116
//IDataParameter[] parameters =
122117
//{

SiteServer.CMS/Database/Repositories/AreaRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private void Insert(AreaInfo parentInfo, AreaInfo areaInfo)
6060
//};
6161

6262
//areaInfo.Id = _db.ExecuteNonQueryAndReturnId(TableName, nameof(AreaInfo.Id), trans, "INSERT INTO siteserver_Area (AreaName, ParentID, ParentsPath, ParentsCount, ChildrenCount, IsLastNode, Taxis, CountOfAdmin) VALUES (@AreaName, @ParentID, @ParentsPath, @ParentsCount, @ChildrenCount, @IsLastNode, @Taxis, @CountOfAdmin)", parameters);
63-
base.InsertObject(areaInfo);
63+
InsertObject(areaInfo);
6464

6565
if (!string.IsNullOrEmpty(areaInfo.ParentsPath) && areaInfo.ParentsPath != "0")
6666
{
@@ -320,7 +320,7 @@ private int GetMaxTaxisByParentPath(string parentPath)
320320
//return maxTaxis;
321321
}
322322

323-
public new void Insert(AreaInfo areaInfo)
323+
public void Insert(AreaInfo areaInfo)
324324
{
325325
//using (var conn = GetConnection())
326326
//{
@@ -353,7 +353,7 @@ private int GetMaxTaxisByParentPath(string parentPath)
353353
AreaManager.ClearCache();
354354
}
355355

356-
public new void Update(AreaInfo areaInfo)
356+
public void Update(AreaInfo areaInfo)
357357
{
358358
// IDataParameter[] updateParams = {
359359
// _db.GetParameter(ParamName, areaInfo.AreaName),
@@ -367,7 +367,7 @@ private int GetMaxTaxisByParentPath(string parentPath)
367367

368368
// var i = _db.ExecuteNonQuery(_connectionString, SqlUpdate, updateParams);
369369

370-
if (base.UpdateObject(areaInfo))
370+
if (UpdateObject(areaInfo))
371371
{
372372
AreaManager.ClearCache();
373373
}

SiteServer.CMS/Database/Repositories/ChannelGroupRepository.cs

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,14 @@ namespace SiteServer.CMS.Database.Repositories
99
{
1010
public class ChannelGroupRepository : GenericRepository<ChannelGroupInfo>
1111
{
12-
//public override string TableName => "siteserver_ChannelGroup";
13-
14-
//public override List<TableColumn> TableColumns => new List<TableColumn>
15-
//{
16-
// new TableColumn
17-
// {
18-
// AttributeName = nameof(ChannelGroupInfo.Id),
19-
// DataType = DataType.Integer,
20-
// IsIdentity = true,
21-
// IsPrimaryKey = true
22-
// },
23-
// new TableColumn
24-
// {
25-
// AttributeName = nameof(ChannelGroupInfo.GroupName),
26-
// DataType = DataType.VarChar
27-
// },
28-
// new TableColumn
29-
// {
30-
// AttributeName = nameof(ChannelGroupInfo.SiteId),
31-
// DataType = DataType.Integer
32-
// },
33-
// new TableColumn
34-
// {
35-
// AttributeName = nameof(ChannelGroupInfo.Taxis),
36-
// DataType = DataType.Integer
37-
// },
38-
// new TableColumn
39-
// {
40-
// AttributeName = nameof(ChannelGroupInfo.Description),
41-
// DataType = DataType.Text
42-
// }
43-
//};
44-
45-
//private const string ParamGroupName = "@GroupName";
46-
//private const string ParamSiteId = "@SiteId";
47-
// private const string ParamTaxis = "@Taxis";
48-
//private const string ParamDescription = "@Description";
49-
5012
private static class Attr
5113
{
5214
public const string GroupName = nameof(ChannelGroupInfo.GroupName);
5315
public const string SiteId = nameof(ChannelGroupInfo.SiteId);
5416
public const string Taxis = nameof(ChannelGroupInfo.Taxis);
5517
}
5618

57-
public new void Insert(ChannelGroupInfo groupInfo)
19+
public void Insert(ChannelGroupInfo groupInfo)
5820
{
5921
var maxTaxis = GetMaxTaxis(groupInfo.SiteId);
6022
groupInfo.Taxis = maxTaxis + 1;
@@ -71,12 +33,12 @@ private static class Attr
7133

7234
//DatabaseApi.ExecuteNonQuery(ConnectionString, sqlString, parameters);
7335

74-
base.InsertObject(groupInfo);
36+
InsertObject(groupInfo);
7537

7638
ChannelGroupManager.ClearCache();
7739
}
7840

79-
public new void Update(ChannelGroupInfo groupInfo)
41+
public void Update(ChannelGroupInfo groupInfo)
8042
{
8143
//var sqlString = $"UPDATE {TableName} SET Description = @Description WHERE GroupName = @GroupName AND SiteId = @SiteId";
8244

@@ -88,7 +50,7 @@ private static class Attr
8850
//};
8951

9052
//DatabaseApi.ExecuteNonQuery(ConnectionString, sqlString, parameters);
91-
base.UpdateObject(groupInfo);
53+
UpdateObject(groupInfo);
9254

9355
ChannelGroupManager.ClearCache();
9456
}

0 commit comments

Comments
 (0)
0