Repositories inserted and new page for accounts inserted
This commit is contained in:
58
WinFormDi.BLR/AccountRecordRepository.cs
Normal file
58
WinFormDi.BLR/AccountRecordRepository.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WinFormDiApp.BL.Models;
|
||||
using WinFormDiApp.BLI;
|
||||
using WinFormDiApp.DAL;
|
||||
|
||||
namespace WinFormDiApp.BLR;
|
||||
|
||||
public class AccountRecordRepository : IAccountRecordRepository
|
||||
{
|
||||
private readonly ApplicationDbContext _dataContext;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly ILogger<AccountRecordRepository> _logger;
|
||||
|
||||
public AccountRecordRepository(ApplicationDbContext dataContext, IConfiguration configuration, ILogger<AccountRecordRepository> logger)
|
||||
{
|
||||
_dataContext = dataContext;
|
||||
_configuration = configuration;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public bool AddAccountRecord(AccountRecord record)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dataContext.AccountRecords.Add(record);
|
||||
_dataContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError($"Error occured in AddAccountRecord :{e.Message}");
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public bool DeleteAccountRecord(AccountRecord record)
|
||||
{
|
||||
try
|
||||
{
|
||||
_dataContext.AccountRecords.Remove(record);
|
||||
_dataContext.SaveChanges();
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError($"Error occured in DeleteAccountRecord :{e.Message}");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEnumerable<AccountRecord> GetAllAccounts()
|
||||
{
|
||||
return _dataContext.AccountRecords;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user