using Microsoft.EntityFrameworkCore; using TIAM.Database.DbContexts.ServiceProviders; using TIAM.Entities.Users; namespace TIAM.Database.DbSets.Users; public static class UserProductMappingDbSetExtensions { public static IQueryable UserProductMappingsWithRelations(this IUserProductMappingDbSet ctx, bool autoInclude = true) => autoInclude ? ctx.UserProductMappings.Include(x => x.User).Include(x => x.Product) : ctx.UserProductMappings; public static UserProductMapping? GetUserProductMappingById(this IUserProductMappingDbSet ctx, Guid userProductMappingId, bool autoInclude = true) => ctx.UserProductMappingsWithRelations(autoInclude).FirstOrDefault(x => x.Id == userProductMappingId); public static UserProductMapping? GetUserProductMapping(this IUserProductMappingDbSet ctx, Guid userId, Guid productId, bool autoInclude = true) => ctx.UserProductMappingsWithRelations(autoInclude).FirstOrDefault(x => x.UserId == userId && x.ProductId == productId); public static IQueryable GetUserProductMappingsByUserId(this IUserProductMappingDbSet ctx, Guid userId, bool autoInclude = true) => ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.UserId == userId); public static IQueryable GetUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId, bool autoInclude = true) => ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.ProductId == productId); }