diff --git a/Data/Repositories/DeviceRepository.cs b/Data/Repositories/DeviceRepository.cs
index 7f24031..73daa7b 100644
--- a/Data/Repositories/DeviceRepository.cs
+++ b/Data/Repositories/DeviceRepository.cs
@@ -29,13 +29,13 @@ public class DeviceRepository
///
/// 要编辑的设备对象。
/// 受影响的行数。
- public async Task Edit(Device device)
+ public async Task UpdateAsync(Device device)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var db = DbContext.GetInstance())
{
- var result = await Edit(device, db);
+ var result = await UpdateAsync(device, db);
stopwatch.Stop();
NlogHelper.Info($"编辑设备 '{device.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
@@ -47,7 +47,7 @@ public class DeviceRepository
///
/// 要编辑的设备对象。
/// 受影响的行数。
- public async Task Edit(Device device, SqlSugarClient db)
+ public async Task UpdateAsync(Device device, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -64,7 +64,7 @@ public class DeviceRepository
/// 获取设备列表
///
///
- public async Task> GetAll()
+ public async Task> GetAllAsync()
{
using (var db = DbContext.GetInstance())
{
@@ -88,7 +88,7 @@ public class DeviceRepository
///
/// 设备ID。
/// 对应的DbDevice对象。
- public async Task GetById(int id)
+ public async Task GetByIdAsync(int id)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -108,7 +108,7 @@ public class DeviceRepository
///
/// 要删除的设备ID。
/// 受影响的行数。
- public async Task Delete(Device device, List menus)
+ public async Task DeleteAsync(Device device, List menus)
{
using (var db = DbContext.GetInstance())
{
@@ -117,7 +117,7 @@ public class DeviceRepository
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
- var res = await Delete(device, menus, db);
+ var res = await DeleteAsync(device, menus, db);
stopwatch.Stop();
NlogHelper.Info($"删除设备:{device.Name},耗时:{stopwatch.ElapsedMilliseconds}ms");
@@ -143,7 +143,7 @@ public class DeviceRepository
///
/// 要删除的设备ID。
/// 受影响的行数。
- public async Task Delete(Device device, List menus, SqlSugarClient db)
+ public async Task DeleteAsync(Device device, List menus, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -156,7 +156,7 @@ public class DeviceRepository
var menu = DataServicesHelper.FindMenusForDevice(device, menus);
if (menu == null)
throw new NullReferenceException($"没有找到设备:{device.Name},的菜单对象。");
- await _menuRepository.DeleteMenu(menu, db);
+ await _menuRepository.DeleteAsync(menu, db);
stopwatch.Stop();
NlogHelper.Info($"删除设备:{device.Name},耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
@@ -167,7 +167,7 @@ public class DeviceRepository
/// 添加设备
///
///
- public async Task Add(Device device)
+ public async Task AddAsync(Device device)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -185,7 +185,7 @@ public class DeviceRepository
throw new InvalidOperationException("设备名称已经存在。");
// 2. 将设备添加到数据库
- var addDevice = await Add(device, db);
+ var addDevice = await AddAsync(device, db);
await db.CommitTranAsync();
@@ -214,7 +214,7 @@ public class DeviceRepository
///
///
///
- private async Task Add(Device device, SqlSugarClient db)
+ private async Task AddAsync(Device device, SqlSugarClient db)
{
;
// 添加设备
@@ -222,7 +222,7 @@ public class DeviceRepository
.ExecuteReturnEntityAsync();
// 4. 为新设备添加菜单
- var addDeviceMenuId = await _menuRepository.Add(addDevice, db);
+ var addDeviceMenuId = await _menuRepository.AddAsync(addDevice, db);
if (device.IsAddDefVarTable)
{
@@ -235,7 +235,7 @@ public class DeviceRepository
varTable.Description = "默认变量表";
varTable.ProtocolType = device.ProtocolType;
device.VariableTables.Add(varTable);
- var addVarTable = await _varTableRepository.Add(varTable, db);
+ var addVarTable = await _varTableRepository.AddAsync(varTable, db);
// 添加添加变量表的菜单
var varTableMenu = new MenuBean()
{
@@ -245,10 +245,10 @@ public class DeviceRepository
ParentId = addDeviceMenuId,
DataId = addVarTable.Id
};
- await _menuRepository.Add(varTableMenu, db);
+ await _menuRepository.AddAsync(varTableMenu, db);
}
- await _menuRepository.AddVarTableMenu(addDevice, addDeviceMenuId, db);
+ await _menuRepository.AddVarTableMenuAsync(addDevice, addDeviceMenuId, db);
return _mapper.Map(addDevice);
}
diff --git a/Data/Repositories/MenuRepository.cs b/Data/Repositories/MenuRepository.cs
index d07b739..099306d 100644
--- a/Data/Repositories/MenuRepository.cs
+++ b/Data/Repositories/MenuRepository.cs
@@ -21,17 +21,13 @@ public class MenuRepository
_mapper = mapper;
}
- public async Task DeleteMenu(MenuBean menu)
+ public async Task DeleteAsync(MenuBean menu)
{
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- using (var db = DbContext.GetInstance())
- {
- return await DeleteMenu(menu, db);
- }
+ using var db = DbContext.GetInstance();
+ return await DeleteAsync(menu, db);
}
- public async Task DeleteMenu(MenuBean menu, SqlSugarClient db)
+ public async Task DeleteAsync(MenuBean menu, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
@@ -45,7 +41,7 @@ public class MenuRepository
return result;
}
- public async Task> GetMenuTrees()
+ public async Task> GetMenuTreesAsync()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -64,12 +60,12 @@ public class MenuRepository
}
- public async Task Add(MenuBean menu)
+ public async Task AddAsync(MenuBean menu)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using var db = DbContext.GetInstance();
- var result = await Add(menu, db);
+ var result = await AddAsync(menu, db);
stopwatch.Stop();
NlogHelper.Info($"添加菜单 '{menu.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
@@ -82,7 +78,7 @@ public class MenuRepository
///
///
///
- public async Task Add(MenuBean menu, SqlSugarClient db)
+ public async Task AddAsync(MenuBean menu, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -94,7 +90,7 @@ public class MenuRepository
}
- public async Task AddVarTableMenu(DbDevice dbDevice, int parentMenuId, SqlSugarClient db)
+ public async Task AddVarTableMenuAsync(DbDevice dbDevice, int parentMenuId, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -121,7 +117,7 @@ public class MenuRepository
///
///
///
- public async Task Add(DbDevice device, SqlSugarClient db)
+ public async Task AddAsync(DbDevice device, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -151,13 +147,13 @@ public class MenuRepository
///
///
///
- public async Task Edit(MenuBean menu)
+ public async Task UpdateAsync(MenuBean menu)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var db = DbContext.GetInstance())
{
- var result = await Edit(menu, db);
+ var result = await UpdateAsync(menu, db);
stopwatch.Stop();
NlogHelper.Info($"编辑菜单 '{menu.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
@@ -169,7 +165,7 @@ public class MenuRepository
///
///
///
- public async Task Edit(MenuBean menu, SqlSugarClient db)
+ public async Task UpdateAsync(MenuBean menu, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -180,7 +176,7 @@ public class MenuRepository
return result;
}
- public async Task GetMenuByDataId(int dataId, MenuType menuType)
+ public async Task GetMenuByDataIdAsync(int dataId, MenuType menuType)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -194,7 +190,7 @@ public class MenuRepository
}
}
- public async Task GetMainMenuByName(string name)
+ public async Task GetMainMenuByNameAsync(string name)
{
using var db = DbContext.GetInstance();
var dbMenu= await db.Queryable().FirstAsync(m => m.Name == name && m.Type == MenuType.MainMenu);
diff --git a/Data/Repositories/MqttRepository.cs b/Data/Repositories/MqttRepository.cs
index b3830f8..4b539ee 100644
--- a/Data/Repositories/MqttRepository.cs
+++ b/Data/Repositories/MqttRepository.cs
@@ -27,7 +27,7 @@ public class MqttRepository
///
/// 主键ID
///
- public async Task GetById(int id)
+ public async Task GetByIdAsync(int id)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -46,7 +46,7 @@ public class MqttRepository
/// 获取所有Mqtt配置
///
///
- public async Task> GetAll()
+ public async Task> GetAllAsync()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -66,7 +66,7 @@ public class MqttRepository
///
/// Mqtt实体
///
- public async Task Add(Mqtt mqtt)
+ public async Task AddAsync(Mqtt mqtt)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -76,8 +76,8 @@ public class MqttRepository
{
var result = await db.Insertable(_mapper.Map(mqtt))
.ExecuteReturnIdentityAsync();
- var mqttMenu = await _menuRepository.GetMainMenuByName("Mqtt服务器");
- // Add menu entry
+ var mqttMenu = await _menuRepository.GetMainMenuByNameAsync("Mqtt服务器");
+ // AddAsync menu entry
var menu = new MenuBean()
{
Name = mqtt.Name,
@@ -86,7 +86,7 @@ public class MqttRepository
DataId = result,
ParentId = mqttMenu.Id,
};
- await _menuRepository.Add(menu, db);
+ await _menuRepository.AddAsync(menu, db);
await db.CommitTranAsync();
stopwatch.Stop();
NlogHelper.Info($"新增Mqtt配置 '{mqtt.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
@@ -105,7 +105,7 @@ public class MqttRepository
///
/// Mqtt实体
///
- public async Task Edit(Mqtt mqtt)
+ public async Task UpdateAsync(Mqtt mqtt)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -117,11 +117,11 @@ public class MqttRepository
var result = await db.Updateable(_mapper.Map(mqtt))
.ExecuteCommandAsync();
// Update menu entry
- var menu = await _menuRepository.GetMenuByDataId(mqtt.Id, MenuType.MqttMenu);
+ var menu = await _menuRepository.GetMenuByDataIdAsync(mqtt.Id, MenuType.MqttMenu);
if (menu != null)
{
menu.Name = mqtt.Name;
- await _menuRepository.Edit(menu, db);
+ await _menuRepository.UpdateAsync(menu, db);
}
await db.CommitTranAsync();
@@ -143,7 +143,7 @@ public class MqttRepository
///
/// Mqtt实体
///
- public async Task Delete(Mqtt mqtt)
+ public async Task DeleteAsync(Mqtt mqtt)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -156,10 +156,10 @@ public class MqttRepository
.In(mqtt.Id)
.ExecuteCommandAsync();
// DeleteAsync menu entry
- var menu = await _menuRepository.GetMenuByDataId(mqtt.Id, MenuType.MqttMenu);
+ var menu = await _menuRepository.GetMenuByDataIdAsync(mqtt.Id, MenuType.MqttMenu);
if (menu!=null )
{
- await _menuRepository.DeleteMenu(menu, db);
+ await _menuRepository.DeleteAsync(menu, db);
}
await db.CommitTranAsync();
diff --git a/Data/Repositories/VarDataRepository.cs b/Data/Repositories/VarDataRepository.cs
index 69c3914..174da0b 100644
--- a/Data/Repositories/VarDataRepository.cs
+++ b/Data/Repositories/VarDataRepository.cs
@@ -67,7 +67,7 @@ public class VarDataRepository
/// 获取所有VariableData
///
///
- public async Task> GetByVariableTableId(int varTableId)
+ public async Task> GetByVariableTableIdAsync(int varTableId)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
diff --git a/Data/Repositories/VarTableRepository.cs b/Data/Repositories/VarTableRepository.cs
index 1202c32..c00d71c 100644
--- a/Data/Repositories/VarTableRepository.cs
+++ b/Data/Repositories/VarTableRepository.cs
@@ -24,13 +24,13 @@ public class VarTableRepository
///
///
/// 变量表的ID
- public async Task Add(VariableTable varTable)
+ public async Task AddAsync(VariableTable varTable)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
using (var db = DbContext.GetInstance())
{
- var addVarTable = await Add(varTable, db);
+ var addVarTable = await AddAsync(varTable, db);
stopwatch.Stop();
NlogHelper.Info($"添加变量表 '{varTable.Name}' 耗时:{stopwatch.ElapsedMilliseconds}ms");
@@ -45,7 +45,7 @@ public class VarTableRepository
///
///
///
- public async Task Add(VariableTable variableTable, SqlSugarClient db)
+ public async Task AddAsync(VariableTable variableTable, SqlSugarClient db)
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
@@ -142,12 +142,6 @@ public class VarTableRepository
.ExecuteCommandAsync();
}
- public async Task AddAsync(VariableTable varTable)
- {
- using var db = DbContext.GetInstance();
- return await Add(varTable);
- }
-
}
\ No newline at end of file