diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index 7d5a7cc2..fcd1bc8e 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -138,6 +138,7 @@ namespace TIAM.Database.DataLayers.Admins #region TransferToDriver public Task GetTransferToDriverByIdAsync(Guid transferToDriverId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriverById(transferToDriverId, autoInclude)); + public Task> GetTransferToDriversByUpmId(Guid upmId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriversByUpmId(upmId, autoInclude).ToList()); public Task> GetTransferToDriversByTransferIdAsync(Guid transferId, bool autoInclude = true) => SessionAsync(ctx => ctx.GetTransferToDriversByTransferId(transferId, autoInclude).ToList()); public Task AddTransferToDriverAsync(TransferToDriver transferToDriver) => TransactionAsync(ctx => ctx.AddTransferToDriver(transferToDriver)); @@ -251,8 +252,7 @@ namespace TIAM.Database.DataLayers.Admins #region UserProductMapping - public Task AddUserProductMappingAsync(UserProductMapping userProductMapping) - => TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping)); + public Task AddUserProductMappingAsync(UserProductMapping userProductMapping) => TransactionAsync(ctx => ctx.AddUserProductMapping(userProductMapping)); public async Task AddUserProductMappingAsync(Guid userProductMappingId, Guid userId, Guid productId, int permissions = 1, UserProductJsonDetailModel? userProductToCars = null) { @@ -643,7 +643,7 @@ namespace TIAM.Database.DataLayers.Admins #region UserProductMappings //24 . (IServiceProviderDataService) Remove Assigned Users By Product Id - public Task RemoveUserProductMappingsByContextId(Guid productId) + public Task RemoveUserProductMappingsByProductId(Guid productId) { using (var transaction = Context.Database.BeginTransaction()) { diff --git a/TIAM.Database/DbContexts/ServiceProviders/ServiceProviderDbContext.cs b/TIAM.Database/DbContexts/ServiceProviders/ServiceProviderDbContext.cs index 3d405982..84d51896 100644 --- a/TIAM.Database/DbContexts/ServiceProviders/ServiceProviderDbContext.cs +++ b/TIAM.Database/DbContexts/ServiceProviders/ServiceProviderDbContext.cs @@ -65,5 +65,7 @@ namespace TIAM.Database.DbContexts.ServiceProviders //modelBuilder.Entity().HasOne(e => e.TransferDestination); //modelBuilder.Entity().Navigation(e => e.TransferDestination).AutoInclude(true); } + + public DbSet TransferToDrivers { get; set; } } } diff --git a/TIAM.Database/DbSets/Transfers/TransferToDriverDbSetExtensions.cs b/TIAM.Database/DbSets/Transfers/TransferToDriverDbSetExtensions.cs index c7496111..b924a75c 100644 --- a/TIAM.Database/DbSets/Transfers/TransferToDriverDbSetExtensions.cs +++ b/TIAM.Database/DbSets/Transfers/TransferToDriverDbSetExtensions.cs @@ -16,6 +16,9 @@ public static class TransferToDriverDbSetExtensions public static IQueryable GetTransferToDriversByTransferId(this ITransferToDriverDbSet ctx, Guid transferId, bool autoInclude = true) => ctx.TransferToDrivers.Where(x => x.TransferId == transferId); + public static IQueryable GetTransferToDriversByUpmId(this ITransferToDriverDbSet ctx, Guid upmId, bool autoInclude = true) + => ctx.TransferToDrivers.Where(x => x.UserProductMappingId == upmId); + public static bool AddTransferToDriver(this ITransferDbSet ctx, TransferToDriver transferToDriver) { ctx.UpdateTransferStatus(transferToDriver.TransferId, TransferStatusType.AssignedToDriver); diff --git a/TIAM.Database/DbSets/Users/IUserProductMappingDbSet.cs b/TIAM.Database/DbSets/Users/IUserProductMappingDbSet.cs index d35a7ba1..96baa4ea 100644 --- a/TIAM.Database/DbSets/Users/IUserProductMappingDbSet.cs +++ b/TIAM.Database/DbSets/Users/IUserProductMappingDbSet.cs @@ -1,9 +1,10 @@ using Microsoft.EntityFrameworkCore; +using TIAM.Database.DbSets.Transfers; using TIAM.Entities.Users; namespace TIAM.Database.DbSets.Users; -public interface IUserProductMappingDbSet +public interface IUserProductMappingDbSet : ITransferToDriverDbSet { public DbSet UserProductMappings { get; set; } } \ No newline at end of file diff --git a/TIAM.Database/DbSets/Users/UserProductMappingDbSetExtensions.cs b/TIAM.Database/DbSets/Users/UserProductMappingDbSetExtensions.cs index e4b79ae3..1fb6f744 100644 --- a/TIAM.Database/DbSets/Users/UserProductMappingDbSetExtensions.cs +++ b/TIAM.Database/DbSets/Users/UserProductMappingDbSetExtensions.cs @@ -1,5 +1,6 @@ using AyCode.Core.Extensions; using Microsoft.EntityFrameworkCore; +using TIAM.Database.DbSets.Transfers; using TIAM.Entities.Drivers; using TIAM.Entities.Users; @@ -69,6 +70,9 @@ public static class UserProductMappingDbSetExtensions { if (userProductMapping == null) return false; + if (ctx.GetTransferToDriversByUpmId(userProductMapping.Id).Any()) + return false; + return ctx.UserProductMappings.Remove(userProductMapping).State == EntityState.Deleted; } diff --git a/TIAMSharedUI/Pages/User/SysAdmins/UserProductMappingGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/UserProductMappingGridComponent.razor index 467afa69..e2f7c1f8 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/UserProductMappingGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/UserProductMappingGridComponent.razor @@ -12,6 +12,7 @@ @using AyCode.Core.Loggers @using AyCode.Services.Loggers @using AyCode.Core +@using AyCode.Core.Enums @using AyCode.Core.Helpers @using AyCode.Models.Users @using AyCode.Services.SignalRs @@ -31,7 +32,8 @@ EditMode="GridEditMode.EditRow" ColumnResizeMode="GridColumnResizeMode.NextColumn" OnGridEditModelSaving="OnGridEditModelSaving" - DetailExpandButtonDisplayMode="DetailExpandButtonDisplayMode"> + DetailExpandButtonDisplayMode="DetailExpandButtonDisplayMode" + OnGridItemChanged="OnGridItemChanged"> @@ -79,25 +81,6 @@ } - - @* - @{ - var userProduct = (UserProductMapping)userEditFormContext.EditModel; - } - - - @userEditFormContext.GetEditor("UserId") - - - - - - @userEditFormContext.GetEditor("Permissions") - - - - - *@ @code { @@ -172,7 +155,15 @@ private void OnGridEditModelSaving(GridEditModelSavingEventArgs e) { - _isNewState = false; + _isNewState = e.IsNew; + } + + private void OnGridItemChanged(GridDataItemChangedEventArgs args) + { + // if (args.TrackingState != TrackingState.Add) return; + + // args.CancelStateChangeInvoke = true; + // StateHasChanged(); } } \ No newline at end of file diff --git a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs index 0a07cbda..a8a1a548 100644 --- a/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs +++ b/TIAMWebApp/Server/Controllers/ServiceProviderAPIController.cs @@ -177,20 +177,20 @@ namespace TIAMWebApp.Server.Controllers [Tags("Finished", "ServiceProvider")] [EndpointSummary("Create assigned user to product")] [SignalR(SignalRTags.CreateUserProductMapping)] - public async Task CreateUserProductMapping(UserProductMapping userProductMapping) + public async Task CreateUserProductMapping(UserProductMapping userProductMapping) { - if (userProductMapping.ProductId == Guid.Empty || userProductMapping.UserId == Guid.Empty) - { - return BadRequest("Invalid request"); - } - else - { - _logger.Info($@"CreateUserProductMappings called with ownerId: {userProductMapping.ProductId}, {userProductMapping.UserId}"); + _logger.Info($@"CreateUserProductMappings called with ownerId: {userProductMapping.ProductId}, {userProductMapping.UserId}"); - var result = await adminDal.AddUserProductMappingAsync(userProductMapping); - - return Ok(result); + if (userProductMapping.ProductId.IsNullOrEmpty() || userProductMapping.UserId.IsNullOrEmpty()) + { + _logger.Error(@"CreateUserProductMappings; (userProductMapping.ProductId.IsNullOrEmpty() || userProductMapping.UserId.IsNullOrEmpty())"); + return null;//BadRequest("Invalid request"); } + + var result = await adminDal.AddUserProductMappingAsync(userProductMapping); + + //TODO: A userProductMapping-nem include-olja be a User-t és a Product-ot automatikusan, ezért kell újra lekérni! TransactionAsync T-t adjon vissza, ne csak bool-t... - J. + return result ? adminDal.GetUserProductMappingById(userProductMapping.Id) : null; //Ok(result); } [AllowAnonymous] @@ -203,7 +203,8 @@ namespace TIAMWebApp.Server.Controllers var result = await adminDal.UpdateUserProductMappingAsync(userProductMapping); - return result == null ? string.Empty : userProductMapping.ToJson(); + //TODO: A userProductMapping-nem include-olja be a User-t és a Product-ot automatikusan, ezért kell újra lekérni! TransactionAsync T-t adjon vissza, ne csak bool-t... - J. + return result == null ? string.Empty : adminDal.GetUserProductMappingById(userProductMapping.Id).ToJson(); } [AllowAnonymous]