Implement UserModels; Add Profile; improvements, fixes, etc...

This commit is contained in:
jozsef.b@aycode.com 2023-12-18 23:08:11 +01:00
parent 4a07b1bcc2
commit 34098e207b
32 changed files with 259 additions and 66 deletions

View File

@ -5,6 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AyCode.Database.DataLayers.Users; using AyCode.Database.DataLayers.Users;
using Newtonsoft.Json;
using TIAM.Database.DataLayers.ServiceProviders; using TIAM.Database.DataLayers.ServiceProviders;
using TIAM.Database.DataLayers.Users; using TIAM.Database.DataLayers.Users;
using TIAM.Database.DbContexts.ServiceProviders; using TIAM.Database.DbContexts.ServiceProviders;
@ -97,11 +98,35 @@ namespace TIAM.Database.Test
public void GetUserProductMappingById_ReturnsUserProductMapping_WherHasUserAndProductRelation(string userProductMappingIdString) public void GetUserProductMappingById_ReturnsUserProductMapping_WherHasUserAndProductRelation(string userProductMappingIdString)
{ {
var userProductMappingId = Guid.Parse(userProductMappingIdString); var userProductMappingId = Guid.Parse(userProductMappingIdString);
var userProductMapping = Dal.GetUserProductMappingById(userProductMappingId); var userProductMapping = Dal.GetUserProductMappingById(userProductMappingId, true);
Assert.IsNotNull(userProductMapping); Assert.IsNotNull(userProductMapping);
Assert.IsNotNull(userProductMapping.User, "User is null"); Assert.IsNotNull(userProductMapping.User, "User is null");
Assert.IsNotNull(userProductMapping.Product, "Product is null"); Assert.IsNotNull(userProductMapping.Product, "Product is null");
} }
//[TestMethod]
//[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
//public void SerializeUser_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)
//{
// var userId = Guid.Parse(userIdString);
// var user = Dal.GetUserProductMappingById(userId);
// JsonSerializerSettings options = new()
// {
// ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
// //NullValueHandling = NullValueHandling.Ignore
// };
// var serializedUser = JsonConvert.SerializeObject(user, options);
// user = JsonConvert.DeserializeObject<User>(serializedUser);
// Assert.IsNotNull(user);
// Assert.IsNotNull(user.Products);
// Assert.IsNotNull(user.UserProductMappings);
// Assert.IsNotNull(user.UserProductMappings.FirstOrDefault()?.Product);
// Assert.IsTrue(user.Products.Count > 0);
//}
} }
} }

View File

@ -10,12 +10,15 @@ using System.Text.Json.Serialization;
using System.Text.Json; using System.Text.Json;
using TIAM.Database.DataLayers.Users; using TIAM.Database.DataLayers.Users;
using TIAM.Database.DbContexts.Users; using TIAM.Database.DbContexts.Users;
using TIAM.Entities.Profiles;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
using AyCode.Interfaces.Users.Dtos;
namespace TIAM.Database.Test namespace TIAM.Database.Test
{ {
[TestClass] [TestClass]
public class UserDalTests : AcUserDalTestBase<UserDal, UserDbContext, User, UserToken> public class UserDalTests : AcUserDalTestBase<UserDal, UserDbContext, User, Profile, UserToken>
{ {
private Mock<UserDbContext> _mockContext; private Mock<UserDbContext> _mockContext;
@ -51,23 +54,26 @@ namespace TIAM.Database.Test
[TestMethod] [TestMethod]
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")] [DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
public void SerializeUser_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString) public void SerializeUserModelDto_ReturnDeserializedUser_WhenUserAndRelationsExists(string userIdString)
{ {
var userId = Guid.Parse(userIdString); var userId = Guid.Parse(userIdString);
var user = Dal.GetUserById(userId);
JsonSerializerSettings options = new() JsonSerializerSettings options = new()
{ {
ReferenceLoopHandling = ReferenceLoopHandling.Ignore, ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
//NullValueHandling = NullValueHandling.Ignore NullValueHandling = NullValueHandling.Ignore
}; };
var serializedUser = JsonConvert.SerializeObject(user, options); var userModel = Dal.GetUserModelDtoById(userId);
user = JsonConvert.DeserializeObject<User>(serializedUser);
Assert.IsNotNull(user); var serializedUserModel = JsonConvert.SerializeObject(userModel, options);
Assert.IsNotNull(user.UserProductMappings); userModel = JsonConvert.DeserializeObject<UserModelDto>(serializedUserModel);
//Assert.IsNotNull(user.UserProductMappings.FirstOrDefault()?.Product);
Assert.IsNotNull(userModel);
Assert.IsNotNull(userModel.Profile);
Assert.IsTrue(userModel.Products.Count > 0);
Assert.IsTrue(userModel.UserProductMappings.Count > 0);
} }
//[TestMethod] //[TestMethod]

View File

@ -8,14 +8,15 @@ using Microsoft.EntityFrameworkCore;
using TIAM.Entities.Permissions; using TIAM.Entities.Permissions;
using TIAM.Entities.Products; using TIAM.Entities.Products;
using TIAM.Entities.ServiceProviders; using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Products.DTOs;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Database.DbContexts.ServiceProviders; using TIAM.Database.DbContexts.ServiceProviders;
using TIAM.Database.DbSets.Permissions; using TIAM.Database.DbSets.Permissions;
using TIAM.Database.DbSets.Users; using TIAM.Database.DbSets.Users;
using TIAM.Entities.Products.DTOs;
using AyCode.Database.DataLayers; using AyCode.Database.DataLayers;
using AyCode.Database.DbSets.Users; using AyCode.Database.DbSets.Users;
using TIAM.Database.DbSets.Products; using TIAM.Database.DbSets.Products;
using TIAM.Models.Dtos.Users;
namespace TIAM.Database.DataLayers.ServiceProviders namespace TIAM.Database.DataLayers.ServiceProviders
@ -31,10 +32,13 @@ namespace TIAM.Database.DataLayers.ServiceProviders
{ {
} }
public User? GetUserById(Guid userId, bool autoInclude = true) => Session(x => x.GetUserById(userId, autoInclude)); public User? GetUserById(Guid userId, bool autoInclude = false) => Session(x => x.GetUserById(userId, autoInclude));
public User? GetUserByEmail(string email, bool autoInclude = true) => Session(x => x.GetUserByEmail(email, autoInclude)); public User? GetUserByEmail(string email, bool autoInclude = false) => Session(x => x.GetUserByEmail(email, autoInclude));
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId) => Session(x => x.GetUserProductMappingById(userProductMappingId)); public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId));
public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email));
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(x => x.GetUserProductMappingById(userProductMappingId, autoInclude));
#region ServiceProviders #region ServiceProviders

View File

@ -99,7 +99,7 @@ public static class ServiceProviderDalExtension
existingProduct.Description = product.Description; existingProduct.Description = product.Description;
existingProduct.Price = product.Price; existingProduct.Price = product.Price;
existingProduct.JsonDetails = product.JsonDetails; existingProduct.JsonDetails = product.JsonDetails;
existingProduct.UserMediaId = product.UserMediaId; //existingProduct.UserMediaId = product.UserMediaId;
existingProduct.ProductType = product.ProductType; existingProduct.ProductType = product.ProductType;

View File

@ -5,14 +5,18 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AyCode.Database.DataLayers; using AyCode.Database.DataLayers;
using AyCode.Database.DataLayers.Users; using AyCode.Database.DataLayers.Users;
using AyCode.Database.DbSets.Users;
using AyCode.Entities.Users; using AyCode.Entities.Users;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using TIAM.Database.DbContexts.Users; using TIAM.Database.DbContexts.Users;
using TIAM.Database.DbSets.Users;
using TIAM.Entities.Profiles;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
namespace TIAM.Database.DataLayers.Users namespace TIAM.Database.DataLayers.Users
{ {
public class UserDal : AcUserDalBase<UserDbContext, User, UserToken> public class UserDal : AcUserDalBase<UserDbContext, User, Profile, UserToken>
{ {
public UserDal() : base() public UserDal() : base()
@ -28,14 +32,8 @@ namespace TIAM.Database.DataLayers.Users
return Context.Users.ToListAsync(); return Context.Users.ToListAsync();
} }
//public Task<User?> GetUserByEmailAsync(string email) public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId));
//{ public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email));
// Console.WriteLine($"Getting user from db {email}");
// //var emailLower = email.ToLower();
// return Context.GetUserByEmail(email);
// //return Context.Users.SingleOrDefaultAsync(x=>x.Email.ToLower() == emailLower);
//}
public Task<User?> GetUserByPhoneNumberAsync(string phoneNumber) public Task<User?> GetUserByPhoneNumberAsync(string phoneNumber)
{ {

View File

@ -29,7 +29,7 @@ namespace TIAM.Database.DbContexts
{ {
base.OnConfiguring(optionsBuilder); base.OnConfiguring(optionsBuilder);
optionsBuilder.UseLazyLoadingProxies(false); optionsBuilder.UseLazyLoadingProxies(true);
optionsBuilder.EnableDetailedErrors(true); optionsBuilder.EnableDetailedErrors(true);
//optionsBuilder.UseSqlServer(Configuration.GetConnectionString("DeveloperDbConnection")); //optionsBuilder.UseSqlServer(Configuration.GetConnectionString("DeveloperDbConnection"));

View File

@ -1,10 +1,11 @@
using AyCode.Database.DbContexts.Users; using AyCode.Database.DbContexts.Users;
using AyCode.Entities.Users; using AyCode.Entities.Users;
using TIAM.Database.DbSets.Users; using TIAM.Database.DbSets.Users;
using TIAM.Entities.Profiles;
using TIAM.Entities.Users; using TIAM.Entities.Users;
namespace TIAM.Database.DbContexts.Users; namespace TIAM.Database.DbContexts.Users;
public interface IUserDbContext : IAcUserDbContextBase<User, UserToken> public interface IUserDbContext : IAcUserDbContextBase<User, Profile, UserToken>, IUserDbSet
{ {
} }

View File

@ -11,8 +11,10 @@ using AyCode.Entities.Users;
using AyCode.Interfaces.Users; using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using TIAM.Database.ModelBuilders.Products;
using TIAM.Database.ModelBuilders.Users; using TIAM.Database.ModelBuilders.Users;
using TIAM.Entities.Permissions; using TIAM.Entities.Permissions;
using TIAM.Entities.Products;
using TIAM.Entities.Users; using TIAM.Entities.Users;
namespace TIAM.Database.DbContexts.Users namespace TIAM.Database.DbContexts.Users
@ -51,7 +53,9 @@ namespace TIAM.Database.DbContexts.Users
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>()); new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
modelBuilder.Entity<Product>().BuildProductToServiceProviderRelation();
//new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
} }
} }
} }

View File

@ -1,8 +1,9 @@
using AyCode.Database.DbSets.Users; using AyCode.Database.DbSets.Users;
using TIAM.Entities.Profiles;
using TIAM.Entities.Users; using TIAM.Entities.Users;
namespace TIAM.Database.DbSets.Users; namespace TIAM.Database.DbSets.Users;
public interface IUserDbSet : IAcUserDbSet<User> public interface IUserDbSet : IAcUserDbSet<User, Profile>
{ {
} }

View File

@ -1,6 +1,8 @@
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using AyCode.Database.DbSets.Users;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAM.Models.Dtos.Users;
namespace TIAM.Database.DbSets.Users; namespace TIAM.Database.DbSets.Users;
@ -13,16 +15,15 @@ public static class UserDbSetExtensions
.ThenInclude(x => x.Product) .ThenInclude(x => x.Product)
: ctx.Users; : 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) public static User? GetUserById(this IUserDbSet ctx, Guid userId, bool autoInclude)
=> ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.Id == userId); => ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.Id == userId);
public static User? GetUserByEmail(this IUserDbSet ctx, string email, bool autoInclude) public static User? GetUserByEmail(this IUserDbSet ctx, string email, bool autoInclude)
=> ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.EmailAddress == email); => 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();
} }

View File

@ -12,15 +12,15 @@ public static class UserProductMappingDbSetExtensions
: ctx.UserProductMappings; : ctx.UserProductMappings;
public static UserProductMapping? GetUserProductMappingById(this IUserProductMappingDbSet ctx, Guid userProductMappingId) public static UserProductMapping? GetUserProductMappingById(this IUserProductMappingDbSet ctx, Guid userProductMappingId, bool autoInclude = true)
=> ctx.UserProductMappingsWithRelations().FirstOrDefault(x => x.Id == userProductMappingId); => ctx.UserProductMappingsWithRelations(autoInclude).FirstOrDefault(x => x.Id == userProductMappingId);
public static UserProductMapping? GetUserProductMapping(this IUserProductMappingDbSet ctx, Guid userId, Guid productId) public static UserProductMapping? GetUserProductMapping(this IUserProductMappingDbSet ctx, Guid userId, Guid productId, bool autoInclude = true)
=> ctx.UserProductMappingsWithRelations().FirstOrDefault(x => x.UserId == userId && x.ProductId == productId); => ctx.UserProductMappingsWithRelations(autoInclude).FirstOrDefault(x => x.UserId == userId && x.ProductId == productId);
public static IQueryable<UserProductMapping> GetUserProductMappingsByUserId(this IUserProductMappingDbSet ctx, Guid userId) public static IQueryable<UserProductMapping> GetUserProductMappingsByUserId(this IUserProductMappingDbSet ctx, Guid userId, bool autoInclude = true)
=> ctx.UserProductMappingsWithRelations().Where(x => x.UserId == userId); => ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.UserId == userId);
public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId) public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId, bool autoInclude = true)
=> ctx.UserProductMappingsWithRelations().Where(x => x.ProductId == productId); => ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.ProductId == productId);
} }

View File

@ -12,10 +12,16 @@ public static class ProductEntityTypeBuilderExtensions
public static void BuildProductToUserProductMappingRelation(this EntityTypeBuilder<Product> modelBuilder, bool autoInclude = true) public static void BuildProductToUserProductMappingRelation(this EntityTypeBuilder<Product> modelBuilder, bool autoInclude = true)
{ {
modelBuilder modelBuilder
.HasMany(e => e.UserProductMappings) .HasMany(e => e.Users)
.WithOne(e => e.Product).HasForeignKey(x => x.ProductId); .WithMany(e => e.Products)
.UsingEntity<UserProductMapping>();
//modelBuilder
// .HasMany(e => e.UserProductMappings)
// .WithOne(e => e.Product).HasForeignKey(x => x.ProductId);
modelBuilder.Navigation(e => e.UserProductMappings).AutoInclude(autoInclude); modelBuilder.Navigation(e => e.UserProductMappings).AutoInclude(autoInclude);
modelBuilder.Navigation(e => e.Users).AutoInclude(autoInclude);
} }
public static void BuildProductToServiceProviderRelation(this EntityTypeBuilder<Product> modelBuilder, bool autoInclude = true) public static void BuildProductToServiceProviderRelation(this EntityTypeBuilder<Product> modelBuilder, bool autoInclude = true)

View File

@ -11,7 +11,7 @@ public class ProductEntityTypeDefaultConfiguration : IAcEntityTypeConfiguration<
{ {
public void Configure(EntityTypeBuilder<Product> builder) public void Configure(EntityTypeBuilder<Product> builder)
{ {
builder.BuildProductToUserProductMappingRelation(); //builder.BuildProductToUserProductMappingRelation();
builder.BuildProductToServiceProviderRelation(); builder.BuildProductToServiceProviderRelation();
} }
} }

View File

@ -2,6 +2,7 @@
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System.Numerics; using System.Numerics;
using AyCode.Interfaces.Profiles;
using TIAM.Entities.Products; using TIAM.Entities.Products;
using TIAM.Entities.Users; using TIAM.Entities.Users;
@ -13,17 +14,20 @@ public static class UserEntityTypeBuilderExtensions
public static void BuildUserToUserProductMappingRelation(this EntityTypeBuilder<User> modelBuilder, bool autoInclude = true) public static void BuildUserToUserProductMappingRelation(this EntityTypeBuilder<User> modelBuilder, bool autoInclude = true)
{ {
//modelBuilder
// .HasMany(e => e.Products)
// .WithMany(e => e.Users)
//.UsingEntity<UserProductMapping>();
modelBuilder modelBuilder
.HasMany(e => e.UserProductMappings) .HasMany(e => e.Products)
.WithOne(e => e.User).HasForeignKey(x => x.UserId); .WithMany(e => e.Users)
//.WithMany(e => e.User). .UsingEntity<UserProductMapping>();
//.UsingEntity<UserProductMapping>.HasForeignKey(x => x.UserId); //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.Products).AutoInclude(autoInclude);
modelBuilder.Navigation(e => e.UserProductMappings).AutoInclude(autoInclude); modelBuilder.Navigation(e => e.UserProductMappings).AutoInclude(autoInclude);
} }
@ -65,7 +69,7 @@ public static class UserEntityTypeBuilderExtensions
#endregion UserProductMapping #endregion UserProductMapping
public static void BuildUserToServiceProviderRelation<TUser>(this EntityTypeBuilder<TUser> modelBuilder) where TUser : class, IUserBase public static void BuildUserToServiceProviderRelation<TUser, TProfile>(this EntityTypeBuilder<TUser> modelBuilder) where TUser : class, IUserBase<TProfile> where TProfile : class, IAcProfileBase
{ {
} }

View File

@ -2,6 +2,7 @@
using AyCode.Database.ModelBuilders.Users; using AyCode.Database.ModelBuilders.Users;
using AyCode.Interfaces.Users; using AyCode.Interfaces.Users;
using Microsoft.EntityFrameworkCore.Metadata.Builders; using Microsoft.EntityFrameworkCore.Metadata.Builders;
using TIAM.Entities.Profiles;
using TIAM.Entities.Users; using TIAM.Entities.Users;
namespace TIAM.Database.ModelBuilders.Users; namespace TIAM.Database.ModelBuilders.Users;
@ -21,6 +22,6 @@ public class UserEntityTypeDefaultConfiguration : IAcEntityTypeConfiguration<Use
//base.Configure(builder); //base.Configure(builder);
builder.BuildUserToUserProductMappingRelation(); builder.BuildUserToUserProductMappingRelation();
builder.BuildUserToServiceProviderRelation(); builder.BuildUserToServiceProviderRelation<User, Profile>();
} }
} }

View File

@ -23,6 +23,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\TIAM.Entities.Server\TIAM.Entities.Server.csproj" /> <ProjectReference Include="..\TIAM.Entities.Server\TIAM.Entities.Server.csproj" />
<ProjectReference Include="..\TIAM.Entities\TIAM.Entities.csproj" /> <ProjectReference Include="..\TIAM.Entities\TIAM.Entities.csproj" />
<ProjectReference Include="..\TIAM.Models\TIAM.Models.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -14,12 +14,14 @@ public class Product : ProductBase
public Guid ServiceProviderId { get; set; } public Guid ServiceProviderId { get; set; }
public virtual TiamServiceProvider ServiceProvider { get; set; } public virtual TiamServiceProvider ServiceProvider { get; set; }
public virtual List<User> Users { get; } = new();
public virtual List<UserProductMapping> UserProductMappings { get; } = new(); public virtual List<UserProductMapping> UserProductMappings { get; } = new();
public Product(){} public Product(){}
public Product(Guid ownerId, ProductType productType, Guid userMediaId, string name, string description, float price, string jsonDetails) : this(Guid.NewGuid(), ownerId, productType, userMediaId, name, description, price, jsonDetails) { } public Product(Guid ownerId, ProductType productType, string name, string description, float price, string jsonDetails) : this(Guid.NewGuid(), ownerId, productType, name, description, price, jsonDetails) { }
public Product(Guid id, Guid serviceProviderId, ProductType productType, Guid userMediaId, string name, string description, float price, string jsonDetails) : base(id, productType, userMediaId, name, description, price, jsonDetails) public Product(Guid id, Guid serviceProviderId, ProductType productType, string name, string description, float price, string jsonDetails) : base(id, productType, name, description, price, jsonDetails)
{ {
ServiceProviderId = serviceProviderId; ServiceProviderId = serviceProviderId;
} }

View File

@ -13,7 +13,7 @@ public abstract class ProductBase : IEntityGuid, ITimeStampInfo
public Guid Id { get; set; } public Guid Id { get; set; }
public ProductType ProductType { get; set; } public ProductType ProductType { get; set; }
public Guid? UserMediaId { get; set; } //public Guid? UserMediaId { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
@ -25,11 +25,11 @@ public abstract class ProductBase : IEntityGuid, ITimeStampInfo
protected ProductBase(){} protected ProductBase(){}
protected ProductBase(Guid id, ProductType type, Guid userMediaId, string name, string description, float price, string jsonDetails) protected ProductBase(Guid id, ProductType type, string name, string description, float price, string jsonDetails)
{ {
Id = id; Id = id;
ProductType = type; ProductType = type;
UserMediaId = userMediaId; //UserMediaId = userMediaId;
Name = name; Name = name;
Description = description; Description = description;
Price = price; Price = price;

View File

@ -0,0 +1,8 @@
using AyCode.Interfaces.Profiles;
namespace TIAM.Entities.Profiles;
public interface IProfile : IAcProfileBase, IProfileDto
{
}

View File

@ -0,0 +1,8 @@
using AyCode.Interfaces.Profiles.Dtos;
namespace TIAM.Entities.Profiles;
public interface IProfileDto : IAcProfileDtoBase
{
}

View File

@ -0,0 +1,8 @@
using AyCode.Entities.Profiles;
namespace TIAM.Entities.Profiles;
public class Profile : AcProfileBase, IProfile
{
}

View File

@ -0,0 +1,13 @@
using AyCode.Interfaces.Users;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
namespace TIAM.Entities.Users;
public interface IUser : IUserBase<Profile>, IUserDto
{
public List<Product> Products { get; }
//public ServiceProvider ServiceProvider { get; set; }
public List<UserProductMapping> UserProductMappings { get; }
}

View File

@ -0,0 +1,9 @@
using AyCode.Interfaces.Users;
using AyCode.Interfaces.Users.Dtos;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
namespace TIAM.Entities.Users;
public interface IUserDto : IAcUserDtoBase
{ }

View File

@ -6,15 +6,16 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using AyCode.Entities.Users; using AyCode.Entities.Users;
using TIAM.Entities.Products; using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
namespace TIAM.Entities.Users namespace TIAM.Entities.Users
{ {
public class User : UserBase public class User : UserBase<Profile>, IUser
{ {
//public virtual List<Product> Products { get; } = new(); public virtual List<Product> Products { get; } = new();
//public virtual ServiceProvider ServiceProvider { get; set; } = new(); //public virtual ServiceProvider ServiceProvider { get; set; } = new();
public virtual List<UserProductMapping> UserProductMappings { get; set; } = new(); public virtual List<UserProductMapping> UserProductMappings { get; } = new();
public User() { } public User() { }
public User(string email, string password) : this(Guid.NewGuid(), email, password) { } public User(string email, string password) : this(Guid.NewGuid(), email, password) { }

View File

@ -0,0 +1,13 @@
using TIAM.Entities.Profiles;
namespace TIAM.Models.Dtos.Profiles;
public class ProfileDto : IProfileDto
{
public Guid Id { get; set; }
public Guid OwnerId { get; set; }
public Guid? UserMediaId { get; set; }
public string? Name { get; set; }
public string? ThumbnailUrl { get; set; }
}

View File

@ -0,0 +1,9 @@
using AyCode.Interfaces.Users.Dtos;
using TIAM.Entities.Users;
namespace TIAM.Models.Dtos.Users;
public class UserDto : IUserDto
{
public Guid Id { get; set; }
}

View File

@ -0,0 +1,29 @@
using AyCode.Entities.Profiles;
using AyCode.Interfaces.Users.Dtos;
using AyCode.Models.Users;
using TIAM.Entities.Products;
using TIAM.Entities.Profiles;
using TIAM.Entities.Users;
using TIAM.Models.Dtos.Profiles;
namespace TIAM.Models.Dtos.Users;
public class UserModelDto : AcUserModelDtoBase<UserDto, Profile, ProfileDto>
{
public List<UserProductMapping> UserProductMappings = new();
public List<Product> Products = new();
public UserModelDto(){}
public UserModelDto(User user, Profile profile, List<UserProductMapping> userProductMappings, List<Product> products) : base(user, profile)
{
foreach (var product in products)
{
Products.Add(new Product(product.Id, product.ServiceProviderId, product.ProductType, product.Name, product.Description, product.Price, product.JsonDetails));
}
foreach (var userProduct in userProductMappings)
{
UserProductMappings.Add(new UserProductMapping(userProduct.Id, userProduct.UserId, userProduct.ProductId));
}
}
}

View File

@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Dtos\Profiles\" />
<Folder Include="Dtos\UserProductMappings\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TIAM.Core\TIAM.Core.csproj" />
<ProjectReference Include="..\TIAM.Entities.Server\TIAM.Entities.Server.csproj" />
<ProjectReference Include="..\TIAM.Entities\TIAM.Entities.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="AyCode.Core">
<HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Core.dll</HintPath>
</Reference>
<Reference Include="AyCode.Entities">
<HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Entities.dll</HintPath>
</Reference>
<Reference Include="AyCode.Interfaces">
<HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Interfaces.dll</HintPath>
</Reference>
<Reference Include="AyCode.Models">
<HintPath>..\..\AyCode.Core\AyCode.Services.Server\bin\Debug\net8.0\AyCode.Models.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@ -6,7 +6,6 @@ using TIAM.Database.DataLayers.ServiceProviders;
using TIAM.Database.DataLayers.Users; using TIAM.Database.DataLayers.Users;
using TIAM.Entities.Permissions; using TIAM.Entities.Permissions;
using TIAM.Entities.Products; using TIAM.Entities.Products;
using TIAM.Entities.Products.DTOs;
using TIAM.Entities.ServiceProviders; using TIAM.Entities.ServiceProviders;
using TIAM.Entities.Users; using TIAM.Entities.Users;
using TIAMWebApp.Shared.Application.Models; using TIAMWebApp.Shared.Application.Models;

View File

@ -25,6 +25,7 @@
<ProjectReference Include="..\..\TIAM.Database\TIAM.Database.csproj" /> <ProjectReference Include="..\..\TIAM.Database\TIAM.Database.csproj" />
<ProjectReference Include="..\..\TIAM.Entities.Server\TIAM.Entities.Server.csproj" /> <ProjectReference Include="..\..\TIAM.Entities.Server\TIAM.Entities.Server.csproj" />
<ProjectReference Include="..\..\TIAM.Entities\TIAM.Entities.csproj" /> <ProjectReference Include="..\..\TIAM.Entities\TIAM.Entities.csproj" />
<ProjectReference Include="..\..\TIAM.Models\TIAM.Models.csproj" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -33,6 +33,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Blazor.Models", "..\
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Blazor.Models.Server", "..\Aycode.Blazor\AyCode.Blazor.Models.Server\AyCode.Blazor.Models.Server.csproj", "{A36322E8-F485-455E-84AA-B911948B6702}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AyCode.Blazor.Models.Server", "..\Aycode.Blazor\AyCode.Blazor.Models.Server\AyCode.Blazor.Models.Server.csproj", "{A36322E8-F485-455E-84AA-B911948B6702}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TIAM.Models", "TIAM.Models\TIAM.Models.csproj", "{6037FF79-88D2-457C-BA3A-9AC978873741}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -101,6 +103,10 @@ Global
{A36322E8-F485-455E-84AA-B911948B6702}.Debug|Any CPU.Build.0 = Debug|Any CPU {A36322E8-F485-455E-84AA-B911948B6702}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A36322E8-F485-455E-84AA-B911948B6702}.Release|Any CPU.ActiveCfg = Release|Any CPU {A36322E8-F485-455E-84AA-B911948B6702}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A36322E8-F485-455E-84AA-B911948B6702}.Release|Any CPU.Build.0 = Release|Any CPU {A36322E8-F485-455E-84AA-B911948B6702}.Release|Any CPU.Build.0 = Release|Any CPU
{6037FF79-88D2-457C-BA3A-9AC978873741}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6037FF79-88D2-457C-BA3A-9AC978873741}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6037FF79-88D2-457C-BA3A-9AC978873741}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6037FF79-88D2-457C-BA3A-9AC978873741}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE