Files
DMS/DMS.Infrastructure/Repositories/DeviceRepository.cs

61 lines
1.9 KiB
C#
Raw Normal View History

2025-07-21 22:02:42 +08:00
using System.Diagnostics;
using AutoMapper;
2025-07-21 22:02:42 +08:00
using DMS.Core.Helper;
2025-07-21 18:49:49 +08:00
using DMS.Core.Interfaces.Repositories;
2025-07-19 09:25:01 +08:00
using DMS.Core.Models;
using DMS.Infrastructure.Data;
2025-07-21 18:49:49 +08:00
using DMS.Infrastructure.Entities;
2025-06-10 22:13:06 +08:00
namespace DMS.Infrastructure.Repositories;
2025-06-10 22:13:06 +08:00
2025-07-21 18:49:49 +08:00
public class DeviceRepository : BaseRepository<DbDevice>, IDeviceRepository
2025-06-10 22:13:06 +08:00
{
2025-07-21 18:49:49 +08:00
private readonly IMapper _mapper;
2025-07-02 22:07:16 +08:00
2025-07-21 18:49:49 +08:00
public DeviceRepository(IMapper mapper, SqlSugarDbContext dbContext)
2025-07-19 22:29:50 +08:00
: base(dbContext)
{
2025-07-21 18:49:49 +08:00
_mapper = mapper;
2025-06-10 22:13:06 +08:00
}
public async Task<List<Core.Models.Device>> GetAllAsync()
2025-07-21 18:49:49 +08:00
{
var dbList = await base.GetAllAsync();
return _mapper.Map<List<Core.Models.Device>>(dbList);
2025-07-21 18:49:49 +08:00
}
public async Task<Core.Models.Device> GetByIdAsync(int id)
2025-07-21 18:49:49 +08:00
{
var dbDevice = await base.GetByIdAsync(id);
return _mapper.Map<Core.Models.Device>(dbDevice);
2025-07-21 18:49:49 +08:00
}
public async Task<Core.Models.Device> AddAsync(Core.Models.Device model)
2025-07-21 18:49:49 +08:00
{
var dbDevice = await base.AddAsync(_mapper.Map<DbDevice>(model));
return _mapper.Map(dbDevice, model);
}
public async Task<int> UpdateAsync(Core.Models.Device model) => await base.UpdateAsync(_mapper.Map<DbDevice>(model));
2025-07-21 18:49:49 +08:00
public async Task<int> DeleteAsync(Core.Models.Device model) => await base.DeleteAsync(_mapper.Map<DbDevice>(model));
2025-07-21 22:02:42 +08:00
public async Task<int> DeleteAsync(int id)
{
var stopwatch = new Stopwatch();
stopwatch.Start();
var result = await Db.Deleteable(new DbDevice() { Id = id })
.ExecuteCommandAsync();
stopwatch.Stop();
NlogHelper.Info($"Delete {typeof(DbDevice)},ID={id},耗时:{stopwatch.ElapsedMilliseconds}ms");
return result;
}
2025-07-22 21:36:33 +08:00
public new async Task<List<Core.Models.Device>> TakeAsync(int number)
2025-07-22 21:36:33 +08:00
{
var dbList = await base.TakeAsync(number);
return _mapper.Map<List<Core.Models.Device>>(dbList);
2025-07-22 21:36:33 +08:00
}
2025-06-10 22:13:06 +08:00
}