DbContexts, EntityDbSets, EntityExtensions improvemens, fixes, etc..
This commit is contained in:
parent
225c605697
commit
42be674be7
|
|
@ -8,7 +8,7 @@ using AyCode.Entities.ServiceProviders;
|
|||
|
||||
namespace AyCode.Core.Tests.Internal.Entities;
|
||||
|
||||
public class Company : AcCompany<User, UserToCompany, Profile>
|
||||
public class Company : AcCompany<User, UserToCompany, Profile, Address>
|
||||
{
|
||||
|
||||
}
|
||||
|
|
@ -21,14 +21,14 @@ using AyCode.Interfaces.ServiceProviders;
|
|||
|
||||
namespace AyCode.Database.DataLayers.Users
|
||||
{
|
||||
public abstract class AcUserDalBase<TDbContext, TUser, TProfile, TUserToken, TCompany, TUserToServiceProvider, TProfileAddress, TEmailMessage> : AcDalBase<TDbContext>
|
||||
where TDbContext : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToServiceProvider, TProfileAddress, TEmailMessage>
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToServiceProvider, TProfileAddress>
|
||||
where TProfile : class, IAcProfile<TProfileAddress>
|
||||
public abstract class AcUserDalBase<TDbContext, TUser, TProfile, TUserToken, TCompany, TUserToCompany, TAddress, TEmailMessage> : AcDalBase<TDbContext>
|
||||
where TDbContext : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToCompany, TAddress, TEmailMessage>
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToCompany, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TUserToken : class, IAcUserTokenBase
|
||||
where TCompany : class, IAcCompanyBase
|
||||
where TUserToServiceProvider : class, IAcUserToCompanyBase
|
||||
where TProfileAddress : class, IAcAddress
|
||||
where TUserToCompany : class, IAcUserToCompanyBase
|
||||
where TAddress : class, IAcAddress
|
||||
where TEmailMessage : class, IAcEmailMessageBase
|
||||
{
|
||||
public TUser? GetUserById(Guid userId, bool onlyConfirmed) => Session(x => x.GetUserById(userId, onlyConfirmed));
|
||||
|
|
@ -58,7 +58,7 @@ namespace AyCode.Database.DataLayers.Users
|
|||
return TransactionAsync(ctx => ctx.AddUser(user));
|
||||
}
|
||||
|
||||
public Task<bool> AddUserAsync(TUser user, string profileName, TProfileAddress address, string? firstName = null, string? lastName = null)
|
||||
public Task<bool> AddUserAsync(TUser user, string profileName, TAddress address, string? firstName = null, string? lastName = null)
|
||||
{
|
||||
return TransactionAsync(ctx =>
|
||||
{
|
||||
|
|
@ -69,7 +69,7 @@ namespace AyCode.Database.DataLayers.Users
|
|||
});
|
||||
}
|
||||
|
||||
public bool AddUser(TUser user, string profileName, TProfileAddress address, string? firstName = null, string? lastName = null)
|
||||
public bool AddUser(TUser user, string profileName, TAddress address, string? firstName = null, string? lastName = null)
|
||||
{
|
||||
return Transaction(ctx =>
|
||||
{
|
||||
|
|
@ -81,7 +81,7 @@ namespace AyCode.Database.DataLayers.Users
|
|||
});
|
||||
}
|
||||
|
||||
private static TProfile CreateProfile(string profileName, TProfileAddress address, string? firstName, string? lastName)
|
||||
private static TProfile CreateProfile(string profileName, TAddress address, string? firstName, string? lastName)
|
||||
{
|
||||
var profile = Activator.CreateInstance<TProfile>();
|
||||
|
||||
|
|
@ -96,29 +96,8 @@ namespace AyCode.Database.DataLayers.Users
|
|||
return profile;
|
||||
}
|
||||
|
||||
public Task<bool> RemoveUserAsync(TUser? user) => TransactionAsync(ctx => RemoveUserTransactionBody(user, ctx));
|
||||
public Task<bool> RemoveUserAsync(Guid userId) => TransactionAsync(ctx =>
|
||||
{
|
||||
var user = ctx.GetUserById(userId, false);
|
||||
|
||||
return RemoveUserTransactionBody(user, ctx);
|
||||
});
|
||||
|
||||
protected virtual bool RemoveUserTransactionBody(TUser? user, TDbContext ctx)
|
||||
{
|
||||
if (user == null) return false;
|
||||
|
||||
var profile = ctx.Profiles.FirstOrDefault(x => x.Id == user.ProfileId);
|
||||
if (profile != null)
|
||||
{
|
||||
var address = ctx.Addresses.FirstOrDefault(x => x.Id == profile.AddressId);
|
||||
if (address != null) ctx.Addresses.Remove(address);
|
||||
|
||||
ctx.Profiles.Remove(profile);
|
||||
}
|
||||
|
||||
return ctx.RemoveUser(user);
|
||||
}
|
||||
public Task<bool> RemoveUserAsync(TUser user) => TransactionAsync(ctx => ctx.RemoveUser(user));
|
||||
public Task<bool> RemoveUserAsync(Guid userId) => TransactionAsync(ctx => ctx.RemoveUser(userId));
|
||||
|
||||
public TUser? AuthenticateUser(string? email, string? password, string refreshToken, out AcErrorCode errorCode)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,21 +9,21 @@ using Microsoft.EntityFrameworkCore;
|
|||
|
||||
namespace AyCode.Database.DbContexts.Users
|
||||
{
|
||||
public abstract class AcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToServiceProvider, TProfileAddress, TEmailMessage> : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToServiceProvider, TProfileAddress, TEmailMessage>
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToServiceProvider, TProfileAddress>
|
||||
where TProfile : class, IAcProfile<TProfileAddress>
|
||||
public abstract class AcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToCompany, TAddress, TEmailMessage> : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToCompany, TAddress, TEmailMessage>
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToCompany, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TUserToken : class, IAcUserTokenBase
|
||||
where TCompany : class, IAcCompany<TUser, TUserToServiceProvider, TProfile>//IAcServiceProviderBase
|
||||
where TUserToServiceProvider : class, IAcUserToCompanyBase
|
||||
where TProfileAddress : class, IAcAddress
|
||||
where TCompany : class, IAcCompany<TUser, TUserToCompany, TProfile>//IAcServiceProviderBase
|
||||
where TUserToCompany : class, IAcUserToCompanyBase
|
||||
where TAddress : class, IAcAddress
|
||||
where TEmailMessage : class, IAcEmailMessageBase
|
||||
{
|
||||
public required DbSet<TUser> Users { get; set; }
|
||||
public required DbSet<TUserToken> UserTokens { get; set; }
|
||||
public DbSet<TProfileAddress> Addresses { get; set; }
|
||||
public DbSet<TAddress> Addresses { get; set; }
|
||||
public DbSet<TProfile> Profiles { get; set; }
|
||||
public DbSet<TEmailMessage> EmailMessages { get; set; }
|
||||
|
||||
public DbSet<TCompany> Companies { get; set; }
|
||||
|
||||
protected AcUserDbContextBase() : this(string.Empty)
|
||||
{ }
|
||||
|
|
@ -46,8 +46,8 @@ namespace AyCode.Database.DbContexts.Users
|
|||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
new AcUserEntityTypeDefaultConfiguration<TUser, TProfile, TCompany, TUserToServiceProvider, TProfileAddress>().Configure(modelBuilder.Entity<TUser>());
|
||||
new AcProfileEntityTypeDefaultConfiguration<TProfile, TProfileAddress>().Configure(modelBuilder.Entity<TProfile>());
|
||||
new AcUserEntityTypeDefaultConfiguration<TUser, TProfile, TCompany, TUserToCompany, TAddress>().Configure(modelBuilder.Entity<TUser>());
|
||||
new AcProfileEntityTypeDefaultConfiguration<TProfile, TAddress>().Configure(modelBuilder.Entity<TProfile>());
|
||||
|
||||
//new EmailMessageEntityTypeDefaultConfigurations().Configure(modelBuilder.Entity<EmailMessage>());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@ using AyCode.Interfaces.Users;
|
|||
namespace AyCode.Database.DbContexts.Users;
|
||||
|
||||
public interface IAcUserDbContextBase<TUser, TProfile, TUserToken, TCompany, TUserToServiceProvider, TProfileAddress, TEmailMessage>
|
||||
: IAcUserDbSet<TUser, TProfile, TCompany, TUserToServiceProvider, TProfileAddress>, IAcUserTokenDbSet<TUserToken>,
|
||||
IAcAddressDbSetBase<TProfileAddress>, IAcProfileDbSetBase<TProfile>,
|
||||
IAcEmailMessageDbSet<TEmailMessage>
|
||||
: IAcUserDbSetBase<TUser, TProfile, TCompany, TUserToServiceProvider, TProfileAddress>, IAcUserTokenDbSet<TUserToken>, IAcEmailMessageDbSet<TEmailMessage>
|
||||
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToServiceProvider, TProfileAddress>
|
||||
where TProfile : class, IAcProfile<TProfileAddress>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,84 @@
|
|||
using AyCode.Database.DbSets.Profiles;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Interfaces.ServiceProviders;
|
||||
using AyCode.Interfaces.Users;
|
||||
using AyCode.Utils.Extensions;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AyCode.Database.DbSets.Companies;
|
||||
|
||||
public static class AcCompanyDbSetExtensions
|
||||
{
|
||||
#region Add, Update, Remove
|
||||
|
||||
public static bool AddServiceProvider<TCompany, TProfile, TAddress>(this IAcCompanyDbSetBase<TCompany> ctx, TCompany company)
|
||||
where TCompany : class, IAcCompany<TProfile, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
var companyProfile = company.Profile;
|
||||
|
||||
if (company.ProfileId.IsNullOrEmpty() || companyProfile.Id != company.ProfileId || companyProfile.AddressId.IsNullOrEmpty() || companyProfile.Address.Id != companyProfile.AddressId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!company.OwnerId.IsNullOrEmpty())
|
||||
company.AddUser(company.OwnerId.Value, 1);
|
||||
|
||||
return ctx.Companies.Add(company).State == EntityState.Added;
|
||||
}
|
||||
|
||||
public static bool UpdateServiceProvider<TCompany, TProfile, TAddress>(this IAcCompanyDbSetBase<TCompany> ctx, TCompany company)
|
||||
where TCompany : class, IAcCompany<TProfile, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
var companyProfile = company.Profile;
|
||||
|
||||
if (company.ProfileId.IsNullOrEmpty() || companyProfile.Id != company.ProfileId || companyProfile.AddressId.IsNullOrEmpty() || companyProfile.Address.Id != companyProfile.AddressId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
//if (!company.OwnerId.IsNullOrEmpty())
|
||||
//{
|
||||
// companyProfile
|
||||
// company.AddUser(company.OwnerId.Value, 1);
|
||||
//}
|
||||
|
||||
return ctx.Companies.Update(company).State == EntityState.Modified;
|
||||
}
|
||||
|
||||
public static bool RemoveServiceProvider<TCompany, TProfile, TAddress>(this IAcCompanyDbSetBase<TCompany, TProfile, TAddress> ctx, TCompany company)
|
||||
where TCompany : class, IAcCompany<TProfile, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
ctx.RemoveProfile(company.ProfileId);
|
||||
|
||||
return ctx.Companies.Remove(company).State == EntityState.Deleted;
|
||||
}
|
||||
|
||||
public static bool RemoveServiceProvider<TCompany, TProfile, TAddress>(this IAcCompanyDbSetBase<TCompany, TProfile, TAddress> ctx, Guid companyId)
|
||||
where TCompany : class, IAcCompany<TProfile, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
var company = ctx.GetServiceProviderById(companyId);
|
||||
return company == null || ctx.RemoveServiceProvider(company);
|
||||
}
|
||||
|
||||
#endregion Add, Update, Remove
|
||||
|
||||
public static TCompany? GetServiceProviderById<TCompany>(this IAcCompanyDbSetBase<TCompany> ctx, Guid companyId) where TCompany : class, IAcCompanyBase
|
||||
=> ctx.Companies.FirstOrDefault(x => x.Id == companyId);
|
||||
|
||||
public static IQueryable<TCompany> GetServiceProviders<TCompany>(this IAcCompanyDbSetBase<TCompany> ctx) where TCompany : class, IAcCompanyBase
|
||||
=> ctx.Companies;
|
||||
|
||||
public static List<TCompany> GetServiceProvidersByOwnerId<TCompany>(this IAcCompanyDbSetBase<TCompany> ctx, Guid ownerId) where TCompany : class, IAcCompanyBase
|
||||
=> ctx.Companies.Where(x => x.OwnerId == ownerId).ToList();
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using AyCode.Database.DbSets.Profiles;
|
||||
using AyCode.Database.DbSets.Users;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Interfaces.ServiceProviders;
|
||||
using AyCode.Interfaces.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AyCode.Database.DbSets.Companies;
|
||||
|
||||
public interface IAcCompanyDbSetBase<TCompany> where TCompany : class, IAcCompanyBase
|
||||
{
|
||||
DbSet<TCompany> Companies { get; set; }
|
||||
}
|
||||
|
||||
public interface IAcCompanyDbSetBase<TCompany, TProfile> : IAcCompanyDbSetBase<TCompany>, IAcProfileDbSetBase<TProfile>
|
||||
where TCompany : class, IAcCompany<TProfile>
|
||||
where TProfile : class, IAcProfileDtoBase
|
||||
{ }
|
||||
|
||||
public interface IAcCompanyDbSetBase<TCompany, TProfile, TAddress> : IAcCompanyDbSetBase<TCompany, TProfile>, IAcProfileDbSetBase<TProfile, TAddress>
|
||||
where TCompany : class, IAcCompany<TProfile, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{ }
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
using AyCode.Core.Server.Loggers;
|
||||
using AyCode.Database.DbSets.Profiles;
|
||||
using AyCode.Entities;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AyCode.Database.DbSets.Profiles;
|
||||
|
||||
public static class AcProfileDbSetExtensions
|
||||
{
|
||||
public static TProfile? GetProfileById<TProfile>(this IAcProfileDbSetBase<TProfile> ctx, Guid profileId) where TProfile : class, IAcProfileDtoBase
|
||||
=> ctx.Profiles.FirstOrDefault(u => u.Id == profileId);
|
||||
|
||||
public static bool AddProfile<TProfile>(this IAcProfileDbSetBase<TProfile> ctx, TProfile profile) where TProfile : class, IAcProfileDtoBase
|
||||
{
|
||||
return ctx.Profiles.Add(profile).State == EntityState.Added;
|
||||
}
|
||||
|
||||
public static bool RemoveProfile<TProfile, TAddress>(this IAcProfileDbSetBase<TProfile, TAddress> ctx, TProfile profile)
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
var address = ctx.Addresses.FirstOrDefault(x => x.Id == profile.AddressId);
|
||||
if (address != null) ctx.Addresses.Remove(address);
|
||||
|
||||
return ctx.Profiles.Remove(profile).State == EntityState.Deleted;
|
||||
}
|
||||
|
||||
public static bool RemoveProfile<TProfile, TAddress>(this IAcProfileDbSetBase<TProfile, TAddress> ctx, Guid profileId)
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
var profile = ctx.GetProfileById(profileId);
|
||||
|
||||
return profile != null && ctx.RemoveProfile(profile);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,7 @@
|
|||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Database.DbSets.Addresses;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Interfaces.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
|
@ -7,4 +10,10 @@ namespace AyCode.Database.DbSets.Profiles;
|
|||
public interface IAcProfileDbSetBase<TProfile> where TProfile : class, IAcProfileDtoBase
|
||||
{
|
||||
DbSet<TProfile> Profiles { get; set; }
|
||||
}
|
||||
|
||||
public interface IAcProfileDbSetBase<TProfile, TAddress> : IAcProfileDbSetBase<TProfile>, IAcAddressDbSetBase<TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
}
|
||||
|
|
@ -1,13 +1,18 @@
|
|||
using AyCode.Core.Extensions;
|
||||
using AyCode.Core.Loggers;
|
||||
using AyCode.Core.Server.Loggers;
|
||||
using AyCode.Database.DbSets.Profiles;
|
||||
using AyCode.Database.Extensions;
|
||||
using AyCode.Entities;
|
||||
using AyCode.Entities.Users;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Interfaces.ServiceProviders;
|
||||
using AyCode.Interfaces.Users;
|
||||
using AyCode.Models.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AyCode.Database.DbSets.Users;
|
||||
|
||||
|
|
@ -58,21 +63,29 @@ public static class AcUserDbSetExtensions
|
|||
{
|
||||
var emailLower = user.EmailAddress.ToLower();
|
||||
|
||||
GlobalLogger.Info($"GetUserByEmail: {emailLower}");
|
||||
GlobalLogger.Info($"AddUser: {emailLower}");
|
||||
|
||||
return ctx.Users.Add(user).State == Microsoft.EntityFrameworkCore.EntityState.Added;
|
||||
return ctx.Users.Add(user).State == EntityState.Added;
|
||||
}
|
||||
|
||||
public static bool RemoveUser<TUser>(this IAcUserDbSetBase<TUser> ctx, TUser user) where TUser : class, IAcUserBase
|
||||
=> ctx.Users.Remove(user).State == Microsoft.EntityFrameworkCore.EntityState.Deleted;
|
||||
public static bool RemoveUser<TUser, TProfile, TAddress>(this IAcUserDbSetBase<TUser, TProfile, TAddress> ctx, TUser user)
|
||||
where TUser : class, IAcUser<TProfile, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
ctx.RemoveProfile(user.ProfileId);
|
||||
|
||||
public static bool RemoveUser<TUser>(this IAcUserDbSetBase<TUser> ctx, Guid userId) where TUser : class, IAcUserBase
|
||||
return ctx.Users.Remove(user).State == EntityState.Deleted;
|
||||
}
|
||||
|
||||
public static bool RemoveUser<TUser, TProfile, TAddress>(this IAcUserDbSetBase<TUser, TProfile, TAddress> ctx, Guid userId)
|
||||
where TUser : class, IAcUser<TProfile, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
var user = ctx.GetUserById(userId, false);
|
||||
|
||||
if (user == null) return false;
|
||||
|
||||
return ctx.RemoveUser(user);
|
||||
return user != null && ctx.RemoveUser(user);
|
||||
}
|
||||
|
||||
public static bool UpdateJwtRefreshToken<TUser>(this IAcUserDbSetBase<TUser> ctx, TUser user, string refreshToken) where TUser : class, IAcUserBase
|
||||
|
|
|
|||
|
|
@ -1,15 +0,0 @@
|
|||
using AyCode.Database.DbContexts;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using AyCode.Interfaces.ServiceProviders;
|
||||
using AyCode.Interfaces.Users;
|
||||
|
||||
namespace AyCode.Database.DbSets.Users;
|
||||
|
||||
public interface IAcUserDbSet<TUser, TProfile, TCompany, TUserToServiceProvider, TProfileAddress> : IAcUserDbSetBase<TUser>
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToServiceProvider, TProfileAddress>
|
||||
where TProfile : class, IAcProfile<TProfileAddress>
|
||||
where TCompany : class, IAcCompanyBase
|
||||
where TUserToServiceProvider : class, IAcUserToCompanyBase
|
||||
where TProfileAddress : class, IAcAddress
|
||||
{ }
|
||||
|
|
@ -1,4 +1,10 @@
|
|||
using AyCode.Interfaces.Users;
|
||||
using AyCode.Database.DbSets.Addresses;
|
||||
using AyCode.Database.DbSets.Companies;
|
||||
using AyCode.Database.DbSets.Profiles;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using AyCode.Interfaces.ServiceProviders;
|
||||
using AyCode.Interfaces.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace AyCode.Database.DbSets.Users;
|
||||
|
|
@ -6,4 +12,25 @@ namespace AyCode.Database.DbSets.Users;
|
|||
public interface IAcUserDbSetBase<TUser> where TUser : class, IAcUserBase
|
||||
{
|
||||
DbSet<TUser> Users { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public interface IAcUserDbSetBase<TUser, TProfile, TAddress> : IAcUserDbSetBase<TUser>, IAcProfileDbSetBase<TProfile, TAddress>
|
||||
where TUser : class, IAcUserBase
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{ }
|
||||
|
||||
public interface IAcUserDbSetBase<TUser, TProfile, TCompany, TAddress> : IAcUserDbSetBase<TUser, TProfile, TAddress>, IAcCompanyDbSetBase<TCompany>
|
||||
where TUser : class, IAcUserBase
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TCompany : class, IAcCompanyBase
|
||||
where TAddress : class, IAcAddress
|
||||
{ }
|
||||
|
||||
public interface IAcUserDbSetBase<TUser, TProfile, TCompany, TUserToCompany, TAddress> : IAcUserDbSetBase<TUser, TProfile, TCompany, TAddress>
|
||||
where TUser : class, IAcUserBase, IAcUser<TProfile, TCompany, TUserToCompany, TAddress>
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TCompany : class, IAcCompanyBase
|
||||
where TUserToCompany : class, IAcUserToCompanyBase
|
||||
where TAddress : class, IAcAddress
|
||||
{ }
|
||||
|
|
@ -7,17 +7,38 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
|||
|
||||
namespace AyCode.Database.ModelBuilders.Users;
|
||||
|
||||
public class AcUserEntityTypeDefaultConfiguration<TUser, TProfile, TCompany, TUserToServiceProvider, TProfileAddress> : IAcEntityTypeConfiguration<TUser>
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToServiceProvider, TProfileAddress>
|
||||
public class AcUserEntityTypeDefaultConfiguration<TUser, TProfile, TCompany, TUserToCompany, TProfileAddress> : IAcEntityTypeConfiguration<TUser>
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToCompany, TProfileAddress>
|
||||
where TProfile : class, IAcProfile<TProfileAddress>
|
||||
where TCompany : class, IAcCompany<TUser, TUserToServiceProvider, TProfile>
|
||||
where TUserToServiceProvider : class, IAcUserToCompanyBase
|
||||
where TCompany : class, IAcCompany<TUser, TUserToCompany, TProfile>
|
||||
where TUserToCompany : class, IAcUserToCompanyBase
|
||||
where TProfileAddress : class, IAcAddress
|
||||
{
|
||||
public virtual void Configure(EntityTypeBuilder<TUser> modelBuilder)
|
||||
{
|
||||
modelBuilder.BuildEntityToProfileRelation<TUser, TProfile>();
|
||||
//modelBuilder.BuildEntityToAddressRelation<TProfileAddress, TProfile, TProfileAddress>();
|
||||
modelBuilder.BuildEntityToServiceProviderRelation<TUser, TCompany, TUserToServiceProvider, TProfile>();
|
||||
modelBuilder.BuildEntityToServiceProviderRelation<TUser, TCompany, TUserToCompany, TProfile>();
|
||||
}
|
||||
}
|
||||
|
||||
public class AcCompanyEntityTypeDefaultConfiguration<TCompany, TProfile, TProfileAddress, TUserToCompany, TUser> : IAcEntityTypeConfiguration<TCompany>
|
||||
where TUser : class, IAcUser<TProfile, TCompany, TUserToCompany, TProfileAddress>
|
||||
where TProfile : class, IAcProfile<TProfileAddress>
|
||||
where TCompany : class, IAcCompany<TUser, TUserToCompany, TProfile>
|
||||
where TUserToCompany : class, IAcUserToCompanyBase
|
||||
where TProfileAddress : class, IAcAddress
|
||||
{
|
||||
public virtual void Configure(EntityTypeBuilder<TCompany> modelBuilder)
|
||||
{
|
||||
modelBuilder.BuildEntityToProfileRelation<TCompany, TProfile>();
|
||||
|
||||
//modelBuilder
|
||||
// .HasMany(e => e.Users)
|
||||
// .WithMany(e => e.ServiceProviders)
|
||||
// .UsingEntity<TUserToCompany>();
|
||||
|
||||
//modelBuilder.Navigation(e => e.Users).AutoInclude();
|
||||
modelBuilder.Navigation(e => e.UserToServiceProviders).AutoInclude();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Interfaces.ServiceProviders;
|
||||
using AyCode.Interfaces.Users;
|
||||
|
|
@ -9,10 +11,11 @@ using AyCode.Utils.Extensions;
|
|||
namespace AyCode.Entities.ServiceProviders
|
||||
{
|
||||
[Table("ServiceProviders")]
|
||||
public abstract class AcCompany<TUser, TUserToServiceProvider, TProfile> : IAcCompany<TUser, TUserToServiceProvider, TProfile>
|
||||
public abstract class AcCompany<TUser, TUserToCompany, TProfile, TAddress> : IAcCompany<TUser, TUserToCompany, TProfile, TAddress>
|
||||
where TUser : class, IAcUserBase
|
||||
where TUserToServiceProvider : class, IAcUserToCompanyBase
|
||||
where TProfile : class, IAcProfileDtoBase
|
||||
where TUserToCompany : class, IAcUserToCompanyBase
|
||||
where TProfile : class, IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public Guid Id { get; set; }
|
||||
|
|
@ -33,8 +36,8 @@ namespace AyCode.Entities.ServiceProviders
|
|||
public Guid AffiliateId { get; set; }
|
||||
public Guid? ReferralId { get; set; }
|
||||
|
||||
public virtual List<TUser> Users { get; set; }
|
||||
public virtual List<TUserToServiceProvider> UserToServiceProviders { get; set; }
|
||||
public virtual List<TUser> Users { get; set; } = [];
|
||||
public virtual List<TUserToCompany> UserToServiceProviders { get; set; } = [];
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
|
|
@ -69,5 +72,20 @@ namespace AyCode.Entities.ServiceProviders
|
|||
Profile = profile;
|
||||
ProfileId = profile.Id;
|
||||
}
|
||||
|
||||
public void AddUser(Guid userId, int permissions)
|
||||
{
|
||||
if (UserToServiceProviders.Any(x => x.UserId == userId))
|
||||
return;
|
||||
|
||||
var userToCompany = Activator.CreateInstance<TUserToCompany>();
|
||||
|
||||
userToCompany.Id = Guid.NewGuid();
|
||||
userToCompany.UserId = userId;
|
||||
userToCompany.ServiceProviderId = Id;
|
||||
userToCompany.Permissions = permissions;
|
||||
|
||||
UserToServiceProviders.Add(userToCompany);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,31 @@
|
|||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Interfaces.Addresses;
|
||||
using AyCode.Interfaces.Profiles.Dtos;
|
||||
using AyCode.Interfaces.Profiles;
|
||||
using AyCode.Interfaces.Users;
|
||||
|
||||
namespace AyCode.Interfaces.ServiceProviders;
|
||||
|
||||
public interface IAcCompany<TUser, TUserToServiceProvider, TProfile> : IAcCompanyBase, IAcUsersRelation<TUser, TUserToServiceProvider>, IAcProfileRelation<TProfile>
|
||||
where TUser : IAcUserBase
|
||||
where TUserToServiceProvider : IAcUserToCompanyBase
|
||||
public interface IAcCompany<TProfile> : IAcCompanyBase, IAcProfileRelation<TProfile>
|
||||
where TProfile : IAcProfileDtoBase
|
||||
{
|
||||
public void SetProfile(TProfile profile);
|
||||
}
|
||||
|
||||
public interface IAcCompany<TProfile, TAddress> : IAcCompany<TProfile>
|
||||
where TProfile : IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{}
|
||||
|
||||
|
||||
public interface IAcCompany<TUser, TUserToCompany, TProfile> : IAcCompany<TProfile>, IAcUsersRelation<TUser, TUserToCompany>
|
||||
where TUser : IAcUserBase
|
||||
where TUserToCompany : IAcUserToCompanyBase
|
||||
where TProfile : IAcProfileDtoBase
|
||||
{}
|
||||
|
||||
public interface IAcCompany<TUser, TUserToCompany, TProfile, TAddress> : IAcCompany<TUser, TUserToCompany, TProfile>, IAcCompany<TProfile, TAddress>
|
||||
where TUser : IAcUserBase
|
||||
where TUserToCompany : IAcUserToCompanyBase
|
||||
where TProfile : IAcProfile<TAddress>
|
||||
where TAddress : class, IAcAddress
|
||||
{}
|
||||
|
|
@ -14,4 +14,6 @@ public interface IAcCompanyBase : IEntityGuid, IAcProfileForeignKey, ITimeStampI
|
|||
|
||||
Guid AffiliateId { get; set; }
|
||||
Guid? ReferralId { get; set; }
|
||||
|
||||
public void AddUser(Guid userId, int permissions);
|
||||
}
|
||||
|
|
@ -4,10 +4,14 @@ using AyCode.Interfaces.Addresses;
|
|||
|
||||
namespace AyCode.Interfaces.Users.Dtos;
|
||||
|
||||
public interface IAcUserDtoBase<TProfile, TCompany, TUserToServiceProvider, TProfileAddress> : IAcUserDtoMinBase<TProfile>, IAcCompanyRelation<TCompany, TUserToServiceProvider>
|
||||
where TProfile : IAcProfile<TProfileAddress>
|
||||
public interface IAcUserDtoBase<TProfile, TAddress> : IAcUserDtoMinBase<TProfile>
|
||||
where TProfile : IAcProfile<TAddress>
|
||||
where TAddress : IAcAddress
|
||||
{ }
|
||||
|
||||
public interface IAcUserDtoBase<TProfile, TCompany, TUserToCompany, TAddress> : IAcUserDtoBase<TProfile, TAddress>, IAcCompanyRelation<TCompany, TUserToCompany>
|
||||
where TProfile : IAcProfile<TAddress>
|
||||
where TCompany : IAcCompanyBase
|
||||
where TUserToServiceProvider : IAcUserToCompanyBase
|
||||
where TProfileAddress : IAcAddress
|
||||
{
|
||||
}
|
||||
where TUserToCompany : IAcUserToCompanyBase
|
||||
where TAddress : IAcAddress
|
||||
{ }
|
||||
|
|
@ -4,10 +4,14 @@ using AyCode.Interfaces.ServiceProviders;
|
|||
|
||||
namespace AyCode.Interfaces.Users.Dtos;
|
||||
|
||||
public interface IAcUserDtoDetailBase<TProfile, TCompany, TUserToServiceProvider, TProfileAddress> : IAcUserBase, IAcUserDtoBase<TProfile, TCompany, TUserToServiceProvider, TProfileAddress>
|
||||
where TProfile : IAcProfile<TProfileAddress>
|
||||
public interface IAcUserDtoDetailBase<TProfile, TAddress> : IAcUserBase, IAcUserDtoBase<TProfile, TAddress>
|
||||
where TProfile : IAcProfile<TAddress>
|
||||
where TAddress : IAcAddress
|
||||
{ }
|
||||
|
||||
public interface IAcUserDtoDetailBase<TProfile, TCompany, TUserToCompany, TAddress> : IAcUserDtoDetailBase<TProfile, TAddress>, IAcUserDtoBase<TProfile, TCompany, TUserToCompany, TAddress>
|
||||
where TProfile : IAcProfile<TAddress>
|
||||
where TCompany : IAcCompanyBase
|
||||
where TUserToServiceProvider : IAcUserToCompanyBase
|
||||
where TProfileAddress : IAcAddress
|
||||
{
|
||||
}
|
||||
where TUserToCompany : IAcUserToCompanyBase
|
||||
where TAddress : IAcAddress
|
||||
{ }
|
||||
|
|
@ -6,9 +6,14 @@ using AyCode.Interfaces.Users.Dtos;
|
|||
|
||||
namespace AyCode.Interfaces.Users;
|
||||
|
||||
public interface IAcUser<TProfile, TCompany, TUserToServiceProvider, TProfileAddress> : IAcUserDtoDetailBase<TProfile, TCompany, TUserToServiceProvider, TProfileAddress>, IAcProfileForeignKey
|
||||
where TProfile : IAcProfile<TProfileAddress>
|
||||
public interface IAcUser<TProfile, TAddress> : IAcUserDtoDetailBase<TProfile, TAddress>
|
||||
where TProfile : IAcProfile<TAddress>
|
||||
where TAddress : IAcAddress
|
||||
{ }
|
||||
|
||||
public interface IAcUser<TProfile, TCompany, TUserToCompany, TAddress> : IAcUser<TProfile, TAddress>, IAcUserDtoDetailBase<TProfile, TCompany, TUserToCompany, TAddress>
|
||||
where TProfile : IAcProfile<TAddress>
|
||||
where TCompany : IAcCompanyBase
|
||||
where TUserToServiceProvider : IAcUserToCompanyBase
|
||||
where TProfileAddress : IAcAddress
|
||||
where TUserToCompany : IAcUserToCompanyBase
|
||||
where TAddress : IAcAddress
|
||||
{ }
|
||||
Loading…
Reference in New Issue