Implement User, Product, ServiceProvider relations mapping; refactoring, improvements, fixes, etc...
This commit is contained in:
parent
231119963e
commit
80eaf66d17
|
|
@ -9,6 +9,8 @@ using TIAM.Database.DataLayers.ServiceProviders;
|
|||
using TIAM.Database.DataLayers.Users;
|
||||
using TIAM.Database.DbContexts.ServiceProviders;
|
||||
using TIAM.Database.DbSets.Permissions;
|
||||
using TIAM.Entities.Products;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.Test
|
||||
{
|
||||
|
|
@ -29,12 +31,10 @@ namespace TIAM.Database.Test
|
|||
public void GetPermissionViewBySubjectId_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string subjectIdString)
|
||||
{
|
||||
var subjectId= Guid.Parse(subjectIdString);
|
||||
|
||||
//var permMapping = Dal.GetPermissionByContextId(contextId);
|
||||
var permMapping = Dal.GetPermissionContextsViewBySubjectId(subjectId).ToList();
|
||||
|
||||
Assert.IsNotNull(permMapping, "Result is null");
|
||||
Assert.IsTrue(permMapping.Count > 0, "Result count: 0");
|
||||
Assert.IsNotNull(permMapping, "PermissionContextsView is null");
|
||||
Assert.IsTrue(permMapping.Count > 0, "PermissionContextsView count: 0");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
@ -42,12 +42,10 @@ namespace TIAM.Database.Test
|
|||
public void GetPermissionViewByContextId_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string contextIdString)
|
||||
{
|
||||
var contextId = Guid.Parse(contextIdString);
|
||||
|
||||
//var permMapping = Dal.GetPermissionByContextId(contextId);
|
||||
var permMapping = Dal.GetPermissionContextsViewByContextId(contextId).ToList();
|
||||
|
||||
Assert.IsNotNull(permMapping, "Result is null");
|
||||
Assert.IsTrue(permMapping.Count > 0, "Result count: 0");
|
||||
Assert.IsNotNull(permMapping, "PermissionContextsView is null");
|
||||
Assert.IsTrue(permMapping.Count > 0, "PermissionContextsView count: 0");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
@ -55,22 +53,55 @@ namespace TIAM.Database.Test
|
|||
public async Task GetPermissionContextMappingByContextIdAsync_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string contextIdString)
|
||||
{
|
||||
var contextId = Guid.Parse(contextIdString);
|
||||
|
||||
var permMapping = await Dal.GetPermissionContextsViewByContextIdAsync(contextId);
|
||||
|
||||
Assert.IsNotNull(permMapping, "Result is null");
|
||||
Assert.IsTrue(permMapping.Count > 0, "Result count: 0");
|
||||
Assert.IsNotNull(permMapping, "PermissionContextsView is null");
|
||||
Assert.IsTrue(permMapping.Count > 0, "PermissionContextsView count: 0");
|
||||
}
|
||||
|
||||
public Product GetProductById_ReturnsProduct_WhenProductExists(string productIdString)
|
||||
{
|
||||
var productId = Guid.Parse(productIdString);
|
||||
var product = Dal.GetProductById(productId);
|
||||
|
||||
Assert.IsNotNull(product, "Product is null");
|
||||
|
||||
return product;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("814B5495-C2E9-4F1D-A73F-37CD5D353078")]
|
||||
public void GetProductById_ReturnsProduct_WhenProductExists(string productIdString)
|
||||
[DataRow("814b5495-c2e9-4f1d-a73f-37cd5d353078")]
|
||||
public void GeProductById_ReturnsProduct_WherHasUserProductMappingRelation(string productIdString)
|
||||
{
|
||||
var productId = Guid.Parse(productIdString);
|
||||
var product = GetProductById_ReturnsProduct_WhenProductExists(productIdString);
|
||||
|
||||
var product = Dal.GetProductById(productId);
|
||||
|
||||
Assert.IsNotNull(product, "Result is null");
|
||||
Assert.IsTrue(product.UserProductMappings.Count > 0, "UserProductMappings count: 0");
|
||||
Assert.IsNotNull(product.UserProductMappings[0].User, "User is null");
|
||||
Assert.IsNotNull(product.ServiceProvider, "ServiceProvider is null");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
||||
public void GetUserById_ReturnsUser_WherHasUserProductMappingRelation(string userIdString)
|
||||
{
|
||||
var userId = Guid.Parse(userIdString);
|
||||
var user = Dal.GetUserById(userId);
|
||||
|
||||
Assert.IsNotNull(user);
|
||||
Assert.IsTrue(user.UserProductMappings.Count > 0, "UserProductMappings count: 0");
|
||||
Assert.IsNotNull(user.UserProductMappings[0].Product, "Product is null");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[DataRow("a24bf07a-76a7-48a4-813f-4a77e515b2f3")]
|
||||
public void GetUserProductMappingById_ReturnsUserProductMapping_WherHasUserAndProductRelation(string userProductMappingIdString)
|
||||
{
|
||||
var userProductMappingId = Guid.Parse(userProductMappingIdString);
|
||||
var userProductMapping = Dal.GetUserProductMappingById(userProductMappingId);
|
||||
|
||||
Assert.IsNotNull(userProductMapping);
|
||||
Assert.IsNotNull(userProductMapping.User, "User is null");
|
||||
Assert.IsNotNull(userProductMapping.Product, "Product is null");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,8 @@ namespace TIAM.Database.Test
|
|||
public override Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
|
||||
=> base.GetUserByEmailAsync_ReturnsUser_WhenUserExists(email);
|
||||
|
||||
|
||||
|
||||
//[TestMethod]
|
||||
//[DataRow("test@tiam.hu")]
|
||||
//public async Task GetUserByEmailAsync_ReturnsUser_WhenUserExists(string email)
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ using TIAM.Database.DbContexts.ServiceProviders;
|
|||
using TIAM.Database.DbSets.Permissions;
|
||||
using TIAM.Database.DbSets.Users;
|
||||
using AyCode.Database.DataLayers;
|
||||
using AyCode.Database.DbSets.Users;
|
||||
using TIAM.Database.DbSets.Products;
|
||||
|
||||
|
||||
|
|
@ -30,6 +31,11 @@ namespace TIAM.Database.DataLayers.ServiceProviders
|
|||
{
|
||||
}
|
||||
|
||||
public User? GetUserById(Guid userId, bool autoInclude = true) => Session(x => x.GetUserById(userId, autoInclude));
|
||||
public User? GetUserByEmail(string email, bool autoInclude = true) => Session(x => x.GetUserByEmail(email, autoInclude));
|
||||
|
||||
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId) => Session(x => x.GetUserProductMappingById(userProductMappingId));
|
||||
|
||||
#region ServiceProviders
|
||||
|
||||
//16. (IServiceProviderDataService) get all service providers
|
||||
|
|
|
|||
|
|
@ -30,10 +30,7 @@ namespace TIAM.Database.DbContexts.Admins
|
|||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.EnableDetailedErrors(true);
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,10 +34,7 @@ namespace TIAM.Database.DbContexts.Auctions
|
|||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.EnableDetailedErrors(true);
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ namespace TIAM.Database.DbContexts
|
|||
{
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
|
||||
optionsBuilder.EnableDetailedErrors(true);
|
||||
|
||||
//optionsBuilder.UseSqlServer(Configuration.GetConnectionString("DeveloperDbConnection"));
|
||||
var connString = "Data Source=185.51.190.197;Initial Catalog=TIAM_DEV;Trusted_Connection=false;Encrypt=false;TrustServerCertificate=True;Connect Timeout=200;User ID=Anata_Development_Team;Password=v6f_?xNfg9N1;MultipleActiveResultSets=true";
|
||||
optionsBuilder.UseSqlServer(connString);
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
using TIAM.Database.DbSets.Permissions;
|
||||
using AyCode.Database.DbSets.Users;
|
||||
using TIAM.Database.DbSets.Permissions;
|
||||
using TIAM.Database.DbSets.Products;
|
||||
using TIAM.Database.DbSets.ServiceProvider;
|
||||
using TIAM.Database.DbSets.Users;
|
||||
|
||||
namespace TIAM.Database.DbContexts.ServiceProviders;
|
||||
|
||||
public interface IServiceProviderDbContext : IServiceProviderDbSet, IProductDbSet, IAssignedUserDbSet, IPermissionsDbSetContext
|
||||
public interface IServiceProviderDbContext : IServiceProviderDbSet, IProductDbSet, IUserProductMappingDbSet, IUserDbSet, IPermissionsDbSetContext
|
||||
{
|
||||
}
|
||||
|
|
@ -8,6 +8,8 @@ using AyCode.Database.DbContexts.Users;
|
|||
using AyCode.Entities.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Database.DbContexts.Users;
|
||||
using TIAM.Database.ModelBuilders.Products;
|
||||
using TIAM.Database.ModelBuilders.Users;
|
||||
using TIAM.Entities.Permissions;
|
||||
using TIAM.Entities.Products;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
|
|
@ -17,10 +19,13 @@ namespace TIAM.Database.DbContexts.ServiceProviders
|
|||
{
|
||||
public class ServiceProviderDbContext : DbContextBase, IServiceProviderDbContext
|
||||
{
|
||||
public DbSet<TiamServiceProvider> ServiceProviders { get; set; }
|
||||
public DbSet<Product> Products { get; set; }
|
||||
public DbSet<User> Users { get; set; }
|
||||
public DbSet<UserProductMapping> UserProductMappings { get; set; }
|
||||
|
||||
public DbSet<Product> Products { get; set; }
|
||||
public DbSet<TiamServiceProvider> ServiceProviders { get; set; }
|
||||
|
||||
|
||||
public DbSet<PermissionsType> PermissionsTypes { get; set; }
|
||||
public DbSet<PermissionGroup> PermissionGroups { get; set; }
|
||||
public DbSet<PermissionGroupUserMapping> PermissionGroupUserMappings { get; set; }
|
||||
|
|
@ -46,8 +51,17 @@ namespace TIAM.Database.DbContexts.ServiceProviders
|
|||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.EnableDetailedErrors(true);
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
|
||||
new UserProductMappingEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<UserProductMapping>());
|
||||
|
||||
new ProductEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<Product>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AyCode.Database.DbContexts;
|
||||
|
|
@ -8,6 +10,8 @@ using AyCode.Database.DbContexts.Users;
|
|||
using AyCode.Entities.Users;
|
||||
using AyCode.Interfaces.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using TIAM.Database.ModelBuilders.Users;
|
||||
using TIAM.Entities.Permissions;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
|
|
@ -39,8 +43,14 @@ namespace TIAM.Database.DbContexts.Users
|
|||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.EnableDetailedErrors(true);
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
new UserEntityTypeDefaultConfiguration().Configure(modelBuilder.Entity<User>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,19 @@ namespace TIAM.Database.DbSets.Products;
|
|||
public static class ProductDbSetExtensins
|
||||
{
|
||||
#region Add, Update, Remove
|
||||
|
||||
public static bool AddProduct(this IProductDbSet ctx, Product product)
|
||||
=> ctx.Products.Add(product).State == EntityState.Added;
|
||||
|
||||
#endregion Add, Update, Remove
|
||||
|
||||
public static Product? GetProductById(this IProductDbSet ctx, Guid productId)
|
||||
=> ctx.Products.FirstOrDefault(x => x.Id == productId);
|
||||
public static IQueryable<Product> ProductsWithUserRelations(this IProductDbSet ctx, bool autoInclude = true)
|
||||
=> autoInclude
|
||||
? ctx.Products
|
||||
.Include(x => x.UserProductMappings)
|
||||
.ThenInclude(x => x.User)
|
||||
: ctx.Products;
|
||||
|
||||
public static Product? GetProductById(this IProductDbSet ctx, Guid productId, bool includeUsers = true)
|
||||
=> ctx.ProductsWithUserRelations(includeUsers).FirstOrDefault(x => x.Id == productId);
|
||||
}
|
||||
|
|
@ -3,7 +3,7 @@ using TIAM.Entities.Users;
|
|||
|
||||
namespace TIAM.Database.DbSets.Users;
|
||||
|
||||
public interface IAssignedUserDbSet
|
||||
public interface IUserProductMappingDbSet
|
||||
{
|
||||
public DbSet<UserProductMapping> UserProductMappings { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.DbSets.Users;
|
||||
|
||||
public static class UserDbSetExtensions
|
||||
{
|
||||
public static IQueryable<User> UsersWithProductRelations(this IUserDbSet ctx, bool autoInclude = true)
|
||||
=> autoInclude
|
||||
? ctx.Users
|
||||
.Include(x => x.UserProductMappings)
|
||||
.ThenInclude(x => x.Product)
|
||||
: ctx.Users;
|
||||
|
||||
//public static IQueryable<User> UsersWithServiceProviderRelations(this IUserDbSet ctx, bool autoInclude = true)
|
||||
// => autoInclude
|
||||
// ? ctx.Users
|
||||
// .Include(x => x.UserProductMappings)
|
||||
// .ThenInclude(x => x.Product)
|
||||
// : ctx.Users;
|
||||
|
||||
public static User? GetUserById(this IUserDbSet ctx, Guid userId, bool autoInclude)
|
||||
=> ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.Id == userId);
|
||||
|
||||
public static User? GetUserByEmail(this IUserDbSet ctx, string email, bool autoInclude)
|
||||
=> ctx.UsersWithProductRelations(autoInclude).FirstOrDefault(x => x.EmailAddress == email);
|
||||
}
|
||||
|
|
@ -1,13 +1,26 @@
|
|||
using TIAM.Database.DbContexts.ServiceProviders;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using TIAM.Database.DbContexts.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.DbSets.Users;
|
||||
|
||||
public static class UserProductMappingDbSetExtensions
|
||||
{
|
||||
public static UserProductMapping? GetUserProductMappingById(this IAssignedUserDbSet ctx, Guid userProductMappingId)
|
||||
=> ctx.UserProductMappings.FirstOrDefault(x => x.Id == userProductMappingId);
|
||||
public static IQueryable<UserProductMapping> UserProductMappingsWithRelations(this IUserProductMappingDbSet ctx, bool autoInclude = true)
|
||||
=> autoInclude
|
||||
? ctx.UserProductMappings.Include(x => x.User).Include(x => x.Product)
|
||||
: ctx.UserProductMappings;
|
||||
|
||||
public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IAssignedUserDbSet ctx, Guid productId)
|
||||
=> ctx.UserProductMappings.Where(x => x.ProductId == productId);
|
||||
|
||||
public static UserProductMapping? GetUserProductMappingById(this IUserProductMappingDbSet ctx, Guid userProductMappingId)
|
||||
=> ctx.UserProductMappingsWithRelations().FirstOrDefault(x => x.Id == userProductMappingId);
|
||||
|
||||
public static UserProductMapping? GetUserProductMapping(this IUserProductMappingDbSet ctx, Guid userId, Guid productId)
|
||||
=> ctx.UserProductMappingsWithRelations().FirstOrDefault(x => x.UserId == userId && x.ProductId == productId);
|
||||
|
||||
public static IQueryable<UserProductMapping> GetUserProductMappingsByUserId(this IUserProductMappingDbSet ctx, Guid userId)
|
||||
=> ctx.UserProductMappingsWithRelations().Where(x => x.UserId == userId);
|
||||
|
||||
public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId)
|
||||
=> ctx.UserProductMappingsWithRelations().Where(x => x.ProductId == productId);
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
using System.Security.Cryptography.X509Certificates;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using TIAM.Entities.Users;
|
||||
using TIAM.Entities.Products;
|
||||
|
||||
namespace TIAM.Database.ModelBuilders.Products;
|
||||
|
||||
public static class ProductEntityTypeBuilderExtensions
|
||||
{
|
||||
#region Product
|
||||
|
||||
public static void BuildProductToUserProductMappingRelation(this EntityTypeBuilder<Product> modelBuilder, bool autoInclude = true)
|
||||
{
|
||||
modelBuilder
|
||||
.HasMany(e => e.UserProductMappings)
|
||||
.WithOne(e => e.Product).HasForeignKey(x => x.ProductId);
|
||||
|
||||
modelBuilder.Navigation(e => e.UserProductMappings).AutoInclude(autoInclude);
|
||||
}
|
||||
|
||||
public static void BuildProductToServiceProviderRelation(this EntityTypeBuilder<Product> modelBuilder, bool autoInclude = true)
|
||||
{
|
||||
modelBuilder
|
||||
.HasOne(x => x.ServiceProvider)
|
||||
.WithMany(x => x.Products)
|
||||
.HasForeignKey(x => x.ServiceProviderId);
|
||||
|
||||
modelBuilder.Navigation(e => e.ServiceProvider).AutoInclude(autoInclude);
|
||||
}
|
||||
|
||||
#endregion Product
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
using AyCode.Database.DbContexts;
|
||||
using AyCode.Database.ModelBuilders.Users;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using TIAM.Database.ModelBuilders.Users;
|
||||
using TIAM.Entities.Products;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.ModelBuilders.Products;
|
||||
|
||||
public class ProductEntityTypeDefaultConfiguration : IAcEntityTypeConfiguration<Product>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<Product> builder)
|
||||
{
|
||||
builder.BuildProductToUserProductMappingRelation();
|
||||
builder.BuildProductToServiceProviderRelation();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
using AyCode.Interfaces.Users;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System.Numerics;
|
||||
using TIAM.Entities.Products;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.ModelBuilders.Users;
|
||||
|
||||
public static class UserEntityTypeBuilderExtensions
|
||||
{
|
||||
#region User
|
||||
|
||||
public static void BuildUserToUserProductMappingRelation(this EntityTypeBuilder<User> modelBuilder, bool autoInclude = true)
|
||||
{
|
||||
//modelBuilder
|
||||
// .HasMany(e => e.Products)
|
||||
// .WithMany(e => e.Users)
|
||||
//.UsingEntity<UserProductMapping>();
|
||||
|
||||
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.UserProductMappings).AutoInclude(autoInclude);
|
||||
}
|
||||
|
||||
#endregion User
|
||||
|
||||
#region UserProductMapping
|
||||
/// <summary>
|
||||
/// Mapping User and Product relations
|
||||
/// </summary>
|
||||
public static void BuildUserProductMappingToRelations(this EntityTypeBuilder<UserProductMapping> modelBuilder, bool autoInclude)
|
||||
{
|
||||
modelBuilder.BuildUserProductMappingToUserRelation(autoInclude);
|
||||
modelBuilder.BuildUserProductMappingToProductRelation(autoInclude);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mapping User relation
|
||||
/// </summary>
|
||||
public static void BuildUserProductMappingToUserRelation(this EntityTypeBuilder<UserProductMapping> modelBuilder, bool autoInclude)
|
||||
{
|
||||
modelBuilder
|
||||
.HasOne(e => e.User)
|
||||
.WithMany(e => e.UserProductMappings).HasForeignKey(x => x.UserId);
|
||||
|
||||
modelBuilder.Navigation(e => e.User).AutoInclude(autoInclude);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mapping Product relation
|
||||
/// </summary>
|
||||
public static void BuildUserProductMappingToProductRelation(this EntityTypeBuilder<UserProductMapping> modelBuilder, bool autoInclude)
|
||||
{
|
||||
modelBuilder
|
||||
.HasOne(e => e.Product)
|
||||
.WithMany(e => e.UserProductMappings).HasForeignKey(x => x.ProductId);
|
||||
|
||||
modelBuilder.Navigation(e => e.Product).AutoInclude(autoInclude);
|
||||
}
|
||||
|
||||
#endregion UserProductMapping
|
||||
|
||||
public static void BuildUserToServiceProviderRelation<TUser>(this EntityTypeBuilder<TUser> modelBuilder) where TUser : class, IUserBase
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using AyCode.Database.DbContexts;
|
||||
using AyCode.Database.ModelBuilders.Users;
|
||||
using AyCode.Interfaces.Users;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Database.ModelBuilders.Users;
|
||||
|
||||
public class UserProductMappingEntityTypeDefaultConfiguration : IAcEntityTypeConfiguration<UserProductMapping>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<UserProductMapping> builder)
|
||||
{
|
||||
builder.BuildUserProductMappingToRelations(false);
|
||||
}
|
||||
}
|
||||
|
||||
public class UserEntityTypeDefaultConfiguration : IAcEntityTypeConfiguration<User>//AcUserEntityTypeDefaultConfiguration<User>
|
||||
{
|
||||
public /*override*/ void Configure(EntityTypeBuilder<User> builder)
|
||||
{
|
||||
//base.Configure(builder);
|
||||
|
||||
builder.BuildUserToUserProductMappingRelation();
|
||||
builder.BuildUserToServiceProviderRelation();
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@ using System.ComponentModel.DataAnnotations.Schema;
|
|||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
using TIAM.Core;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
using TIAM.Entities.Users;
|
||||
|
||||
namespace TIAM.Entities.Products;
|
||||
|
||||
|
|
@ -11,6 +13,9 @@ public class Product : ProductBase
|
|||
{
|
||||
public Guid ServiceProviderId { get; set; }
|
||||
|
||||
public virtual TiamServiceProvider ServiceProvider { get; set; }
|
||||
public virtual List<UserProductMapping> UserProductMappings { get; } = new();
|
||||
|
||||
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) { }
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
|
||||
namespace TIAM.Entities.Products;
|
||||
|
||||
[Table("ServiceProvider")]
|
||||
public class ServiceProvider : IEntityGuid, ITimeStampInfo
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
public Guid Id { get; set; }
|
||||
public Guid OwnerId { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Entities.ServiceProviders;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
using TIAM.Entities.Products;
|
||||
|
||||
namespace TIAM.Entities.ServiceProviders;
|
||||
|
||||
[Table("ServiceProviders")]
|
||||
public class TiamServiceProvider : ServiceProviderBase
|
||||
{
|
||||
public virtual List<Product> Products { get; } = new();
|
||||
|
||||
public TiamServiceProvider(){}
|
||||
public TiamServiceProvider(string name, Guid ownerId) : this(Guid.NewGuid(), name, ownerId) { }
|
||||
public TiamServiceProvider(Guid id, string name, Guid ownerId) : base(id, name, ownerId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AyCode.Entities.ServiceProviders;
|
||||
|
||||
|
||||
namespace TIAM.Entities.ServiceProviders
|
||||
{
|
||||
public class TiamServiceProvider : ServiceProviderBase
|
||||
{
|
||||
public TiamServiceProvider() { }
|
||||
public TiamServiceProvider(string name, Guid ownerId) : this(Guid.NewGuid(), name, ownerId) { }
|
||||
public TiamServiceProvider(Guid id, string name, Guid ownerId) : base(id, name, ownerId)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -4,11 +4,17 @@ using System.Linq;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AyCode.Entities.Users;
|
||||
using TIAM.Entities.Products;
|
||||
|
||||
namespace TIAM.Entities.Users
|
||||
{
|
||||
public class User : UserBase
|
||||
{
|
||||
//public virtual List<Product> Products { get; } = new();
|
||||
|
||||
//public virtual ServiceProvider ServiceProvider { get; set; } = new();
|
||||
public virtual List<UserProductMapping> UserProductMappings { get; } = new();
|
||||
|
||||
public User() { }
|
||||
public User(string email, string password) : this(Guid.NewGuid(), email, password) { }
|
||||
public User(Guid id, string email, string password) : base(id, email, password)
|
||||
|
|
|
|||
|
|
@ -2,31 +2,34 @@
|
|||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
using TIAM.Entities.Products;
|
||||
|
||||
namespace TIAM.Entities.Users;
|
||||
|
||||
[Table("UserProductMapping")]
|
||||
public class UserProductMapping : IEntityGuid, ITimeStampInfo
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public Guid Id { get; set; }
|
||||
public Guid UserId { get; set; }
|
||||
public Guid ProductId { get; set; }
|
||||
|
||||
|
||||
public virtual User User { get; set; }
|
||||
public virtual Product Product { get; set; }
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
|
||||
public UserProductMapping()
|
||||
{ }
|
||||
|
||||
public UserProductMapping(Guid userId, Guid productId) : this(Guid.NewGuid(), userId, productId)
|
||||
{
|
||||
|
||||
}
|
||||
{ }
|
||||
|
||||
public UserProductMapping(Guid id, Guid userId, Guid productId)
|
||||
{
|
||||
Id = id;
|
||||
UserId = userId;
|
||||
ProductId = productId;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using AyCode.Interfaces.Entities;
|
||||
using AyCode.Interfaces.TimeStampInfo;
|
||||
using TIAM.Entities.Products;
|
||||
using TIAM.Entities.ServiceProviders;
|
||||
|
||||
namespace TIAM.Entities.Users;
|
||||
|
||||
[Table("UserServiceProviderMapping")]
|
||||
public class UserServiceProviderMapping : IEntityGuid, ITimeStampInfo
|
||||
{
|
||||
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
public Guid Id { get; set; }
|
||||
|
||||
public Guid UserId { get; set; }
|
||||
public Guid ServiceProviderId { get; set; }
|
||||
|
||||
public virtual User User { get; set; }
|
||||
public virtual TiamServiceProvider ServiceProvider { get; set; }
|
||||
|
||||
public DateTime Created { get; set; }
|
||||
public DateTime Modified { get; set; }
|
||||
|
||||
public UserServiceProviderMapping() { }
|
||||
}
|
||||
|
|
@ -116,7 +116,7 @@ namespace TIAMWebApp.Server.Controllers
|
|||
|
||||
//return serviceProviders.Where(x => x.OwnerId == ownerId).ToList();
|
||||
var myServiceproviders = serviceProviders.Where(x => x.OwnerId == ownerId).ToDictionary(x => x.Id, x => x.Name);
|
||||
//put serviceprovider id and name into a dictionary
|
||||
//put TiamServiceProvider id and name into a dictionary
|
||||
|
||||
return myServiceproviders;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue