Compare commits

...

2 Commits

Author SHA1 Message Date
Loretta 28c673b613 fixes 2024-06-24 15:19:53 +02:00
Loretta 1f34a556eb fixes 2024-06-24 14:11:53 +02:00
5 changed files with 42 additions and 62 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);
@ -130,8 +131,13 @@ namespace TIAM.Database.DataLayers.Admins
public Task<bool> RemoveProductAsync(Guid productId) => TransactionAsync(ctx => ctx.RemoveProduct(productId));
public UserProductMapping? GetUserProductMappingById(Guid userProductMappingId, bool autoInclude = true) => Session(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
public List<UserProductMapping>? GetAllUserProductMappings(bool autoInclude = true) => Session(ctx => ctx.UserProductMappings).ToList();
public Task<UserProductMapping?> GetUserProductMappingByIdAsync(Guid userProductMappingId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetUserProductMappingById(userProductMappingId, autoInclude));
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)
=> Session(x => x.GetPermissionContextsView(subjectId, contextId).ToList());
@ -506,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,64 +224,57 @@ 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 async Task<string> GetUserProductMappingsByUserId(Guid userId)
public async Task<List<UserProductMapping>> 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 (await adminDal.GetUserProductMappingsByUserIdAsync(userId)).OrderBy(x => x.ProductId).ToList();
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetUserProductMappingByIdRouteName)]
[SignalR(SignalRTags.GetUserProductMappingById)]
public async 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}");
var userProductMappings = adminDal.GetAllUserProductMappings();
var userproductMapping = await adminDal.GetUserProductMappingByIdAsync(id);
return userproductMapping;
}
var myUserProductMappings = userProductMappings.Where(x => x.Id == id).ToList();
//put serviceprovider id and name into a dictionary
[NonAction]
[ApiExplorerSettings(IgnoreApi = true)]
[SignalR(SignalRTags.GetUserProductMappingsById)]
public async Task<List<UserProductMapping>> GetUserProductMappingsById(Guid id)
{
_logger.Info($@"GetUserProductMappingsById called with userId: {id}");
return myUserProductMappings.ToJson();
var userproductMapping = await adminDal.GetUserProductMappingByIdAsync(id);
return userproductMapping == null ? [] : [userproductMapping];
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetAllUserProductMappingsRouteName)]
[SignalR(SignalRTags.GetAllUserProductMappings)]
public async Task<string> GetAllUserProductMappings()
public async Task<List<UserProductMapping>> GetAllUserProductMappings()
{
_logger.Info($@"GetAllUserProductMappings called");
var serviceProviders = adminDal.GetAllUserProductMappings()!.OrderBy(x => x.ProductId);
//put serviceprovider id and name into a dictionary
return serviceProviders.ToJson();
var companyies = (await adminDal.GetAllUserProductMappingsAsync()).OrderBy(x => x.ProductId).ToList();
return companyies;
}
[AllowAnonymous]
@ -291,8 +285,7 @@ namespace TIAMWebApp.Server.Controllers
{
_logger.Info($@"GetCarsForUserProductMapping called with userProductMappingId: {userProductMappingId}");
var cars = adminDal.GetCarByUserProductMappingId(userProductMappingId);
var cars = await adminDal.GetCarByUserProductMappingIdAsync(userProductMappingId);
return cars;
}
@ -305,7 +298,6 @@ namespace TIAMWebApp.Server.Controllers
_logger.Info($@"GetAllCars called ");
var cars = await adminDal.GetAllCarsAsync();
return cars;
}
@ -347,12 +339,10 @@ namespace TIAMWebApp.Server.Controllers
[Tags("Finished", "Cars")]
[EndpointSummary("Create car")]
[SignalR(SignalRTags.CreateCar)]
public async Task<Car> CreateCar(Car car)
public async Task<Car?> CreateCar(Car car)
{
var result = await CarDataChanging(car, TrackingState.Add);
if (result)
return car;
else return null;
return result ? car : null;
}
[AllowAnonymous]
@ -361,12 +351,10 @@ namespace TIAMWebApp.Server.Controllers
[Tags("Finished", "Cars")]
[EndpointSummary("Update car")]
[SignalR(SignalRTags.UpdateCar)]
public async Task<Car> UpdateCar(Car car)
public async Task<Car?> UpdateCar(Car car)
{
var result = await CarDataChanging(car, TrackingState.Update);
if (result)
return car;
else return null;
return result ? car : null;
}
@ -384,8 +372,7 @@ namespace TIAMWebApp.Server.Controllers
[Tags("In-Progress", "Product")]
[SignalR(SignalRTags.AddProduct)]
public async Task<IActionResult> AddProduct([FromBody] Product product)
{
{
_logger.Info(@"AddProduct called");
if (product == null)
@ -394,7 +381,7 @@ namespace TIAMWebApp.Server.Controllers
}
else
{
var result = adminDal.AddProductAsync(product);
var result = await adminDal.AddProductAsync(product);
return Ok(product);
}
}
@ -466,19 +453,12 @@ namespace TIAMWebApp.Server.Controllers
[HttpGet]
[Route(APIUrls.GetAllProductsRouteName)]
[Tags("In-Progress", "Product")]
public async Task<string> GetAllProducts()
public Task<string> GetAllProducts()
{
_logger.Info("GetAllProducts called");
var products = adminDal.GetProductsJson();
if (products != null)
{
return products;
}
else
{
return null;
}
return Task.FromResult(products);
}
[AllowAnonymous]