
This repository contains Transmission RSS Manager with the following changes: - Fixed dark mode navigation tab visibility issue - Improved text contrast in dark mode throughout the app - Created dedicated dark-mode.css for better organization - Enhanced JavaScript for dynamic styling in dark mode - Added complete installation scripts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
90 lines
2.5 KiB
C#
90 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace TransmissionRssManager.Data.Repositories
|
|
{
|
|
public class Repository<T> : IRepository<T> where T : class
|
|
{
|
|
protected readonly TorrentManagerContext _context;
|
|
internal DbSet<T> _dbSet;
|
|
|
|
public Repository(TorrentManagerContext context)
|
|
{
|
|
_context = context;
|
|
_dbSet = context.Set<T>();
|
|
}
|
|
|
|
public virtual async Task<IEnumerable<T>> GetAllAsync()
|
|
{
|
|
return await _dbSet.ToListAsync();
|
|
}
|
|
|
|
public virtual async Task<IEnumerable<T>> FindAsync(Expression<Func<T, bool>> predicate)
|
|
{
|
|
return await _dbSet.Where(predicate).ToListAsync();
|
|
}
|
|
|
|
public virtual async Task<T?> GetByIdAsync(int id)
|
|
{
|
|
return await _dbSet.FindAsync(id);
|
|
}
|
|
|
|
public virtual async Task<T?> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate)
|
|
{
|
|
return await _dbSet.FirstOrDefaultAsync(predicate);
|
|
}
|
|
|
|
public virtual async Task AddAsync(T entity)
|
|
{
|
|
await _dbSet.AddAsync(entity);
|
|
}
|
|
|
|
public virtual async Task AddRangeAsync(IEnumerable<T> entities)
|
|
{
|
|
await _dbSet.AddRangeAsync(entities);
|
|
}
|
|
|
|
public virtual Task UpdateAsync(T entity)
|
|
{
|
|
_dbSet.Attach(entity);
|
|
_context.Entry(entity).State = EntityState.Modified;
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public virtual Task RemoveAsync(T entity)
|
|
{
|
|
_dbSet.Remove(entity);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public virtual Task RemoveRangeAsync(IEnumerable<T> entities)
|
|
{
|
|
_dbSet.RemoveRange(entities);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public virtual async Task<bool> AnyAsync(Expression<Func<T, bool>> predicate)
|
|
{
|
|
return await _dbSet.AnyAsync(predicate);
|
|
}
|
|
|
|
public virtual async Task<int> CountAsync(Expression<Func<T, bool>> predicate)
|
|
{
|
|
return await _dbSet.CountAsync(predicate);
|
|
}
|
|
|
|
public virtual async Task SaveChangesAsync()
|
|
{
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
public virtual IQueryable<T> Query()
|
|
{
|
|
return _dbSet;
|
|
}
|
|
}
|
|
} |