You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.6 KiB
60 lines
1.6 KiB
using Infrastructure.Application.Entites.Settings;
|
|
using Infrastructure.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Linq;
|
|
|
|
namespace Infrastructure.Application.Services.Settings
|
|
{
|
|
public class SettingService : ISettingService
|
|
{
|
|
private readonly ILogger<SettingService> _logger;
|
|
private readonly IRepository<Setting> _settingRepo;
|
|
|
|
public SettingService(ILoggerFactory loggerFactory, IRepository<Setting> settingRepo)
|
|
{
|
|
this._logger = loggerFactory.CreateLogger<SettingService>();
|
|
this._settingRepo = settingRepo;
|
|
}
|
|
|
|
public Setting GetSetting(string name)
|
|
{
|
|
return this._settingRepo.ReadOnlyTable().FirstOrDefault(o => o.Name == name);
|
|
}
|
|
|
|
public void AddSetting(Setting setting)
|
|
{
|
|
try
|
|
{
|
|
this._settingRepo.Add(setting);
|
|
this._settingRepo.SaveChanges();
|
|
}
|
|
catch (DbUpdateException ex)
|
|
{
|
|
this._logger.LogError(ex.Message);
|
|
}
|
|
}
|
|
|
|
public void UpdateSetting(Setting setting)
|
|
{
|
|
this._settingRepo.SaveChanges();
|
|
}
|
|
|
|
public void DeleteSetting(Setting setting)
|
|
{
|
|
this._settingRepo.Delete(setting);
|
|
this._settingRepo.SaveChanges();
|
|
}
|
|
|
|
public IQueryable<Setting> Table()
|
|
{
|
|
return this._settingRepo.Table();
|
|
}
|
|
|
|
public IQueryable<Setting> ReadonlyTable()
|
|
{
|
|
return this._settingRepo.ReadOnlyTable();
|
|
}
|
|
}
|
|
} |