28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using System.Security.Cryptography.X509Certificates;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using TIAM.Entities.Users;
|
|
|
|
namespace TIAM.Database.DbSets.Users;
|
|
|
|
public static class UserDbSetExtensions
|
|
{
|
|
public static IQueryable<User> UsersWithProductRelations(this IUserDbSet ctx, bool autoInclude = true)
|
|
=> autoInclude
|
|
? ctx.Users
|
|
.Include(x => x.UserProductMappings)
|
|
.ThenInclude(x => x.Product)
|
|
: ctx.Users;
|
|
|
|
//public static IQueryable<User> UsersWithServiceProviderRelations(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);
|
|
} |