diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index 5cb6e3c7..18642bce 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -36,6 +36,7 @@ namespace TIAM.Database.DataLayers.Admins public Task> GetAllCarsAsync() => SessionAsync(ctx => ctx.Cars.OrderBy(x => x.Manufacture).ThenBy(x => x.CarModel).ToList()); public Car? GetCarById(Guid carId) => Session(ctx => ctx.Cars.FirstOrDefault(x => x.Id == carId)); public List GetCarByUserProductMappingId(Guid userProductMappingId) => Session(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList()); + public Task> GetCarByUserProductMappingIdAsync(Guid userProductMappingId) => SessionAsync(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList()); public Task AddCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Add(car).State == EntityState.Added); public Task UpdateCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Update(car).State == EntityState.Modified); public Task RemoveCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Remove(car).State == EntityState.Deleted); @@ -131,8 +132,11 @@ namespace TIAM.Database.DataLayers.Admins public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude)); public Task GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude)); - public List GetUserProductMappingByUserId(Guid userId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingsByUserId(userId, autoInclude).ToList()); + public List GetUserProductMappingsByUserId(Guid userId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingsByUserId(userId, autoInclude).ToList()); + public Task> GetUserProductMappingsByUserIdAsync(Guid userId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingsByUserId(userId, autoInclude).ToList()); + public Task> GetUserProductMappingsByProductIdAsync(Guid productId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingsByProductId(productId, autoInclude).ToList()); public List GetAllUserProductMappings(bool autoInclude = true) => Session(ctx => ctx.UserProductMappings).ToList(); + public Task> GetAllUserProductMappingsAsync(bool autoInclude = true) => SessionAsync(ctx => ctx.UserProductMappings.ToList()); public List GetPermissionContextsView(Guid subjectId, Guid contextId) @@ -508,13 +512,6 @@ namespace TIAM.Database.DataLayers.Admins #region UserProductMappings - //23. (IServiceProviderDataService) Get Assigned Users By ProductId - public Task> GetUserProductMappingsByProductIdAsync(Guid productId) - { - return Context.UserProductMappings.Where(x => x.ProductId == productId).ToListAsync(); - } - - //24 . (IServiceProviderDataService) Remove Assigned Users By Product Id public Task RemoveUserProductMappingsByContextId(Guid productId) { diff --git a/TIAM.Services/SignalRTags.cs b/TIAM.Services/SignalRTags.cs index fe95c0bd..36999c6f 100644 --- a/TIAM.Services/SignalRTags.cs +++ b/TIAM.Services/SignalRTags.cs @@ -54,6 +54,7 @@ public class SignalRTags : AcSignalRTags public const int GetUserProductMappingsByProductId = 44; public const int GetUserProductMappingsByUserId = 45; public const int GetUserProductMappingById = 46; + public const int GetUserProductMappingsById = 47; public const int GetCarsForUserProductMapping = 50; public const int CreateCar = 51; diff --git a/TIAMSharedUI/Pages/User/SysAdmins/CarDetailGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/CarDetailGridComponent.razor index 59c3442d..9ce4530c 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/CarDetailGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/CarDetailGridComponent.razor @@ -49,7 +49,7 @@ - + diff --git a/TIAMSharedUI/Pages/User/SysAdmins/CarGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/CarGridComponent.razor index c944fca3..9daabbec 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/CarGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/CarGridComponent.razor @@ -49,7 +49,7 @@ - + diff --git a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs index 0ef33cf9..c61738af 100644 --- a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs +++ b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs @@ -18,6 +18,7 @@ using AyCode.Services.SignalRs; using AyCode.Utils.Extensions; using TIAM.Entities.Drivers; using TIAM.Services; +using TIAM.Entities.Products; namespace TIAMWebApp.Server.Controllers { @@ -211,7 +212,7 @@ namespace TIAMWebApp.Server.Controllers [SignalR(SignalRTags.DeleteUserProductMapping)] public async Task DeleteUserProductMapping(UserProductMapping userProductMapping) { - _logger.Info($"UpdateUserProductMapping called! + {userProductMapping.Id}"); + _logger.Info($"DeleteUserProductMapping called! + {userProductMapping.Id}"); var result = await adminDal.RemoveUserProductMappingAsync(userProductMapping.Id); @@ -223,62 +224,69 @@ namespace TIAMWebApp.Server.Controllers [HttpPost] [Route(APIUrls.GetUserProductMappingsByProductIdRouteName)] [SignalR(SignalRTags.GetUserProductMappingsByProductId)] - public async Task GetUserProductMappingsByProductId(Guid productId) + public async Task> GetUserProductMappingsByProductId(Guid productId) { - _logger.Info($@"GetUserProductMappingsByUserId called with serviceProviderId: {productId}"); + _logger.Info($@"GetUserProductMappingsByProductId called with serviceProviderId: {productId}"); - var userProductMappings = adminDal.GetAllUserProductMappings(); - - var myUserProductMappings = userProductMappings.Where(x => x.ProductId == productId).ToList(); - //put serviceprovider id and name into a dictionary - - return myUserProductMappings.ToJson(); + return await adminDal.GetUserProductMappingsByProductIdAsync(productId); } [AllowAnonymous] [HttpPost] [Route(APIUrls.GetUserProductMappingsByUserIdRouteName)] [SignalR(SignalRTags.GetUserProductMappingsByUserId)] - public Task GetUserProductMappingsByUserId(Guid userId) + public async Task> GetUserProductMappingsByUserId(Guid userId) { _logger.Info($@"GetUserProductMappingsByUserId called with userId: {userId}"); - return Task.FromResult(adminDal.GetUserProductMappingByUserId(userId).OrderBy(x => x.ProductId).ToJson()); + return (await adminDal.GetUserProductMappingsByUserIdAsync(userId)).OrderBy(x => x.ProductId).ToList(); } [AllowAnonymous] [HttpPost] [Route(APIUrls.GetUserProductMappingByIdRouteName)] [SignalR(SignalRTags.GetUserProductMappingById)] - public Task GetUserProductMappingById(Guid id) + public async Task GetUserProductMappingById(Guid id) { - _logger.Info($@"GetUserProductMappingsByUserId called with userId: {id}"); + _logger.Info($@"GetUserProductMappingById called with userId: {id}"); - return Task.FromResult(adminDal.GetUserProductMappingById(id).ToJson()); + var userproductMapping = await adminDal.GetUserProductMappingByIdAsync(id); + return userproductMapping; + } + + [NonAction] + [ApiExplorerSettings(IgnoreApi = true)] + [SignalR(SignalRTags.GetUserProductMappingsById)] + public async Task> GetUserProductMappingsById(Guid id) + { + _logger.Info($@"GetUserProductMappingsById called with userId: {id}"); + + var userproductMapping = await adminDal.GetUserProductMappingByIdAsync(id); + return userproductMapping == null ? [] : [userproductMapping]; } [AllowAnonymous] [HttpPost] [Route(APIUrls.GetAllUserProductMappingsRouteName)] [SignalR(SignalRTags.GetAllUserProductMappings)] - public Task GetAllUserProductMappings() + public async Task> GetAllUserProductMappings() { _logger.Info($@"GetAllUserProductMappings called"); - var serviceProviders = adminDal.GetAllUserProductMappings()!.OrderBy(x => x.ProductId); - return Task.FromResult(serviceProviders.ToJson()); + var companyies = (await adminDal.GetAllUserProductMappingsAsync()).OrderBy(x => x.ProductId).ToList(); + return companyies; } [AllowAnonymous] [HttpGet] [Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")] [SignalR(SignalRTags.GetCarsForUserProductMapping)] - public Task> GetCarsForUserProductMapping(Guid userProductMappingId) + public async Task> GetCarsForUserProductMapping(Guid userProductMappingId) { _logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}"); - var cars = adminDal.GetCarByUserProductMappingId(userProductMappingId); - return Task.FromResult(cars); + var cars = await adminDal.GetCarByUserProductMappingIdAsync(userProductMappingId); + return cars; } [AllowAnonymous]