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 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 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 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> 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> 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); 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 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 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 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) public List<PermissionContextMapping> GetPermissionContextsView(Guid subjectId, Guid contextId)
@ -508,13 +512,6 @@ namespace TIAM.Database.DataLayers.Admins
#region UserProductMappings #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 //24 . (IServiceProviderDataService) Remove Assigned Users By Product Id
public Task RemoveUserProductMappingsByContextId(Guid productId) public Task RemoveUserProductMappingsByContextId(Guid productId)
{ {

View File

@ -54,6 +54,7 @@ public class SignalRTags : AcSignalRTags
public const int GetUserProductMappingsByProductId = 44; public const int GetUserProductMappingsByProductId = 44;
public const int GetUserProductMappingsByUserId = 45; public const int GetUserProductMappingsByUserId = 45;
public const int GetUserProductMappingById = 46; public const int GetUserProductMappingById = 46;
public const int GetUserProductMappingsById = 47;
public const int GetCarsForUserProductMapping = 50; public const int GetCarsForUserProductMapping = 50;
public const int CreateCar = 51; public const int CreateCar = 51;

View File

@ -49,7 +49,7 @@
<DxTabs> <DxTabs>
<DxTabPage Text="Driving permissions assigned"> <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> </DxTabPage>
</DxTabs> </DxTabs>

View File

@ -49,7 +49,7 @@
<DxTabs> <DxTabs>
<DxTabPage Text="Driving permissions assigned"> <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> </DxTabPage>
</DxTabs> </DxTabs>

View File

@ -18,6 +18,7 @@ using AyCode.Services.SignalRs;
using AyCode.Utils.Extensions; using AyCode.Utils.Extensions;
using TIAM.Entities.Drivers; using TIAM.Entities.Drivers;
using TIAM.Services; using TIAM.Services;
using TIAM.Entities.Products;
namespace TIAMWebApp.Server.Controllers namespace TIAMWebApp.Server.Controllers
{ {
@ -211,7 +212,7 @@ namespace TIAMWebApp.Server.Controllers
[SignalR(SignalRTags.DeleteUserProductMapping)] [SignalR(SignalRTags.DeleteUserProductMapping)]
public async Task<string> DeleteUserProductMapping(UserProductMapping userProductMapping) 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); var result = await adminDal.RemoveUserProductMappingAsync(userProductMapping.Id);
@ -223,62 +224,69 @@ namespace TIAMWebApp.Server.Controllers
[HttpPost] [HttpPost]
[Route(APIUrls.GetUserProductMappingsByProductIdRouteName)] [Route(APIUrls.GetUserProductMappingsByProductIdRouteName)]
[SignalR(SignalRTags.GetUserProductMappingsByProductId)] [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(); return await adminDal.GetUserProductMappingsByProductIdAsync(productId);
var myUserProductMappings = userProductMappings.Where(x => x.ProductId == productId).ToList();
//put serviceprovider id and name into a dictionary
return myUserProductMappings.ToJson();
} }
[AllowAnonymous] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.GetUserProductMappingsByUserIdRouteName)] [Route(APIUrls.GetUserProductMappingsByUserIdRouteName)]
[SignalR(SignalRTags.GetUserProductMappingsByUserId)] [SignalR(SignalRTags.GetUserProductMappingsByUserId)]
public Task<string> GetUserProductMappingsByUserId(Guid userId) public async Task<List<UserProductMapping>> GetUserProductMappingsByUserId(Guid userId)
{ {
_logger.Info($@"GetUserProductMappingsByUserId called with userId: {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] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.GetUserProductMappingByIdRouteName)] [Route(APIUrls.GetUserProductMappingByIdRouteName)]
[SignalR(SignalRTags.GetUserProductMappingById)] [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] [AllowAnonymous]
[HttpPost] [HttpPost]
[Route(APIUrls.GetAllUserProductMappingsRouteName)] [Route(APIUrls.GetAllUserProductMappingsRouteName)]
[SignalR(SignalRTags.GetAllUserProductMappings)] [SignalR(SignalRTags.GetAllUserProductMappings)]
public Task<string> GetAllUserProductMappings() public async Task<List<UserProductMapping>> GetAllUserProductMappings()
{ {
_logger.Info($@"GetAllUserProductMappings called"); _logger.Info($@"GetAllUserProductMappings called");
var serviceProviders = adminDal.GetAllUserProductMappings()!.OrderBy(x => x.ProductId); var companyies = (await adminDal.GetAllUserProductMappingsAsync()).OrderBy(x => x.ProductId).ToList();
return Task.FromResult(serviceProviders.ToJson()); return companyies;
} }
[AllowAnonymous] [AllowAnonymous]
[HttpGet] [HttpGet]
[Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")] [Route(APIUrls.GetCarsForUserProductMappingRouteName + "/{userProductMappingId}")]
[SignalR(SignalRTags.GetCarsForUserProductMapping)] [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}"); _logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}");
var cars = adminDal.GetCarByUserProductMappingId(userProductMappingId); var cars = await adminDal.GetCarByUserProductMappingIdAsync(userProductMappingId);
return Task.FromResult(cars); return cars;
} }
[AllowAnonymous] [AllowAnonymous]