Add UserProductMapping CRUD; Add Car entity; imptovements, fixes, etc...
This commit is contained in:
parent
41b084ade4
commit
2d75c081f7
|
|
@ -32,7 +32,7 @@ namespace TIAM.Database.Test
|
||||||
public void TearDown()
|
public void TearDown()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DataRow("42968456-6EF3-4D9C-8BC4-0569A129AC05")]
|
[DataRow("42968456-6EF3-4D9C-8BC4-0569A129AC05")]
|
||||||
public void GetPermissionViewBySubjectId_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string subjectIdString)
|
public void GetPermissionViewBySubjectId_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string subjectIdString)
|
||||||
{
|
{
|
||||||
|
|
@ -43,7 +43,7 @@ namespace TIAM.Database.Test
|
||||||
Assert.IsTrue(permMapping.Count > 0, "PermissionContextsView count: 0");
|
Assert.IsTrue(permMapping.Count > 0, "PermissionContextsView count: 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DataRow("814b5495-c2e9-4f1d-a73f-37cd5d353078")]
|
[DataRow("814b5495-c2e9-4f1d-a73f-37cd5d353078")]
|
||||||
public void GetPermissionViewByContextId_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string contextIdString)
|
public void GetPermissionViewByContextId_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string contextIdString)
|
||||||
{
|
{
|
||||||
|
|
@ -54,7 +54,7 @@ namespace TIAM.Database.Test
|
||||||
Assert.IsTrue(permMapping.Count > 0, "PermissionContextsView count: 0");
|
Assert.IsTrue(permMapping.Count > 0, "PermissionContextsView count: 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DataRow("814b5495-c2e9-4f1d-a73f-37cd5d353078")]
|
[DataRow("814b5495-c2e9-4f1d-a73f-37cd5d353078")]
|
||||||
public async Task GetPermissionContextMappingByContextIdAsync_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string contextIdString)
|
public async Task GetPermissionContextMappingByContextIdAsync_ReturnsPermissionContextMapping_WhenPermissionContextMappingExists(string contextIdString)
|
||||||
{
|
{
|
||||||
|
|
@ -75,9 +75,9 @@ namespace TIAM.Database.Test
|
||||||
return product;
|
return product;
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DataRow("814b5495-c2e9-4f1d-a73f-37cd5d353078")]
|
[DataRow("814b5495-c2e9-4f1d-a73f-37cd5d353078")]
|
||||||
public void GeProductById_ReturnsProduct_WherHasUserProductMappingRelation(string productIdString)
|
public void GeProductById_ReturnsProduct_WhenHasUserProductMappingRelation(string productIdString)
|
||||||
{
|
{
|
||||||
var product = GetProductById_ReturnsProduct_WhenProductExists(productIdString);
|
var product = GetProductById_ReturnsProduct_WhenProductExists(productIdString);
|
||||||
|
|
||||||
|
|
@ -86,9 +86,9 @@ namespace TIAM.Database.Test
|
||||||
Assert.IsNotNull(product.ServiceProvider, "ServiceProvider is null");
|
Assert.IsNotNull(product.ServiceProvider, "ServiceProvider is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
||||||
public void GetUserById_ReturnsUser_WherHasUserProductMappingRelation(string userIdString)
|
public void GetUserById_ReturnsUser_WhenHasUserProductMappingRelation(string userIdString)
|
||||||
{
|
{
|
||||||
var userId = Guid.Parse(userIdString);
|
var userId = Guid.Parse(userIdString);
|
||||||
var user = Dal.GetUserById(userId);
|
var user = Dal.GetUserById(userId);
|
||||||
|
|
@ -101,9 +101,10 @@ namespace TIAM.Database.Test
|
||||||
Assert.IsNotNull(user.UserProductMappings[0].Product, "Product is null");
|
Assert.IsNotNull(user.UserProductMappings[0].Product, "Product is null");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
#region UserProductMapping
|
||||||
|
[DataTestMethod]
|
||||||
[DataRow("a24bf07a-76a7-48a4-813f-4a77e515b2f3")]
|
[DataRow("a24bf07a-76a7-48a4-813f-4a77e515b2f3")]
|
||||||
public void GetUserProductMappingById_ReturnsUserProductMapping_WherHasUserAndProductRelation(string userProductMappingIdString)
|
public void GetUserProductMappingById_ReturnsUserProductMapping_WhenHasUserAndProductRelation(string userProductMappingIdString)
|
||||||
{
|
{
|
||||||
var userProductMappingId = Guid.Parse(userProductMappingIdString);
|
var userProductMappingId = Guid.Parse(userProductMappingIdString);
|
||||||
var userProductMapping = Dal.GetUserProductMappingById(userProductMappingId, true);
|
var userProductMapping = Dal.GetUserProductMappingById(userProductMappingId, true);
|
||||||
|
|
@ -115,7 +116,45 @@ namespace TIAM.Database.Test
|
||||||
Assert.IsTrue(userProductMapping.Id == userProductMappingId, "userProductMapping.Id != userProductMappingId");
|
Assert.IsTrue(userProductMapping.Id == userProductMappingId, "userProductMapping.Id != userProductMappingId");
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
|
[DataRow(new[] { "8EF2FC69-2338-4D9F-91B4-B1E15C241E1C", "814b5495-c2e9-4f1d-a73f-37cd5d353078" })]
|
||||||
|
public async Task SetUserProductMappingById_ReturnsUserProductMapping_WhenHasUserAndProductRelation(string[] userIdProductIdStrings)
|
||||||
|
{
|
||||||
|
var userId = Guid.Parse(userIdProductIdStrings[0]);
|
||||||
|
var productId = Guid.Parse(userIdProductIdStrings[1]);
|
||||||
|
var userProductMappingId = Guid.NewGuid();
|
||||||
|
|
||||||
|
await Dal.RemoveUserProductMappingAsync(userId, productId); //kitöröljük a szemetet, ha korábbról bentmaradt - J.
|
||||||
|
|
||||||
|
var userProductMapping = await Dal.AddUserProductMappingAsync(userProductMappingId, userId, productId, 2);
|
||||||
|
Assert.IsNotNull(userProductMapping);
|
||||||
|
|
||||||
|
userProductMapping = await Dal.GetUserProductMappingByIdAsync(userProductMappingId, true);
|
||||||
|
|
||||||
|
Assert.IsNotNull(userProductMapping);
|
||||||
|
|
||||||
|
//userProductMapping.Permissions = 1;
|
||||||
|
Assert.IsNotNull(await Dal.UpdateUserProductMappingAsync(userProductMappingId, 1));
|
||||||
|
|
||||||
|
userProductMapping = await Dal.GetUserProductMappingByIdAsync(userProductMappingId, true);
|
||||||
|
|
||||||
|
Assert.IsNotNull(userProductMapping);
|
||||||
|
Assert.IsTrue(userProductMapping.Permissions == 1);
|
||||||
|
|
||||||
|
Assert.IsNotNull(userProductMapping.User, "User is null");
|
||||||
|
Assert.IsNotNull(userProductMapping.Product, "Product is null");
|
||||||
|
|
||||||
|
Assert.IsTrue(userProductMapping.Id == userProductMappingId, "userProductMapping.Id != userProductMappingId");
|
||||||
|
|
||||||
|
Assert.IsTrue(await Dal.RemoveUserProductMappingAsync(userProductMappingId)); //mielőbb kitöröljük, h ne maradjon szemét a db-ben - J.
|
||||||
|
|
||||||
|
userProductMapping = await Dal.GetUserProductMappingByIdAsync(userProductMappingId, false);
|
||||||
|
Assert.IsNull(userProductMapping); //a korábbi törlés miatt NULL kell legyen - J.
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion UserProductMapping
|
||||||
|
|
||||||
|
[DataTestMethod]
|
||||||
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
||||||
[DataRow("dcf451d2-cc4c-4ac2-8c1f-da00041be1fd")]
|
[DataRow("dcf451d2-cc4c-4ac2-8c1f-da00041be1fd")]
|
||||||
[DataRow("ac612aa8-863b-4b4f-9d63-f5d261b5c5f9")]
|
[DataRow("ac612aa8-863b-4b4f-9d63-f5d261b5c5f9")]
|
||||||
|
|
@ -149,7 +188,7 @@ namespace TIAM.Database.Test
|
||||||
Assert.IsTrue(userModel.UserToServiceProviders.Count > 0);
|
Assert.IsTrue(userModel.UserToServiceProviders.Count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
[DataRow("540271F6-C604-4C16-8160-D5A7CAFEDF00")]
|
||||||
[DataRow("dcf451d2-cc4c-4ac2-8c1f-da00041be1fd")]
|
[DataRow("dcf451d2-cc4c-4ac2-8c1f-da00041be1fd")]
|
||||||
[DataRow("ac612aa8-863b-4b4f-9d63-f5d261b5c5f9")]
|
[DataRow("ac612aa8-863b-4b4f-9d63-f5d261b5c5f9")]
|
||||||
|
|
@ -189,7 +228,7 @@ namespace TIAM.Database.Test
|
||||||
Assert.IsTrue(users.Count>0);
|
Assert.IsTrue(users.Count>0);
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[DataTestMethod]
|
||||||
[DataRow("273EFE3C-D19F-4C2A-BF19-7397DC835C60")]
|
[DataRow("273EFE3C-D19F-4C2A-BF19-7397DC835C60")]
|
||||||
public void GetTransferDestionationById_ReturnsTransferDestination_WhenHasAddressRelation(string transferDestinationIdString)
|
public void GetTransferDestionationById_ReturnsTransferDestination_WhenHasAddressRelation(string transferDestinationIdString)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -25,20 +25,21 @@ namespace TIAM.Database.DataLayers.Admins
|
||||||
public TransferDestination? GetTransferDestinationById(Guid transferDestinationId, bool autoInclude = false) => Session(ctx=>ctx.TransferDestinations.FirstOrDefault(x=>x.Id == transferDestinationId));
|
public TransferDestination? GetTransferDestinationById(Guid transferDestinationId, bool autoInclude = false) => Session(ctx=>ctx.TransferDestinations.FirstOrDefault(x=>x.Id == transferDestinationId));
|
||||||
public string? GetTransferDestinationJsonById(Guid transferDestinationId) => Session(ctx => ctx.TransferDestinations.FirstOrDefault(x => x.Id == transferDestinationId)?.ToJson());
|
public string? GetTransferDestinationJsonById(Guid transferDestinationId) => Session(ctx => ctx.TransferDestinations.FirstOrDefault(x => x.Id == transferDestinationId)?.ToJson());
|
||||||
|
|
||||||
public User? GetUserById(Guid userId, bool autoInclude = false) => Session(x => x.GetUserById(userId, autoInclude));
|
public User? GetUserById(Guid userId, bool autoInclude = false) => Session(ctx => ctx.GetUserById(userId, autoInclude));
|
||||||
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(x => x.GetUserByEmail(email, autoInclude));
|
public User? GetUserByEmail(string email, bool autoInclude = false) => Session(ctx => ctx.GetUserByEmail(email, autoInclude));
|
||||||
|
|
||||||
public UserModelDto? GetUserModelDtoById(Guid userId) => Session(x => x.GetUserModelDtoById(userId));
|
public UserModelDto? GetUserModelDtoById(Guid userId) => Session(ctx => ctx.GetUserModelDtoById(userId));
|
||||||
public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(x => x.GetUserModelDtoById(userId));
|
public Task<UserModelDto?> GetUserModelDtoByIdAsync(Guid userId) => SessionAsync(ctx => ctx.GetUserModelDtoById(userId));
|
||||||
public UserModelDto? GetUserModelDtoByEmail(string email) => Session(x => x.GetUserModelDtoByEmail(email));
|
public UserModelDto? GetUserModelDtoByEmail(string email) => Session(ctx => ctx.GetUserModelDtoByEmail(email));
|
||||||
|
|
||||||
public string? GetUserJsonById(Guid userId) => Session(ctx => ctx.GetUserById(userId)?.ToJson());
|
public string? GetUserJsonById(Guid userId) => Session(ctx => ctx.GetUserById(userId)?.ToJson());
|
||||||
public string GetUsersJson() => Session(ctx => ctx.Users.ToJson());
|
public string GetUsersJson() => Session(ctx => ctx.Users.ToJson());
|
||||||
|
|
||||||
public Product? GetProductById(Guid contextId) => Session(x => x.GetProductById(contextId));
|
public Product? GetProductById(Guid contextId) => Session(ctx => ctx.GetProductById(contextId));
|
||||||
public Task<bool> AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product));
|
public Task<bool> AddProduct(Product product) => TransactionAsync(ctx => ctx.AddProduct(product));
|
||||||
|
|
||||||
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(x => x.GetUserProductMappingById(userProductMappingId, autoInclude));
|
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
|
||||||
|
public Task<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
|
||||||
|
|
||||||
public List<PermissionContextMapping> GetPermissionContextsView(Guid subjectId, Guid contextId)
|
public List<PermissionContextMapping> GetPermissionContextsView(Guid subjectId, Guid contextId)
|
||||||
=> Session(x => x.GetPermissionContextsView(subjectId, contextId).ToList());
|
=> Session(x => x.GetPermissionContextsView(subjectId, contextId).ToList());
|
||||||
|
|
@ -52,6 +53,49 @@ namespace TIAM.Database.DataLayers.Admins
|
||||||
public Task<List<PermissionContextMapping>> GetPermissionContextsViewByContextIdAsync(Guid contextId)
|
public Task<List<PermissionContextMapping>> GetPermissionContextsViewByContextIdAsync(Guid contextId)
|
||||||
=> SessionAsync(x => x.GetPermissionContextsViewByContextId(contextId).ToList());
|
=> SessionAsync(x => x.GetPermissionContextsViewByContextId(contextId).ToList());
|
||||||
|
|
||||||
|
#region UserProductMapping
|
||||||
|
public Task<bool> AddUserProductMappingAsync(UserProductMapping userProductMapping)
|
||||||
|
=> TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping) && ctx.SaveChanges() == 1);
|
||||||
|
|
||||||
|
public async Task<UserProductMapping?> AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, string? jsonDetails = null)
|
||||||
|
{
|
||||||
|
UserProductMapping? userProductMapping = null;
|
||||||
|
|
||||||
|
var isSucces = await TransactionAsync(ctx =>
|
||||||
|
{
|
||||||
|
userProductMapping = ctx.AddUserProductMapping(userProductMappingId, userId, productId, permissions, jsonDetails);
|
||||||
|
|
||||||
|
return userProductMapping != null && ctx.SaveChanges() == 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return isSucces ? userProductMapping : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> UpdateUserProductMappingAsync(UserProductMapping userProductMapping)
|
||||||
|
=> TransactionAsync(ctx => ctx.UpdateUserProductMapping(userProductMapping) && ctx.SaveChanges() > 0);
|
||||||
|
|
||||||
|
public async Task<UserProductMapping?> UpdateUserProductMappingAsync(Guid userProductMappingId, int permissions = 1, string? jsonDetails = null)
|
||||||
|
{
|
||||||
|
UserProductMapping? userProductMapping = null;
|
||||||
|
|
||||||
|
var isSucces = await TransactionAsync(ctx =>
|
||||||
|
{
|
||||||
|
userProductMapping = ctx.UpdateUserProductMapping(userProductMappingId, permissions, jsonDetails);
|
||||||
|
|
||||||
|
return userProductMapping != null && ctx.SaveChanges() == 1;
|
||||||
|
});
|
||||||
|
|
||||||
|
return isSucces ? userProductMapping : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<bool> RemoveUserProductMappingAsync(Guid userProductMappingId)
|
||||||
|
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userProductMappingId) && ctx.SaveChanges() == 1);
|
||||||
|
|
||||||
|
public Task<bool> RemoveUserProductMappingAsync(Guid userId, Guid productId)
|
||||||
|
=> TransactionAsync(ctx => ctx.RemoveUserProductMapping(userId, productId) && ctx.SaveChanges() == 1);
|
||||||
|
|
||||||
|
#endregion UserProductMapping
|
||||||
|
|
||||||
//15. (IServiceProviderDataService) Create service provider
|
//15. (IServiceProviderDataService) Create service provider
|
||||||
public Task<bool> CreateServiceProviderAsync(TiamServiceProvider serviceProvider)
|
public Task<bool> CreateServiceProviderAsync(TiamServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
|
|
@ -78,12 +122,12 @@ namespace TIAM.Database.DataLayers.Admins
|
||||||
return Context.ServiceProviders.SingleOrDefaultAsync(x => x.Id == id);
|
return Context.ServiceProviders.SingleOrDefaultAsync(x => x.Id == id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<UserProductMapping> CreateUserProductMappingAsync(UserProductMapping userProductMapping)
|
//public Task<UserProductMapping> CreateUserProductMappingAsync(UserProductMapping userProductMapping)
|
||||||
{
|
//{
|
||||||
Context.UserProductMappings.Add(userProductMapping);
|
// Context.UserProductMappings.Add(userProductMapping);
|
||||||
Console.WriteLine($"Saving userProductMapping to db {userProductMapping.Id}, {userProductMapping.ProductId}, {userProductMapping.UserId}");
|
// Console.WriteLine($"Saving userProductMapping to db {userProductMapping.Id}, {userProductMapping.ProductId}, {userProductMapping.UserId}");
|
||||||
return Context.SaveChangesAsync().ContinueWith(x => userProductMapping);
|
// return Context.SaveChangesAsync().ContinueWith(x => userProductMapping);
|
||||||
}
|
//}
|
||||||
|
|
||||||
#region ServiceProviders
|
#region ServiceProviders
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,19 +77,6 @@ namespace TIAM.Database.DataLayers.Admins
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UserProductMapping UpdateUserProductMapping(this IAdminDbContext context, UserProductMapping userProductMapping)
|
|
||||||
{
|
|
||||||
if (userProductMapping == null) return null;
|
|
||||||
var existingUserProductMapping = context.UserProductMappings.FirstOrDefault(u => u.Id == userProductMapping.Id);
|
|
||||||
if (existingUserProductMapping == null) return null;
|
|
||||||
existingUserProductMapping.Id = userProductMapping.Id;
|
|
||||||
existingUserProductMapping.UserId = userProductMapping.UserId;
|
|
||||||
existingUserProductMapping.ProductId = userProductMapping.ProductId;
|
|
||||||
|
|
||||||
return existingUserProductMapping;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Product UpdateProduct(this IAdminDbContext ctx, Product product)
|
public static Product UpdateProduct(this IAdminDbContext ctx, Product product)
|
||||||
{
|
{
|
||||||
if (product == null) return null;
|
if (product == null) return null;
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using Microsoft.EntityFrameworkCore;
|
using AyCode.Utils.Extensions;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using TIAM.Database.DbContexts.ServiceProviders;
|
using TIAM.Database.DbContexts.ServiceProviders;
|
||||||
using TIAM.Entities.Users;
|
using TIAM.Entities.Users;
|
||||||
|
|
||||||
|
|
@ -11,7 +12,7 @@ public static class UserProductMappingDbSetExtensions
|
||||||
? ctx.UserProductMappings.Include(x => x.User).Include(x => x.Product)
|
? ctx.UserProductMappings.Include(x => x.User).Include(x => x.Product)
|
||||||
: ctx.UserProductMappings;
|
: ctx.UserProductMappings;
|
||||||
|
|
||||||
|
|
||||||
public static UserProductMapping? GetUserProductMappingById(this IUserProductMappingDbSet ctx, Guid userProductMappingId, bool autoInclude = true)
|
public static UserProductMapping? GetUserProductMappingById(this IUserProductMappingDbSet ctx, Guid userProductMappingId, bool autoInclude = true)
|
||||||
=> ctx.UserProductMappingsWithRelations(autoInclude).FirstOrDefault(x => x.Id == userProductMappingId);
|
=> ctx.UserProductMappingsWithRelations(autoInclude).FirstOrDefault(x => x.Id == userProductMappingId);
|
||||||
|
|
||||||
|
|
@ -23,4 +24,62 @@ public static class UserProductMappingDbSetExtensions
|
||||||
|
|
||||||
public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId, bool autoInclude = true)
|
public static IQueryable<UserProductMapping> GetUserProductMappingsByProductId(this IUserProductMappingDbSet ctx, Guid productId, bool autoInclude = true)
|
||||||
=> ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.ProductId == productId);
|
=> ctx.UserProductMappingsWithRelations(autoInclude).Where(x => x.ProductId == productId);
|
||||||
|
|
||||||
|
|
||||||
|
public static bool AddUserProductMapping(this IUserProductMappingDbSet ctx, UserProductMapping userProductMapping)
|
||||||
|
{
|
||||||
|
if (userProductMapping.UserId.IsNullOrEmpty() || userProductMapping.ProductId.IsNullOrEmpty() || userProductMapping.Permissions < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (userProductMapping.Id.IsNullOrEmpty())
|
||||||
|
userProductMapping.Id = Guid.NewGuid();
|
||||||
|
|
||||||
|
return ctx.UserProductMappings.Add(userProductMapping).State == EntityState.Added;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserProductMapping? AddUserProductMapping(this IUserProductMappingDbSet ctx, Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, string? jsonDetails = null)
|
||||||
|
{
|
||||||
|
var userProductMapping = new UserProductMapping(userProductMappingId, userId, productId, permissions, jsonDetails);
|
||||||
|
|
||||||
|
return ctx.AddUserProductMapping(userProductMapping) ? userProductMapping : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool UpdateUserProductMapping(this IUserProductMappingDbSet ctx, UserProductMapping userProductMapping)
|
||||||
|
{
|
||||||
|
if (userProductMapping.Id.IsNullOrEmpty() || userProductMapping.UserId.IsNullOrEmpty() || userProductMapping.ProductId.IsNullOrEmpty() || userProductMapping.Permissions < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return ctx.UserProductMappings.Update(userProductMapping).State == EntityState.Modified;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UserProductMapping? UpdateUserProductMapping(this IUserProductMappingDbSet ctx, Guid userProductMappingId, int permissions = 1, string? jsonDetails = null)
|
||||||
|
{
|
||||||
|
if (userProductMappingId.IsNullOrEmpty() || permissions < 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var userProductMapping = ctx.GetUserProductMappingById(userProductMappingId, false);
|
||||||
|
if (userProductMapping == null) return null;
|
||||||
|
|
||||||
|
userProductMapping.Permissions = permissions;
|
||||||
|
userProductMapping.JsonDetails = jsonDetails;
|
||||||
|
|
||||||
|
return ctx.UpdateUserProductMapping(userProductMapping) ? userProductMapping : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool RemoveUserProductMapping(this IUserProductMappingDbSet ctx, Guid userProductMappingId)
|
||||||
|
{
|
||||||
|
var userProductMapping = ctx.GetUserProductMappingById(userProductMappingId, false);
|
||||||
|
if (userProductMapping == null) return true;
|
||||||
|
|
||||||
|
return ctx.UserProductMappings.Remove(userProductMapping).State == EntityState.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool RemoveUserProductMapping(this IUserProductMappingDbSet ctx, Guid userId, Guid productId)
|
||||||
|
{
|
||||||
|
var userProductMapping = ctx.GetUserProductMapping(userId, productId, false);
|
||||||
|
if (userProductMapping == null) return true;
|
||||||
|
|
||||||
|
return ctx.UserProductMappings.Remove(userProductMapping).State == EntityState.Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -9,27 +9,24 @@ using AyCode.Interfaces.TimeStampInfo;
|
||||||
|
|
||||||
namespace TIAM.Entities.Drivers
|
namespace TIAM.Entities.Drivers
|
||||||
{
|
{
|
||||||
public enum CarMotorType : byte
|
|
||||||
{
|
|
||||||
Gas = 5,
|
|
||||||
Diesel = 10,
|
|
||||||
Electric = 15,
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Car : IEntityGuid, ITimeStampModified
|
public class Car : IEntityGuid, ITimeStampModified
|
||||||
{
|
{
|
||||||
public Guid Id { get; set; }
|
public Guid Id { get; set; }
|
||||||
|
|
||||||
|
public int CountryCode { get; set; }
|
||||||
|
|
||||||
public string LicencePlate { get; set; }
|
public string LicencePlate { get; set; }
|
||||||
public string Color { get; set; }
|
public string Color { get; set; }
|
||||||
public string Manufacture{ get; set; }
|
public string Manufacture{ get; set; }
|
||||||
public string Model { get; set; }
|
public string CarModel { get; set; }
|
||||||
|
|
||||||
public int YearOfMake { get; set; }
|
public int YearOfMake { get; set; }
|
||||||
public int SeetNumber { get; set; }
|
public int SeetNumber { get; set; }
|
||||||
|
|
||||||
public CarMotorType CarMotorType { get; set; }
|
public CarMotorType CarMotorType { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public DateTime Modified { get; set; }
|
public DateTime Modified { get; set; }
|
||||||
public DateTime Created { get; set; }
|
public DateTime Created { get; set; }
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
namespace TIAM.Entities.Drivers;
|
||||||
|
|
||||||
|
public enum CarMotorType : byte
|
||||||
|
{
|
||||||
|
Gas = 5,
|
||||||
|
Diesel = 10,
|
||||||
|
Electric = 15,
|
||||||
|
}
|
||||||
|
|
@ -13,11 +13,19 @@ public class TiamServiceProvider : AcServiceProvider<User, UserToServiceProvider
|
||||||
{
|
{
|
||||||
public virtual List<Product> Products { get; } = new();
|
public virtual List<Product> Products { get; } = new();
|
||||||
|
|
||||||
public TiamServiceProvider(){}
|
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)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TiamServiceProvider(string name, Guid ownerId) : this(Guid.NewGuid(), name, ownerId)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public TiamServiceProvider(Guid id, string name, Guid ownerId) : this(id, name, ownerId, Guid.NewGuid())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public TiamServiceProvider(Guid id, string name, Guid ownerId, Guid affiliateId) : base(id, name, ownerId, affiliateId)
|
||||||
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -17,7 +17,10 @@ public class UserProductMapping : IEntityGuid, ITimeStampInfo
|
||||||
|
|
||||||
public virtual User User { get; set; }
|
public virtual User User { get; set; }
|
||||||
public virtual Product Product { get; set; }
|
public virtual Product Product { get; set; }
|
||||||
|
|
||||||
|
public int Permissions { get; set; } = 1;
|
||||||
|
public string? JsonDetails { get; set; }
|
||||||
|
|
||||||
public DateTime Created { get; set; }
|
public DateTime Created { get; set; }
|
||||||
public DateTime Modified { get; set; }
|
public DateTime Modified { get; set; }
|
||||||
|
|
||||||
|
|
@ -27,10 +30,18 @@ public class UserProductMapping : IEntityGuid, ITimeStampInfo
|
||||||
public UserProductMapping(Guid userId, Guid productId) : this(Guid.NewGuid(), userId, productId)
|
public UserProductMapping(Guid userId, Guid productId) : this(Guid.NewGuid(), userId, productId)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public UserProductMapping(Guid id, Guid userId, Guid productId)
|
public UserProductMapping(Guid id, Guid userId, Guid productId) : this(id, userId, productId, 1)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
public UserProductMapping(Guid id, Guid userId, Guid productId, int permissions) : this(id, userId, productId, permissions, null)
|
||||||
|
{ }
|
||||||
|
public UserProductMapping(Guid id, Guid userId, Guid productId, int permissions, string? jsonDetails) : this()
|
||||||
{
|
{
|
||||||
Id = id;
|
Id = id;
|
||||||
UserId = userId;
|
UserId = userId;
|
||||||
ProductId = productId;
|
ProductId = productId;
|
||||||
|
|
||||||
|
Permissions = permissions;
|
||||||
|
JsonDetails = jsonDetails;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -182,9 +182,9 @@
|
||||||
base.OnInitialized();
|
base.OnInitialized();
|
||||||
OrderData = new TiamServiceProvider[]
|
OrderData = new TiamServiceProvider[]
|
||||||
{
|
{
|
||||||
new TiamServiceProvider(Guid.NewGuid(), "BAT", Guid.NewGuid()),
|
new TiamServiceProvider(Guid.NewGuid(), "BAT", Guid.NewGuid(), Guid.NewGuid()),
|
||||||
new TiamServiceProvider(Guid.NewGuid(), "TIAM", Guid.NewGuid()),
|
new TiamServiceProvider(Guid.NewGuid(), "TIAM", Guid.NewGuid(), Guid.NewGuid()),
|
||||||
new TiamServiceProvider(Guid.NewGuid(), "TestHotel", Guid.NewGuid())
|
new TiamServiceProvider(Guid.NewGuid(), "TestHotel", Guid.NewGuid(), Guid.NewGuid())
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
public ServiceProviderAPIController(ILogger<ServiceProviderAPIController> logger, AdminDal adminDal)
|
public ServiceProviderAPIController(ILogger<ServiceProviderAPIController> logger, AdminDal adminDal)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
|
||||||
_adminDal = adminDal;
|
_adminDal = adminDal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,17 +39,17 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
[Route("CreateServiceProvider")]
|
[Route("CreateServiceProvider")]
|
||||||
[Tags("In-Progress", "ServiceProvider")]
|
[Tags("In-Progress", "ServiceProvider")]
|
||||||
[EndpointSummary("Create assigned user")]
|
[EndpointSummary("Create assigned user")]
|
||||||
public async Task<IActionResult> CreateServiceProvider([FromBody] ServiceProviderModel SerializedServiceProviderModel)
|
public async Task<IActionResult> CreateServiceProvider([FromBody] ServiceProviderModel serializedServiceProviderModel)
|
||||||
{
|
{
|
||||||
Console.WriteLine("CreateUser called");
|
Console.WriteLine("CreateUser called");
|
||||||
if (SerializedServiceProviderModel == null)
|
if (serializedServiceProviderModel == null)
|
||||||
{
|
{
|
||||||
return BadRequest("SerializedLoginModel is required");
|
return BadRequest("SerializedLoginModel is required");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//ServiceProviderModel? serviceProvider = JObject.Parse(SerializedServiceProviderModel.GetRawText()).ToObject<ServiceProviderModel>();
|
//ServiceProviderModel? serviceProvider = JObject.Parse(serializedServiceProviderModel.GetRawText()).ToObject<ServiceProviderModel>();
|
||||||
ServiceProviderModel? serviceProvider = SerializedServiceProviderModel;
|
var serviceProvider = serializedServiceProviderModel;
|
||||||
|
|
||||||
|
|
||||||
if (serviceProvider != null)
|
if (serviceProvider != null)
|
||||||
|
|
@ -60,8 +59,8 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
//users[users.Length - 1] = new UserModel(user.Email, user.PhoneNumber, user.Password);
|
//users[users.Length - 1] = new UserModel(user.Email, user.PhoneNumber, user.Password);
|
||||||
|
|
||||||
var id = Guid.NewGuid();
|
var id = Guid.NewGuid();
|
||||||
string? name = SerializedServiceProviderModel?.Name;
|
var name = serializedServiceProviderModel.Name;
|
||||||
Guid ownerId = SerializedServiceProviderModel?.OwnerId ?? Guid.Empty;
|
var ownerId = serializedServiceProviderModel.OwnerId;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -74,17 +73,14 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
|
|
||||||
Console.WriteLine($"ServiceProvider to be created: {id}, {name}, {ownerId}");
|
Console.WriteLine($"ServiceProvider to be created: {id}, {name}, {ownerId}");
|
||||||
|
|
||||||
await _adminDal.CreateServiceProviderAsync(new TiamServiceProvider(id, name, ownerId));
|
await _adminDal.CreateServiceProviderAsync(new TiamServiceProvider(id, name, ownerId, Guid.NewGuid()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Ok("yes");
|
return Ok("yes");
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//16.
|
//16.
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
|
@ -96,7 +92,6 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
return _adminDal.GetServiceProvidersAsync();
|
return _adminDal.GetServiceProvidersAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//18.
|
//18.
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
|
|
@ -143,13 +138,11 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
Console.WriteLine($"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}");
|
Console.WriteLine($"CreateUserProductMappings called with ownerId: {createUserProductMappingModel.ContextId}, {createUserProductMappingModel.ContextId}");
|
||||||
|
|
||||||
UserProductMapping userProductMapping = new UserProductMapping(createUserProductMappingModel.ContextId, createUserProductMappingModel.ContextId);
|
var userProductMapping = new UserProductMapping(createUserProductMappingModel.ContextId, createUserProductMappingModel.ContextId);
|
||||||
|
|
||||||
var result = await _adminDal.CreateUserProductMappingAsync(userProductMapping);
|
var result = await _adminDal.AddUserProductMappingAsync(userProductMapping);
|
||||||
|
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -161,7 +154,7 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
Console.WriteLine($"GetUserProductMappingsForServiceProvider called with serviceProviderId: {serviceProviderId}");
|
Console.WriteLine($"GetUserProductMappingsForServiceProvider called with serviceProviderId: {serviceProviderId}");
|
||||||
|
|
||||||
Dictionary<Guid, string> userProductMappingDictionary = new Dictionary<Guid, string>();
|
var userProductMappingDictionary = new Dictionary<Guid, string>();
|
||||||
|
|
||||||
var serviceProviders = await _adminDal.GetServiceProvidersAsync();
|
var serviceProviders = await _adminDal.GetServiceProvidersAsync();
|
||||||
|
|
||||||
|
|
@ -203,23 +196,21 @@ namespace TIAMWebApp.Server.Controllers
|
||||||
{
|
{
|
||||||
//var result = _serviceProviderDal.GetQRCodeAsync(productId);
|
//var result = _serviceProviderDal.GetQRCodeAsync(productId);
|
||||||
|
|
||||||
QRCodeGenerator qrGenerator = new QRCodeGenerator();
|
var qrGenerator = new QRCodeGenerator();
|
||||||
QRCodeData qrCodeData = qrGenerator.CreateQrCode($"https://touriam.com/{productId}", QRCodeGenerator.ECCLevel.Q);
|
var qrCodeData = qrGenerator.CreateQrCode($"https://touriam.com/{productId}", QRCodeGenerator.ECCLevel.Q);
|
||||||
QRCode qrCode = new QRCode(qrCodeData);
|
var qrCode = new QRCode(qrCodeData);
|
||||||
//Bitmap qrCodeImage = qrCode.GetGraphic(20);
|
//Bitmap qrCodeImage = qrCode.GetGraphic(20);
|
||||||
string rootpath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "assets");
|
var rootpath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "assets");
|
||||||
Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.DarkMagenta, Color.White, (Bitmap)Bitmap.FromFile(rootpath + "/myimage.png"));
|
var qrCodeImage = qrCode.GetGraphic(20, Color.DarkMagenta, Color.White, (Bitmap)Bitmap.FromFile(rootpath + "/myimage.png"));
|
||||||
Console.WriteLine($"qrCodeLogo: {rootpath}/myimage.png");
|
Console.WriteLine($"qrCodeLogo: {rootpath}/myimage.png");
|
||||||
MemoryStream ms = new MemoryStream();
|
var ms = new MemoryStream();
|
||||||
qrCodeImage.Save(ms, ImageFormat.Jpeg);
|
qrCodeImage.Save(ms, ImageFormat.Jpeg);
|
||||||
byte[] byteImage = ms.ToArray();
|
var byteImage = ms.ToArray();
|
||||||
|
|
||||||
var SigBase64 = Convert.ToBase64String(byteImage); // Get Base64
|
var sigBase64 = Convert.ToBase64String(byteImage); // Get Base64
|
||||||
|
|
||||||
return Ok(SigBase64);
|
return Ok(sigBase64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue