添加用户和Mqtt的仓储文件,添加的对Excel进行导入导出功能,并完成单元测试
This commit is contained in:
75
Data/Repositories/MqttRepository.cs
Normal file
75
Data/Repositories/MqttRepository.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using PMSWPF.Data.Entities;
|
||||
|
||||
namespace PMSWPF.Data.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// Mqtt仓储类,用于操作DbMqtt实体
|
||||
/// </summary>
|
||||
public class MqttRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据ID获取Mqtt配置
|
||||
/// </summary>
|
||||
/// <param name="id">主键ID</param>
|
||||
/// <returns></returns>
|
||||
public async Task<DbMqtt> GetByIdAsync(int id)
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Queryable<DbMqtt>().In(id).SingleAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有Mqtt配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<DbMqtt>> GetAllAsync()
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Queryable<DbMqtt>().ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增Mqtt配置
|
||||
/// </summary>
|
||||
/// <param name="mqtt">Mqtt实体</param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> AddAsync(DbMqtt mqtt)
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Insertable(mqtt).ExecuteReturnIdentityAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新Mqtt配置
|
||||
/// </summary>
|
||||
/// <param name="mqtt">Mqtt实体</param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> UpdateAsync(DbMqtt mqtt)
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Updateable(mqtt).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID删除Mqtt配置
|
||||
/// </summary>
|
||||
/// <param name="id">主键ID</param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> DeleteAsync(int id)
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Deleteable<DbMqtt>().In(id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
75
Data/Repositories/UserRepository.cs
Normal file
75
Data/Repositories/UserRepository.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using PMSWPF.Data.Entities;
|
||||
|
||||
namespace PMSWPF.Data.Repositories;
|
||||
|
||||
/// <summary>
|
||||
/// 用户仓储类,用于操作DbUser实体
|
||||
/// </summary>
|
||||
public class UserRepository
|
||||
{
|
||||
/// <summary>
|
||||
/// 根据ID获取用户
|
||||
/// </summary>
|
||||
/// <param name="id">主键ID</param>
|
||||
/// <returns></returns>
|
||||
public async Task<DbUser> GetByIdAsync(int id)
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Queryable<DbUser>().In(id).SingleAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有用户
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<DbUser>> GetAllAsync()
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Queryable<DbUser>().ToListAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 新增用户
|
||||
/// </summary>
|
||||
/// <param name="user">用户实体</param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> AddAsync(DbUser user)
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Insertable(user).ExecuteReturnIdentityAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新用户
|
||||
/// </summary>
|
||||
/// <param name="user">用户实体</param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> UpdateAsync(DbUser user)
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Updateable(user).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据ID删除用户
|
||||
/// </summary>
|
||||
/// <param name="id">主键ID</param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> DeleteAsync(int id)
|
||||
{
|
||||
using (var _db = DbContext.GetInstance())
|
||||
{
|
||||
return await _db.Deleteable<DbUser>().In(id).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user