This commit is contained in:
Loretta 2024-06-24 15:19:53 +02:00
parent 1f34a556eb
commit 28c673b613
5 changed files with 36 additions and 30 deletions

View File

@ -36,6 +36,7 @@ namespace TIAM.Database.DataLayers.Admins
public Task<List<Car>> 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<Car> GetCarByUserProductMappingId(Guid userProductMappingId) => Session(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList());
public Task<List<Car>> GetCarByUserProductMappingIdAsync(Guid userProductMappingId) => SessionAsync(ctx => ctx.Cars.Where(x => x.UserProductMappingId == userProductMappingId).ToList());
public Task<bool> AddCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Add(car).State == EntityState.Added);
public Task<bool> UpdateCarAsync(Car car) => TransactionAsync(ctx => ctx.Cars.Update(car).State == EntityState.Modified);
public Task<bool> 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<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
public List<UserProductMapping> GetUserProductMappingByUserId(Guid userId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingsByUserId(userId, autoInclude).ToList());
public List<UserProductMapping> GetUserProductMappingsByUserId(Guid userId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingsByUserId(userId, autoInclude).ToList());
public Task<List<UserProductMapping>> GetUserProductMappingsByUserIdAsync(Guid userId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingsByUserId(userId, autoInclude).ToList());
public Task<List<UserProductMapping>> GetUserProductMappingsByProductIdAsync(Guid productId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingsByProductId(productId, autoInclude).ToList());
public List<UserProductMapping> GetAllUserProductMappings(bool autoInclude = true) => Session(ctx => ctx.UserProductMappings).ToList();
public Task<List<UserProductMapping>> GetAllUserProductMappingsAsync(bool autoInclude = true) => SessionAsync(ctx => ctx.UserProductMappings.ToList());
public List<PermissionContextMapping> 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<List<UserProductMapping>> 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)
{

View File

@ -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;

View File

@ -49,7 +49,7 @@
<DxTabs>
<DxTabPage Text="Driving permissions assigned">
<UserProductMappingGridComponent GetAllTag="SignalRTags.GetUserProductMappingById" ContextIds="new[] { ((Car)context.DataItem).UserProductMappingId }" KeyboardNavigationEnabled="true"/>
<UserProductMappingGridComponent GetAllTag="SignalRTags.GetUserProductMappingsById" ContextIds="new[] { ((Car)context.DataItem).UserProductMappingId }" KeyboardNavigationEnabled="true"/>
</DxTabPage>
</DxTabs>

View File

@ -49,7 +49,7 @@
<DxTabs>
<DxTabPage Text="Driving permissions assigned">
<UserProductMappingGridComponent GetAllTag="SignalRTags.GetUserProductMappingById" ContextIds="new[] { ((Car)context.DataItem).UserProductMappingId }" KeyboardNavigationEnabled="true"/>
<UserProductMappingGridComponent GetAllTag="SignalRTags.GetUserProductMappingsById" ContextIds="new[] { ((Car)context.DataItem).UserProductMappingId }" KeyboardNavigationEnabled="true"/>
</DxTabPage>
</DxTabs>

View File

@ -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<string> 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<string> GetUserProductMappingsByProductId(Guid productId)
public async Task<List<UserProductMapping>> 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<string> GetUserProductMappingsByUserId(Guid userId)
public async Task<List<UserProductMapping>> 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<string> GetUserProductMappingById(Guid id)
public async Task<UserProductMapping?> 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<List<UserProductMapping>> 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<string> GetAllUserProductMappings()
public async Task<List<UserProductMapping>> 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<List<Car>> GetCarsForUserProductMapping(Guid userProductMappingId)
public async Task<List<Car>> 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]