2025-07-15 22:18:37 +08:00
|
|
|
using AutoMapper;
|
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
|
|
|
|
2025-07-18 22:21:16 +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-06-24 20:48:38 +08:00
|
|
|
{
|
2025-07-21 18:49:49 +08:00
|
|
|
_mapper = mapper;
|
2025-06-10 22:13:06 +08:00
|
|
|
}
|
2025-06-23 17:01:06 +08:00
|
|
|
|
2025-07-21 18:49:49 +08:00
|
|
|
public async Task<List<Device>> GetAllAsync()
|
|
|
|
|
{
|
|
|
|
|
var dbList = await base.GetAllAsync();
|
|
|
|
|
return _mapper.Map<List<Device>>(dbList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Device> GetByIdAsync(int id)
|
|
|
|
|
{
|
|
|
|
|
var dbDevice = await base.GetByIdAsync(id);
|
|
|
|
|
return _mapper.Map<Device>(dbDevice);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Device> AddAsync(Device model)
|
|
|
|
|
{
|
|
|
|
|
var dbDevice = await base.AddAsync(_mapper.Map<DbDevice>(model));
|
|
|
|
|
return _mapper.Map(dbDevice, model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<int> UpdateAsync(Device model) => await base.UpdateAsync(_mapper.Map<DbDevice>(model));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<int> DeleteAsync(Device model) => await base.DeleteAsync(_mapper.Map<DbDevice>(model));
|
2025-06-10 22:13:06 +08:00
|
|
|
}
|