Compare commits

...

3 Commits

Author SHA1 Message Date
jozsef.b@aycode.com 4be03c3998 Impelement ServicProvider and Mapping to AcUserModel; refactoring, improvements, fixes, etc... 2023-12-22 06:13:21 +01:00
jozsef.b@aycode.com 02a4c197b4 refactoring, improvements, fixes, etc... 2023-12-20 02:51:05 +01:00
jozsef.b@aycode.com ede481f858 UserModels, Tests improvements, fixes 2023-12-19 11:41:04 +01:00
45 changed files with 483 additions and 211 deletions

View File

@ -2,42 +2,46 @@
using AyCode.Database.DbContexts;
using AyCode.Database.DbContexts.Users;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
namespace AyCode.Database.Tests.Users
{
public abstract class AcUserDalTestBase<TDal, TDbContext, TUser, TProfile, TUserToken> : AcDatabaseTestModelBase<TDal, TDbContext>
where TDal : AcUserDalBase<TDbContext, TUser, TProfile, TUserToken>
where TDbContext : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken>
where TUser : class, IUserBase<TProfile>
where TProfile : class, IAcProfileBase
where TUserToken : class, IUserTokenBase
public abstract class AcUserDalTestBase<TDal, TDbContext, TUser, TProfile, TUserToken, TServiceProvider, TUserToServiceProvider> : AcDatabaseTestModelBase<TDal, TDbContext>
where TDal : AcUserDalBase<TDbContext, TUser, TProfile, TUserToken, TServiceProvider, TUserToServiceProvider>
where TDbContext : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken,TServiceProvider, TUserToServiceProvider>
where TUser : class, IAcUser<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TUserToken : class, IAcUserTokenBase
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
[TestMethod]
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
public virtual void GetUserById_ReturnsUser_WhenUserExists(string userIdString)
protected TUser AcBase_GetUserById_ReturnsUser_WhenUserExists(string userIdString)
{
var userId = Guid.Parse(userIdString);
var user = Dal.GetUserById(userId);
Assert.IsNotNull(user, "User is null");
Assert.IsNotNull(user.Profile, "Profile is null");
Assert.AreEqual(userId, user.Id);
return user;
}
[TestMethod]
[DataRow("test@tiam.hu")]
public virtual void GetUserByEmail_ReturnsUser_WhenUserExists(string email)
protected TUser AcBase_GetUserByEmail_ReturnsUser_WhenUserExists(string email)
{
var user = Dal.GetUserByEmail(email);
Assert.IsNotNull(user, "User is null");
Assert.IsNotNull(user.Profile, "Profile is null");
Assert.AreEqual(email, user.EmailAddress);
return user;
}
[TestMethod]
[DataRow("test@tiam.hu")]
public virtual async Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
protected async Task<TUser> AcBase_GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
{
TUser? user = null;
@ -51,7 +55,11 @@ namespace AyCode.Database.Tests.Users
//}
Assert.IsNotNull(user, "User is null");
Assert.IsNotNull(user.Profile, "Profile is null");
Assert.AreEqual(email, user.EmailAddress);
return user;
}
}
}

View File

@ -12,14 +12,17 @@ using AyCode.Database.Extensions;
using AyCode.Core.Consts;
using AyCode.Database.DbSets.Users;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
namespace AyCode.Database.DataLayers.Users
{
public abstract class AcUserDalBase<TDbContext, TUser, TProfile, TUserToken> : AcDalBase<TDbContext>
where TDbContext : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken>
where TUser : class, IUserBase<TProfile>
where TProfile : class, IAcProfileBase
where TUserToken : class, IUserTokenBase
public abstract class AcUserDalBase<TDbContext, TUser, TProfile, TUserToken, TServiceProvider, TUserToServiceProvider> : AcDalBase<TDbContext>
where TDbContext : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken, TServiceProvider, TUserToServiceProvider>
where TUser : class, IAcUser<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TUserToken : class, IAcUserTokenBase
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
public TUser? GetUserById(Guid userId) => Session(x => x.GetUserById(userId));
public Task<TUser?> GetUserByIdAsync(Guid userId) => SessionAsync(x => x.GetUserById(userId));

View File

@ -11,7 +11,7 @@ namespace AyCode.Database.DataLayers.Users
{
public static class AcUserDalExtension
{
//public static bool DeleteUser(this IAcUserDbContextBase ctx, IUserBase user)
//public static bool DeleteUser(this IAcUserDbContextBase ctx, IAcUser user)
//{
// if (user == null) return false;
@ -48,7 +48,7 @@ namespace AyCode.Database.DataLayers.Users
// return ctx.SetUserConsentsToAccepted(user);
//}
//public static bool SetUserConsentsToAccepted(this AcUserDbContextBase ctx, IUserBase? user)
//public static bool SetUserConsentsToAccepted(this AcUserDbContextBase ctx, IAcUser? user)
//{
// if (!user.EmailConfirmed) return false; //Ez nem kéne ide... - J.
@ -76,7 +76,7 @@ namespace AyCode.Database.DataLayers.Users
//public static void UsernameAndEmailAvailable(this IUserDal userDal, string username, string email, Action<bool, AcErrorCode, AspNetUser> callback)
//{
// IUserBase notConfirmedUser = null;
// IAcUser notConfirmedUser = null;
// var lowerEmail = email.ToLower();
// var lowerUserName = username.ToLower();
@ -106,7 +106,7 @@ namespace AyCode.Database.DataLayers.Users
//}
//public static void AddNewUser(this IUserDal userDal, IUserBase newUser, Action<AspNetUser> callback)
//public static void AddNewUser(this IUserDal userDal, IAcUser newUser, Action<AspNetUser> callback)
//{
// userDal.Add(newUser);
// callback(newUser);

View File

@ -4,15 +4,18 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore;
namespace AyCode.Database.DbContexts.Users
{
public abstract class AcUserDbContextBase<TUser, TProfile, TUserToken> : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken>
where TUser : class, IUserBase<TProfile>
where TProfile : class, IAcProfileBase
where TUserToken : class, IUserTokenBase
public abstract class AcUserDbContextBase<TUser, TProfile, TUserToken, TServiceProvider, TUserToServiceProvider> : AcDbContextBase, IAcUserDbContextBase<TUser, TProfile, TUserToken, TServiceProvider, TUserToServiceProvider>
where TUser : class, IAcUser<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TUserToken : class, IAcUserTokenBase
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
public required DbSet<TUser> Users { get; set; }
public required DbSet<TUserToken> UserTokens { get; set; }

View File

@ -1,13 +1,16 @@
using AyCode.Database.DbSets.Users;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore;
namespace AyCode.Database.DbContexts.Users;
public interface IAcUserDbContextBase<TUser, TProfile, TUserToken> : IAcUserDbSet<TUser, TProfile>, IAcUserTokenDbSet<TUserToken>
where TUser : class, IUserBase<TProfile>
where TProfile : class, IAcProfileBase
where TUserToken : class, IUserTokenBase
public interface IAcUserDbContextBase<TUser, TProfile, TUserToken, TServiceProvider, TUserToServiceProvider> : IAcUserDbSet<TUser, TProfile, TServiceProvider, TUserToServiceProvider>, IAcUserTokenDbSet<TUserToken>
where TUser : class, IAcUser<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TUserToken : class, IAcUserTokenBase
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
}

View File

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore;
namespace AyCode.Database.DbContexts.Users;
public interface IAcUserTokenDbContextBase<TUserToken> where TUserToken : class, IUserTokenBase
public interface IAcUserTokenDbContextBase<TUserToken> where TUserToken : class, IAcUserTokenBase
{
DbSet<TUserToken> UserToken { get; set; }
}

View File

@ -7,16 +7,16 @@ namespace AyCode.Database.DbSets.Users;
public static class AcUserDbSetExtensions
{
public static TUser? GetUserById<TUser, TProfile>(this IAcUserDbSet<TUser, TProfile> ctx, Guid userId) where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
public static TUser? GetUserById<TUser>(this IAcUserDbSetBase<TUser> ctx, Guid userId) where TUser : class, IAcUserBase
=> ctx.GetUsersById(userId).FirstOrDefault();
public static TUser? GetUserByEmail<TUser, TProfile>(this IAcUserDbSet<TUser, TProfile> ctx, string email) where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
public static TUser? GetUserByEmail<TUser>(this IAcUserDbSetBase<TUser> ctx, string email) where TUser : class, IAcUserBase
=> ctx.GetUsersByEmail(email).FirstOrDefault();
public static IQueryable<TUser> GetUsersById<TUser, TProfile>(this IAcUserDbSet<TUser, TProfile> ctx, Guid userId) where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
public static IQueryable<TUser> GetUsersById<TUser>(this IAcUserDbSetBase<TUser> ctx, Guid userId) where TUser : class, IAcUserBase
=> ctx.Users.Where(u => u.Id == userId);
public static IQueryable<TUser> GetUsersByEmail<TUser, TProfile>(this IAcUserDbSet<TUser, TProfile> ctx, string email) where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
public static IQueryable<TUser> GetUsersByEmail<TUser>(this IAcUserDbSetBase<TUser> ctx, string email) where TUser : class, IAcUserBase
{
Logger.Info($"GetUserByEmail: {email}");

View File

@ -6,10 +6,9 @@ namespace AyCode.Database.DbSets.Users;
public static class AcUserTokenDbSetExtensions
{
public static bool ChangePassword<TUser, TProfile, TUserToken>(this IAcUserDbContextBase<TUser, TProfile, TUserToken> ctx, TUser? user, string passwordHash, string verificationToken)
where TUser : class, IUserBase<TProfile>
where TProfile : class, IAcProfileBase
where TUserToken : class, IUserTokenBase
public static bool ChangePassword<TUser, TUserToken>(this IAcUserChangePasswordDbSet<TUser, TUserToken> ctx, TUser? user, string passwordHash, string verificationToken)
where TUser : class, IAcUserBase
where TUserToken : class, IAcUserTokenBase
{
if (user == null || !ctx.IsValidToken(user.Id, verificationToken)) return false;
@ -21,7 +20,7 @@ public static class AcUserTokenDbSetExtensions
return true;
}
public static TUserToken? UpdateUserTokenSent<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId, string verificationToken, DateTime tokenSentUtc) where TUserToken : class, IUserTokenBase
public static TUserToken? UpdateUserTokenSent<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId, string verificationToken, DateTime tokenSentUtc) where TUserToken : class, IAcUserTokenBase
{
var userToken = ctx.GetUserToken(userId, verificationToken);
@ -37,7 +36,7 @@ public static class AcUserTokenDbSetExtensions
return userToken;
}
public static TUserToken CreateUserToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId, string verificationToken) where TUserToken : class, IUserTokenBase
public static TUserToken CreateUserToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId, string verificationToken) where TUserToken : class, IAcUserTokenBase
{
var userToken = Activator.CreateInstance<TUserToken>();
userToken.UserId = userId;
@ -46,7 +45,7 @@ public static class AcUserTokenDbSetExtensions
return ctx.CreateUserToken(userToken);
}
public static TUserToken CreateUserToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, TUserToken userToken) where TUserToken : class, IUserTokenBase
public static TUserToken CreateUserToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, TUserToken userToken) where TUserToken : class, IAcUserTokenBase
{
ctx.DeactivateTokens(userToken.UserId);
@ -56,16 +55,16 @@ public static class AcUserTokenDbSetExtensions
return userToken;
}
public static TUserToken? GetActiveUserToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId) where TUserToken : class, IUserTokenBase
public static TUserToken? GetActiveUserToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId) where TUserToken : class, IAcUserTokenBase
=> ctx.UserTokens.SingleOrDefault(x => x.UserId == userId && x.IsActive && (x.TokenExpiration == null || x.TokenExpiration > DateTime.UtcNow));
public static TUserToken? GetUserToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId, string verificationToken) where TUserToken : class, IUserTokenBase
public static TUserToken? GetUserToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId, string verificationToken) where TUserToken : class, IAcUserTokenBase
=> ctx.UserTokens.SingleOrDefault(x => x.UserId == userId && x.Token == verificationToken);
public static bool IsValidToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId, string verificationToken) where TUserToken : class, IUserTokenBase
public static bool IsValidToken<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId, string verificationToken) where TUserToken : class, IAcUserTokenBase
=> ctx.UserTokens.Any(x => x.UserId == userId && x.IsActive && x.Token == verificationToken && x.TokenExpiration > DateTime.UtcNow && x.TokenSent < DateTime.UtcNow);
public static void DeactivateTokens<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId) where TUserToken : class, IUserTokenBase
public static void DeactivateTokens<TUserToken>(this IAcUserTokenDbSet<TUserToken> ctx, Guid userId) where TUserToken : class, IAcUserTokenBase
{
var activeUserTokens = ctx.UserTokens.Where(x => x.UserId == userId && x.IsActive);

View File

@ -0,0 +1,10 @@
using AyCode.Interfaces.Users;
namespace AyCode.Database.DbSets.Users;
public interface IAcUserChangePasswordDbSet<TUser, TUserToken> : IAcUserDbSetBase<TUser>, IAcUserTokenDbSet<TUserToken>
where TUser : class, IAcUserBase
where TUserToken : class, IAcUserTokenBase
{
}

View File

@ -1,13 +1,13 @@
using AyCode.Database.DbContexts;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore;
namespace AyCode.Database.DbSets.Users;
public interface IAcUserDbSet<TUser, TProfile>
where TUser : class, IUserBase<TProfile>
where TProfile : class, IAcProfileBase
{
DbSet<TUser> Users { get; set; }
}
public interface IAcUserDbSet<TUser, TProfile, TServiceProvider, TUserToServiceProvider> : IAcUserDbSetBase<TUser>
where TUser : class, IAcUser<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{ }

View File

@ -0,0 +1,9 @@
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore;
namespace AyCode.Database.DbSets.Users;
public interface IAcUserDbSetBase<TUser> where TUser : class, IAcUserBase
{
DbSet<TUser> Users { get; set; }
}

View File

@ -3,7 +3,7 @@ using Microsoft.EntityFrameworkCore;
namespace AyCode.Database.DbSets.Users;
public interface IAcUserTokenDbSet<TUserToken> where TUserToken : class, IUserTokenBase
public interface IAcUserTokenDbSet<TUserToken> where TUserToken : class, IAcUserTokenBase
{
DbSet<TUserToken> UserTokens { get; set; }
}

View File

@ -1,17 +1,45 @@
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Formats.Tar;
using AyCode.Interfaces.ServiceProviders;
namespace AyCode.Database.ModelBuilders.Users;
public static class AcUserEntityTypeBuilderExtensions
{
public static void BuildUserToProfileRelation<TUser, TProfile>(this EntityTypeBuilder<TUser> modelBuilder) where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
public static void BuildEntityToProfileRelation<TProfileRelation, TProfile>(this EntityTypeBuilder<TProfileRelation> modelBuilder, bool autoInclude = true)
where TProfileRelation : class, IAcProfileRelation<TProfile>
where TProfile : class, IAcProfile
{
//throw new NotImplementedException();
modelBuilder.Navigation(e => e.Profile).AutoInclude(autoInclude);
}
public static void BuildUserToAddressRelation<TUser, TProfile>(this EntityTypeBuilder<TUser> modelBuilder) where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
public static void BuildEntityToServiceProviderRelation<TServiceProviderRelation, TServiceProvider, TUserToServiceProvider>(this EntityTypeBuilder<TServiceProviderRelation> modelBuilder, bool autoInclude = true)
where TServiceProviderRelation : class, IAcUserBase, IAcServiceProviderRelation<TServiceProvider, TUserToServiceProvider>
where TServiceProvider : class, IAcServiceProvider<TServiceProviderRelation, TUserToServiceProvider>
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
modelBuilder
.HasMany(e => e.ServiceProviders)
.WithMany(e => e.Users)
.UsingEntity<TUserToServiceProvider>();
//l => l.HasOne<Product>().WithMany(x=>x.UserProductMappings).HasForeignKey(e => e.ProductId),
//r => r.HasOne<User>().WithMany(x=>x.UserProductMappings).HasForeignKey(e => e.UserId));
//modelBuilder
// .HasMany(e => e.UserProductMappings)
// .WithOne(e => e.User).HasForeignKey(x => x.UserId);
// //.WithMany(e => e.User).
// //.UsingEntity<UserProductMapping>.HasForeignKey(x => x.UserId);
modelBuilder.Navigation(e => e.ServiceProviders).AutoInclude(autoInclude);
modelBuilder.Navigation(e => e.UserToServiceProviders).AutoInclude(autoInclude);
}
public static void BuildEntityToAddressRelation<TProfileRelation, TProfile>(this EntityTypeBuilder<TProfileRelation> modelBuilder)
where TProfileRelation : class, IAcProfileRelation<TProfile>
where TProfile : class, IAcProfile
{
//throw new NotImplementedException();
}

View File

@ -1,15 +1,21 @@
using AyCode.Database.DbContexts;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace AyCode.Database.ModelBuilders.Users;
public abstract class AcUserEntityTypeDefaultConfiguration<TUser, TProfile> : IAcEntityTypeConfiguration<TUser> where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
public abstract class AcUserEntityTypeDefaultConfiguration<TUser, TProfile, TServiceProvider, TUserToServiceProvider> : IAcEntityTypeConfiguration<TUser>
where TUser : class, IAcUser<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TServiceProvider : class, IAcServiceProvider<TUser, TUserToServiceProvider>
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
public virtual void Configure(EntityTypeBuilder<TUser> modelBuilder)
{
modelBuilder.BuildUserToProfileRelation<TUser, TProfile>();
modelBuilder.BuildUserToAddressRelation<TUser, TProfile>();
modelBuilder.BuildEntityToProfileRelation<TUser, TProfile>();
modelBuilder.BuildEntityToAddressRelation<TUser, TProfile>();
modelBuilder.BuildEntityToServiceProviderRelation<TUser, TServiceProvider, TUserToServiceProvider>();
}
}

View File

@ -10,11 +10,11 @@ using System.Threading.Tasks;
namespace AyCode.Entities.Profiles
{
[Table("Profile")]
public abstract class AcProfileBase : IAcProfileBase
public abstract class AcProfile : IAcProfile
{
protected AcProfileBase() { }
protected AcProfile() { }
protected AcProfileBase(Guid ownerId) : this()
protected AcProfile(Guid ownerId) : this()
{
OwnerId = ownerId;
}

View File

@ -0,0 +1,37 @@

using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
namespace AyCode.Entities.ServiceProviders
{
[Table("ServiceProviders")]
public abstract class AcServiceProvider<TUser, TUserToServiceProvider> : IAcServiceProvider<TUser, TUserToServiceProvider>
where TUser : class, IAcUserBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public string Name { get; set; }
public Guid OwnerId { get; set; }
public virtual List<TUser> Users { get; set; }
public virtual List<TUserToServiceProvider> UserToServiceProviders { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
protected AcServiceProvider() { }
protected AcServiceProvider(string name, Guid ownerId ) : this(Guid.NewGuid(), name, ownerId) { }
protected AcServiceProvider(Guid id, string name, Guid ownerId) : this()
{
Id = id;
Name = name;
OwnerId = ownerId;
}
}
}

View File

@ -1,33 +0,0 @@

using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using AyCode.Interfaces.ServiceProviders;
namespace AyCode.Entities.ServiceProviders
{
[Table("ServiceProviders")]
public abstract class ServiceProviderBase : IServiceProviderBase
{
protected ServiceProviderBase() { }
protected ServiceProviderBase(string name, Guid ownerId ) : this(Guid.NewGuid(), name, ownerId) { }
protected ServiceProviderBase(Guid id, string name, Guid ownerId) : this()
{
Id = id;
Name = name;
OwnerId = ownerId;
}
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public string Name { get; set; }
public Guid OwnerId { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
}
}

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Users;
using AyCode.Entities.ServiceProviders;
using AyCode.Interfaces.ServiceProviders;
//- szétszedni az UserToServiceProvider és UserToProduct mapping list-eket külön interface-re
//- külön interface-ek az entity foreignId -khoz! pl: IUserForeignKey, IProductForeignKey, stb...
//- ModelDto Initialize(...)
namespace AyCode.Entities.Users
{
[Table("Users")]
public abstract class AcUser<TProfile, TServiceProvider, TUserToServiceProvider> : IAcUser<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
[Column("Email")]
public string EmailAddress { get; set; }
//public string NormalizedEmail { get; set; }
public string PhoneNumber { get; set; }
public string Password { get; set; }
public string? RefreshToken { get; set; }
public bool EmailConfirmed { get; set; }
public Guid ProfileId { get; set; }
[ForeignKey(nameof(ProfileId))]
public virtual TProfile Profile { get; set; }
//[NotMapped]
public virtual List<TServiceProvider> ServiceProviders { get; set; }
public virtual List<TUserToServiceProvider> UserToServiceProviders { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
protected AcUser() { }
protected AcUser(string email, string password) : this(Guid.NewGuid(), email, password) { }
protected AcUser(Guid id, string email, string password) : this()
{
Id = id;
EmailAddress = email;
Password = password;
}
protected AcUser(string email, string phoneNumber, string password) : this(Guid.NewGuid(), email, phoneNumber, password) { }
protected AcUser(Guid id, string email, string phoneNumber, string password) : this(id, email, password)
{
PhoneNumber = phoneNumber;
}
protected AcUser(string email, string phoneNumber, string password, string refreshToken) : this(Guid.NewGuid(), email, phoneNumber, password, refreshToken) { }
protected AcUser(Guid id, string email, string phoneNumber, string password, string refreshToken) : this(id, email, phoneNumber, password)
{
RefreshToken = refreshToken;
}
}
}

View File

@ -0,0 +1,24 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
namespace AyCode.Entities.Users;
[Table("UserToServiceProvider")]
public abstract class AcUserToServiceProvider<TUser, TServiceProvider> : IAcUserToServiceProvider<TUser, TServiceProvider>
where TUser : class, IAcUserBase
where TServiceProvider : class, IAcServiceProviderBase
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
public Guid UserId { get; set; }
public Guid ServiceProviderId { get; set; }
public virtual TUser User { get; set; }
public virtual TServiceProvider ServiceProvider { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
}

View File

@ -5,7 +5,7 @@ using System.ComponentModel.DataAnnotations;
namespace AyCode.Entities.Users;
[Table("UserToken")]
public abstract class UserTokenBase : IUserTokenBase
public abstract class AcUserTokenBase : IAcUserTokenBase
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }

View File

@ -1,60 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Users;
namespace AyCode.Entities.Users
{
[Table("Users")]
public abstract class UserBase<TProfile> : IUserBase<TProfile> where TProfile : class, IAcProfileBase
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid Id { get; set; }
[Column("Email")]
public string EmailAddress { get; set; }
//public string NormalizedEmail { get; set; }
public string PhoneNumber { get; set; }
public string Password { get; set; }
public string? RefreshToken { get; set; }
public bool EmailConfirmed { get; set; }
public Guid? ProfileId { get; }
[ForeignKey(nameof(ProfileId))]
public virtual TProfile Profile { get; set; }
public DateTime Created { get; set; }
public DateTime Modified { get; set; }
protected UserBase() { }
protected UserBase(string email, string password) : this(Guid.NewGuid(), email, password) { }
protected UserBase(Guid id, string email, string password) : this()
{
Id = id;
EmailAddress = email;
Password = password;
}
protected UserBase(string email, string phoneNumber, string password) : this(Guid.NewGuid(), email, phoneNumber, password) { }
protected UserBase(Guid id, string email, string phoneNumber, string password) : this(id, email, password)
{
PhoneNumber = phoneNumber;
}
protected UserBase(string email, string phoneNumber, string password, string refreshToken) : this(Guid.NewGuid(), email, phoneNumber, password, refreshToken) { }
protected UserBase(Guid id, string email, string phoneNumber, string password, string refreshToken) : this(id, email, phoneNumber, password)
{
RefreshToken = refreshToken;
}
}
}

View File

@ -1,6 +1,6 @@
namespace AyCode.Interfaces.Profiles;
public abstract class AcProfile : IAcProfileBase
public abstract class AcProfile : IAcProfile
{
public Guid Id { get; set; }
public Guid OwnerId { get; set; }

View File

@ -6,6 +6,6 @@ using AyCode.Interfaces.Profiles.Dtos;
namespace AyCode.Interfaces.Profiles;
public interface IAcProfileBase : IAcProfileDtoBase, ITimeStampInfo
public interface IAcProfile : IAcProfileDtoBase, ITimeStampInfo
{
}

View File

@ -0,0 +1,11 @@
using AyCode.Interfaces.TimeStampInfo;
using AyCode.Interfaces.Users.Dtos;
using AyCode.Interfaces.Users;
namespace AyCode.Interfaces.Profiles;
public interface IAcProfileRelation<TProfile> where TProfile : class, IAcProfile
{
public Guid ProfileId { get; }
public TProfile Profile { get; set; }
}

View File

@ -0,0 +1,6 @@
namespace AyCode.Interfaces.Profiles;
public interface IProfileForeignKey
{
public Guid ProfileId { get; set; }
}

View File

@ -0,0 +1,8 @@
using AyCode.Interfaces.Users;
namespace AyCode.Interfaces.ServiceProviders;
public interface IAcServiceProvider<TUser, TUserToServiceProvider> : IAcServiceProviderBase, IAcUserListRelation<TUser, TUserToServiceProvider>
where TUser : class, IAcUserBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{}

View File

@ -0,0 +1,12 @@

using AyCode.Interfaces.Entities;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.TimeStampInfo;
using System;
namespace AyCode.Interfaces.ServiceProviders;
public interface IAcServiceProviderBase : IEntityGuid, ITimeStampInfo, IOwnerId
{
string Name { get; set; }
}

View File

@ -0,0 +1,11 @@
using AyCode.Interfaces.Users;
namespace AyCode.Interfaces.ServiceProviders;
public interface IAcServiceProviderRelation<TServiceProvider, TUserToServiceProvider>
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
public List<TServiceProvider> ServiceProviders { get; set; }
public List<TUserToServiceProvider> UserToServiceProviders { get; set; }
}

View File

@ -1,11 +0,0 @@

using AyCode.Interfaces.Entities;
using AyCode.Interfaces.TimeStampInfo;
namespace AyCode.Interfaces.ServiceProviders;
public interface IServiceProviderBase : IEntityGuid, ITimeStampInfo
{
string Name { get; }
Guid OwnerId { get; }
}

View File

@ -0,0 +1,6 @@
namespace AyCode.Interfaces.ServiceProviders;
public interface IServiceProviderForeignKey
{
public Guid ServiceProviderId { get; set; }
}

View File

@ -1,6 +1,12 @@
namespace AyCode.Interfaces.Users.Dtos;
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
public interface IAcUserDtoBase : IAcUserDtoMinBase
namespace AyCode.Interfaces.Users.Dtos;
public interface IAcUserDtoBase<TProfile, TServiceProvider, TUserToServiceProvider> : IAcUserDtoMinBase<TProfile>, IAcServiceProviderRelation<TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
}

View File

@ -1,10 +1,12 @@
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
namespace AyCode.Interfaces.Users.Dtos;
public interface IAcUserDtoDetailBase : IEmailAddress, IAcUserDtoBase
public interface IAcUserDtoDetailBase<TProfile, TServiceProvider, TUserToServiceProvider> : IAcUserBase, IAcUserDtoBase<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
public string PhoneNumber { get; set; }
public string? RefreshToken { get; set; }
}

View File

@ -1,9 +1,10 @@

using AyCode.Interfaces.Entities;
using AyCode.Interfaces.Profiles;
namespace AyCode.Interfaces.Users.Dtos;
public interface IAcUserDtoMinBase : IEntityGuid
public interface IAcUserDtoMinBase<TProfile> : IEntityGuid, IAcProfileRelation<TProfile> where TProfile : class, IAcProfile
{
}

View File

@ -0,0 +1,13 @@

using AyCode.Interfaces.Entities;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users.Dtos;
namespace AyCode.Interfaces.Users;
public interface IAcUser<TProfile, TServiceProvider, TUserToServiceProvider> : IAcUserDtoDetailBase<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{ }

View File

@ -0,0 +1,12 @@
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.TimeStampInfo;
using AyCode.Interfaces.Users.Dtos;
namespace AyCode.Interfaces.Users;
public interface IAcUserBase : IEntityGuid, IProfileForeignKey, IEmailAddress, IPassword, ITimeStampInfo
{
public string PhoneNumber { get; set; }
public string? RefreshToken { get; set; }
}

View File

@ -0,0 +1,18 @@
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.ServiceProviders;
namespace AyCode.Interfaces.Users;
public interface IAcUserListRelation<TUser, TUserToServiceProvider>
where TUser : class, IAcUserBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
public List<TUser> Users { get; set; }
public List<TUserToServiceProvider> UserToServiceProviders { get; set; }
}
public interface IAcUserRelation<TUser> where TUser : class, IAcUserBase
{
public Guid UserId { get; }
public TUser User { get; set; }
}

View File

@ -0,0 +1,13 @@
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.TimeStampInfo;
namespace AyCode.Interfaces.Users;
public interface IAcUserToServiceProvider<TUser, TServiceProvider> : IAcUserToServiceProviderBase
where TUser : class, IAcUserBase
where TServiceProvider : class, IAcServiceProviderBase
{
public TUser User { get; set; }
public TServiceProvider ServiceProvider { get; set; }
}

View File

@ -0,0 +1,9 @@
using AyCode.Interfaces.Entities;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.TimeStampInfo;
namespace AyCode.Interfaces.Users;
public interface IAcUserToServiceProviderBase : IEntityGuid, IUserForeignKey, IServiceProviderForeignKey, ITimeStampInfo
{
}

View File

@ -0,0 +1,12 @@
using AyCode.Interfaces.ServiceProviders;
namespace AyCode.Interfaces.Users;
public interface IAcUserToServiceProviderRelation<TUser, TServiceProvider, TUserToServiceProvider>
where TUser : class, IAcUserBase, IAcServiceProviderRelation<TServiceProvider, TUserToServiceProvider>
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
public TUser User { get; set; }
public TServiceProvider ServiceProvider { get; set; }
}

View File

@ -5,7 +5,7 @@ using AyCode.Interfaces.TimeStampInfo;
namespace AyCode.Interfaces.Users;
public interface IUserTokenBase : IEntity<int>, ITimeStampInfo
public interface IAcUserTokenBase : IEntity<int>, ITimeStampInfo
{
public Guid UserId { get; set; }
public bool IsActive { get; set; }

View File

@ -1,13 +0,0 @@

using AyCode.Interfaces.Entities;
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.TimeStampInfo;
using AyCode.Interfaces.Users.Dtos;
namespace AyCode.Interfaces.Users;
public interface IUserBase<TProfile> : IAcUserDtoDetailBase, IPassword, ITimeStampInfo where TProfile : class, IAcProfileBase
{
public Guid? ProfileId { get; }
public TProfile Profile { get; set; }
}

View File

@ -0,0 +1,6 @@
namespace AyCode.Interfaces.Users;
public interface IUserForeignKey
{
Guid UserId { get; set; }
}

View File

@ -1,26 +1,54 @@
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Profiles.Dtos;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using AyCode.Interfaces.Users.Dtos;
namespace AyCode.Models.Users;
public abstract class AcUserModelDtoBase<TUserDto, TProfile, TProfileDto> : AcUserModelDtoMinBase<TUserDto, TProfile>
where TUserDto : class, IAcUserDtoBase
where TProfile : class, IAcProfileBase
public abstract class AcUserModelDtoBase<TUserDto, TProfile, TProfileDto, TServiceProvider, TUserToServiceProvider> : AcUserModelDtoMinBase<TUserDto, TProfile, TProfileDto>, IAcServiceProviderRelation<TServiceProvider, TUserToServiceProvider>
where TUserDto : class, IAcUserDtoBase<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TProfileDto : class, IAcProfileDtoBase
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
public TProfileDto Profile { get; set; }
public List<TServiceProvider> ServiceProviders { get; set; }
public List<TUserToServiceProvider> UserToServiceProviders { get; set; }
protected AcUserModelDtoBase() {}
protected AcUserModelDtoBase(IUserBase<TProfile> user, TProfile? profile) : base(user)
protected AcUserModelDtoBase(IAcUserDtoBase<TProfile, TServiceProvider, TUserToServiceProvider> user) : base(user)
{
if (profile == null) return;
if (user.ServiceProviders.Count == 0) return;
Profile = Activator.CreateInstance<TProfileDto>();
//így proxy error lesz... - J.
//ServiceProviders = new List<TServiceProvider>(user.ServiceProviders);
//UserToServiceProviders = new List<TUserToServiceProvider>(user.UserToServiceProviders);
Profile.Id = profile.Id;
Profile.Name = profile.Name;
Profile.OwnerId = profile.OwnerId;
ServiceProviders = new List<TServiceProvider>(user.ServiceProviders.Count);
UserToServiceProviders = new List<TUserToServiceProvider>(user.UserToServiceProviders.Count);
foreach (var serviceProvider in user.ServiceProviders)
{
var newProvider = Activator.CreateInstance<TServiceProvider>();
newProvider.Id = serviceProvider.Id;
newProvider.Name = serviceProvider.Name;
newProvider.OwnerId = serviceProvider.OwnerId;
ServiceProviders.Add(newProvider);
}
foreach (var userToServiceProvider in user.UserToServiceProviders)
{
var newUserToProvider = Activator.CreateInstance<TUserToServiceProvider>();
newUserToProvider.Id = userToServiceProvider.Id;
newUserToProvider.UserId = userToServiceProvider.UserId;
newUserToProvider.ServiceProviderId = userToServiceProvider.ServiceProviderId;
UserToServiceProviders.Add(newUserToProvider);
}
}
}

View File

@ -1,17 +1,20 @@
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Profiles.Dtos;
using AyCode.Interfaces.ServiceProviders;
using AyCode.Interfaces.Users;
using AyCode.Interfaces.Users.Dtos;
namespace AyCode.Models.Users;
public abstract class AcUserModelDtoDetailBase<TUserDtoDetail, TProfile, TProfileDto> : AcUserModelDtoBase<TUserDtoDetail, TProfile, TProfileDto>
where TUserDtoDetail : class, IAcUserDtoDetailBase
where TProfile : class, IAcProfileBase
public abstract class AcUserModelDtoDetailBase<TUserDtoDetail, TProfile, TProfileDto, TServiceProvider, TUserToServiceProvider> : AcUserModelDtoBase<TUserDtoDetail, TProfile, TProfileDto, TServiceProvider, TUserToServiceProvider>
where TUserDtoDetail : class, IAcUserDtoDetailBase<TProfile, TServiceProvider, TUserToServiceProvider>
where TProfile : class, IAcProfile
where TProfileDto : class, IAcProfileDtoBase
where TServiceProvider : class, IAcServiceProviderBase
where TUserToServiceProvider : class, IAcUserToServiceProviderBase
{
protected AcUserModelDtoDetailBase() {}
protected AcUserModelDtoDetailBase(IUserBase<TProfile> user, TProfile profile) : base(user, profile)
protected AcUserModelDtoDetailBase(IAcUserDtoDetailBase<TProfile, TServiceProvider, TUserToServiceProvider> user) : base(user)
{
}
}

View File

@ -1,19 +1,29 @@
using AyCode.Interfaces.Profiles;
using AyCode.Interfaces.Profiles.Dtos;
using AyCode.Interfaces.Users;
using AyCode.Interfaces.Users.Dtos;
namespace AyCode.Models.Users;
public abstract class AcUserModelDtoMinBase<TUserDtoMin, TProfile> : AcModelDtoBase where TUserDtoMin : IAcUserDtoMinBase where TProfile : class, IAcProfileBase
public abstract class AcUserModelDtoMinBase<TUserDtoMin, TProfile, TProfileDto> : AcModelDtoBase
where TUserDtoMin : class, IAcUserDtoMinBase<TProfile>
where TProfile : class, IAcProfile
where TProfileDto : class, IAcProfileDtoBase
{
public TUserDtoMin UserDto { get; set;}
public TProfileDto? Profile { get; set; }
protected AcUserModelDtoMinBase() {}
protected AcUserModelDtoMinBase(IUserBase<TProfile> user) : base(user.Id)
protected AcUserModelDtoMinBase(IAcUserDtoMinBase<TProfile> user) : base(user.Id)
{
Id = user.Id;
UserDto = Activator.CreateInstance<TUserDtoMin>();
UserDto.Id = user.Id;
Profile = Activator.CreateInstance<TProfileDto>();
Profile.Id = user.Profile.Id;
Profile.Name = user.Profile.Name;
Profile.OwnerId = user.Profile.OwnerId;
}
}