using System.Security.Cryptography.X509Certificates; using AyCode.Database.DbSets.Users; using Microsoft.EntityFrameworkCore; using TIAM.Entities.Users; using TIAM.Models.Dtos.Users; namespace TIAM.Database.DbSets.Users; public static class UserDbSetExtensions { public static IQueryable UsersWithProductRelations(this IUserDbSet ctx, bool autoInclude = true) => autoInclude ? ctx.Users .Include(x => x.UserProductMappings) .ThenInclude(x => x.Product) : ctx.Users; public static User? GetUserById(this IUserDbSet ctx, Guid userId, bool autoInclude) => ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.Id == userId); public static User? GetUserByEmail(this IUserDbSet ctx, string email, bool autoInclude) => ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.EmailAddress == email); public static UserModelDto? GetUserModelDtoById(this IUserDbSet ctx, Guid userId) => ctx.GetUsersById(userId).Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)).FirstOrDefault(); public static UserModelDto? GetUserModelDtoByEmail(this IUserDbSet ctx, string email) => ctx.GetUsersByEmail(email).Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)).FirstOrDefault(); public static IQueryable GetAllUsersModelDto(this IUserDbSet ctx) => ctx.Users.Select(x => new UserModelDto(x, x.Profile, x.UserProductMappings, x.Products)); }