42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using ReserveManagementSystemLib.Models;
|
|
using ReserveManagementSystemLib.Persistence;
|
|
|
|
namespace ReserveManagementSystemLib.Repositories
|
|
{
|
|
public class AuditHistoryRepository: BaseRepository, IAuditHistoryRepository
|
|
{
|
|
public AuditHistoryRepository(AppDbContext context) : base(context) { }
|
|
|
|
public IQueryable<AuditHistory> GetAll()
|
|
{
|
|
return _context.AuditHistories;
|
|
}
|
|
|
|
public async Task<AuditHistory> FindByIdAsync(int id)
|
|
{
|
|
return await _context.AuditHistories.FirstOrDefaultAsync(l => l.AuditId == id);
|
|
}
|
|
|
|
public async Task<AuditHistory> AddHistoryAsync(AuditHistory history)
|
|
{
|
|
try
|
|
{
|
|
var newAudit = await _context.AuditHistories.AddAsync(history);
|
|
await _context.SaveChangesAsync();
|
|
return newAudit.Entity;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex, $"Failure to add audit history");
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public async Task<int> AddHistoriesAsync(List<AuditHistory> histories)
|
|
{
|
|
await _context.AuditHistories.AddRangeAsync(histories);
|
|
return await _context.SaveChangesAsync();
|
|
}
|
|
}
|
|
}
|