diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index a7f74c2b..5cb6e3c7 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -130,8 +130,10 @@ namespace TIAM.Database.DataLayers.Admins public Task RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId)); public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude)); - public List? GetAllUserProductMappings(bool autoInclude = true) => Session(ctx => ctx.UserProductMappings).ToList(); 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 GetAllUserProductMappings(bool autoInclude = true) => Session(ctx => ctx.UserProductMappings).ToList(); + public List GetPermissionContextsView(Guid subjectId, Guid contextId) => Session(x => x.GetPermissionContextsView(subjectId, contextId).ToList()); diff --git a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs index b11a5e40..0ef33cf9 100644 --- a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs +++ b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs @@ -239,61 +239,46 @@ namespace TIAMWebApp.Server.Controllers [HttpPost] [Route(APIUrls.GetUserProductMappingsByUserIdRouteName)] [SignalR(SignalRTags.GetUserProductMappingsByUserId)] - public async Task GetUserProductMappingsByUserId(Guid userId) + public Task GetUserProductMappingsByUserId(Guid userId) { _logger.Info($@"GetUserProductMappingsByUserId called with userId: {userId}"); - var userProductMappings = adminDal.GetAllUserProductMappings(); - - var myUserProductMappings = userProductMappings.Where(x => x.UserId == userId).OrderBy(x => x.ProductId).ToList(); - //put serviceprovider id and name into a dictionary - - return myUserProductMappings.ToJson(); + return Task.FromResult(adminDal.GetUserProductMappingByUserId(userId).OrderBy(x => x.ProductId).ToJson()); } [AllowAnonymous] [HttpPost] [Route(APIUrls.GetUserProductMappingByIdRouteName)] [SignalR(SignalRTags.GetUserProductMappingById)] - public async Task GetUserProductMappingById(Guid id) + public Task GetUserProductMappingById(Guid id) { _logger.Info($@"GetUserProductMappingsByUserId called with userId: {id}"); - var userProductMappings = adminDal.GetAllUserProductMappings(); - - var myUserProductMappings = userProductMappings.Where(x => x.Id == id).ToList(); - //put serviceprovider id and name into a dictionary - - return myUserProductMappings.ToJson(); + return Task.FromResult(adminDal.GetUserProductMappingById(id).ToJson()); } [AllowAnonymous] [HttpPost] [Route(APIUrls.GetAllUserProductMappingsRouteName)] [SignalR(SignalRTags.GetAllUserProductMappings)] - public async Task GetAllUserProductMappings() + public Task GetAllUserProductMappings() { _logger.Info($@"GetAllUserProductMappings called"); - var serviceProviders = adminDal.GetAllUserProductMappings()!.OrderBy(x => x.ProductId); - - //put serviceprovider id and name into a dictionary - - return serviceProviders.ToJson(); + return Task.FromResult(serviceProviders.ToJson()); } [AllowAnonymous] [HttpGet] [Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")] [SignalR(SignalRTags.GetCarsForUserProductMapping)] - public async Task> GetCarsForUserProductMapping(Guid userProductMappingId) + public Task> GetCarsForUserProductMapping(Guid userProductMappingId) { _logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}"); var cars = adminDal.GetCarByUserProductMappingId(userProductMappingId); - - return cars; + return Task.FromResult(cars); } [AllowAnonymous] @@ -305,7 +290,6 @@ namespace TIAMWebApp.Server.Controllers _logger.Info($@"GetAllCars called "); var cars = await adminDal.GetAllCarsAsync(); - return cars; } @@ -347,12 +331,10 @@ namespace TIAMWebApp.Server.Controllers [Tags("Finished", "Cars")] [EndpointSummary("Create car")] [SignalR(SignalRTags.CreateCar)] - public async Task CreateCar(Car car) + public async Task CreateCar(Car car) { var result = await CarDataChanging(car, TrackingState.Add); - if (result) - return car; - else return null; + return result ? car : null; } [AllowAnonymous] @@ -361,12 +343,10 @@ namespace TIAMWebApp.Server.Controllers [Tags("Finished", "Cars")] [EndpointSummary("Update car")] [SignalR(SignalRTags.UpdateCar)] - public async Task UpdateCar(Car car) + public async Task UpdateCar(Car car) { var result = await CarDataChanging(car, TrackingState.Update); - if (result) - return car; - else return null; + return result ? car : null; } @@ -384,8 +364,7 @@ namespace TIAMWebApp.Server.Controllers [Tags("In-Progress", "Product")] [SignalR(SignalRTags.AddProduct)] public async Task AddProduct([FromBody] Product product) - { - + { _logger.Info(@"AddProduct called"); if (product == null) @@ -394,7 +373,7 @@ namespace TIAMWebApp.Server.Controllers } else { - var result = adminDal.AddProductAsync(product); + var result = await adminDal.AddProductAsync(product); return Ok(product); } } @@ -466,19 +445,12 @@ namespace TIAMWebApp.Server.Controllers [HttpGet] [Route(APIUrls.GetAllProductsRouteName)] [Tags("In-Progress", "Product")] - public async Task GetAllProducts() + public Task GetAllProducts() { _logger.Info("GetAllProducts called"); var products = adminDal.GetProductsJson(); - if (products != null) - { - return products; - } - else - { - return null; - } + return Task.FromResult(products); } [AllowAnonymous]