Distribution_GL Initialization

This commit is contained in:
2026-10-20 13:07:07 +05:30
commit 3f16e0cb44
194 changed files with 35659 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;
namespace General_Ledger_Service.Repositories
{
// Shared boilerplate for the GetByIdAsync/ExistsAsync/AddAsync one-liners duplicated across
// most repositories (01_Full_Development_Plan.md Section 10.4) - same shape as
// RecursiveTreeQueries.cs: a parameterized static helper, not a generic repository base class
// (CLAUDE.md Rule 2). Each repository keeps its own public interface/method names and calls
// this internally only where its own method body is literally this one-line shape.
internal static class RepositoryHelpers
{
public static async Task<T?> GetByIdAsync<T>(DbSet<T> set, params object[] keyValues) where T : class =>
await set.FindAsync(keyValues);
public static async Task<bool> ExistsAsync<T>(DbSet<T> set, Expression<Func<T, bool>> predicate) where T : class =>
await set.AnyAsync(predicate);
public static async Task<T> AddAsync<T>(DbSet<T> set, T entity) where T : class
{
await set.AddAsync(entity);
return entity;
}
// Paging is only applied when the caller explicitly supplies both page and pageSize -
// no invented defaults (e.g. page=1/pageSize=20) when either is omitted, so a caller that
// doesn't need paging at a given moment gets the full matching result set back untouched.
public static IQueryable<T> ApplyPaging<T>(IQueryable<T> query, int? page, int? pageSize)
{
if (page.HasValue && pageSize.HasValue)
{
query = query.Skip((page.Value - 1) * pageSize.Value).Take(pageSize.Value);
}
return query;
}
}
}