| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using bitforum.Models;
- namespace bitforum.Repository
- {
- public class ConfigRepository
- {
- private readonly DefaultDbContext _context;
- public ConfigRepository(DefaultDbContext context)
- {
- _context = context;
- }
-
- public void Add(Config config)
- {
- _context.Config.Add(config);
- _context.SaveChanges();
- }
- // Key로 값 조회
- public Config? GetByKey(string key)
- {
- return _context.Config.FirstOrDefault(c => c.Key == key);
- }
- // 모든 값 조회
- public List<Config> GetAll()
- {
- return _context.Config.ToList();
- }
- // Config 갱신
- public void Update(Config config)
- {
- _context.Config.Update(config);
- _context.SaveChanges();
- }
- // id로 Config 삭제
- public void DeleteByID(int id)
- {
- var config = _context.Config.Find(id);
- if (config != null)
- {
- _context.Config.Remove(config);
- _context.SaveChanges();
- }
- }
- // id로 Config 삭제
- public void DeleteByKey(string key)
- {
- var config = _context.Config.FirstOrDefault(c => c.Key == key);
- if (config != null)
- {
- _context.Config.Remove(config);
- _context.SaveChanges();
- }
- }
- }
- }
|