diff --git a/TIAM.Database.Test/AdminDalTest.cs b/TIAM.Database.Test/AdminDalTest.cs index 6a9a282d..adbf88e6 100644 --- a/TIAM.Database.Test/AdminDalTest.cs +++ b/TIAM.Database.Test/AdminDalTest.cs @@ -531,10 +531,10 @@ namespace TIAM.Database.Test [DataTestMethod] [DataRow(["069089cd-66d4-4f0d-851b-2eea14fa62a4", "be709d9b-87dc-4c94-bf9e-d6254db3fa3e"])] - public async Task TransferDestinationCrudTest(string[] transferDestIdaddressIdStrings) + public async Task TransferDestinationCrudTest(string[] transferDestIdAddressIdStrings) { - var transferDestId = Guid.Parse(transferDestIdaddressIdStrings[0]); - var addressId = Guid.Parse(transferDestIdaddressIdStrings[1]); + var transferDestId = Guid.Parse(transferDestIdAddressIdStrings[0]); + var addressId = Guid.Parse(transferDestIdAddressIdStrings[1]); await Dal.RemoveTransferDestinationAsync(transferDestId, true); //kitöröljük a szemetet, ha korábbról bentmaradt - J. diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index ff8190ba..d0bfd422 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -71,6 +71,7 @@ namespace TIAM.Database.DataLayers.Admins #region TransferDestination public TransferDestination? GetTransferDestinationById(Guid transferDestinationId) => Session(ctx=>ctx.GetTransferDestinationById(transferDestinationId)); + public Task GetTransferDestinationByIdAsync(Guid transferDestinationId) => SessionAsync(ctx=>ctx.GetTransferDestinationById(transferDestinationId)); public string? GetTransferDestinationJsonById(Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationById(transferDestinationId)?.ToJson()); public Task AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination)); @@ -97,7 +98,7 @@ namespace TIAM.Database.DataLayers.Admins public Task AddTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.AddTransferDestinationToProduct(transferDestinationToProduct)); public Task UpdateTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.UpdateTransferDestinationToProduct(transferDestinationToProduct)); - public Task RemoveTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.RemoveTransferDestinationToProduct(transferDestinationToProduct)); + public Task RemoveTransferDestinationToProductAsync(TransferDestinationToProduct transferDestinationToProduct) => TransactionAsync(ctx => ctx.RemoveTransferDestinationToProduct(transferDestinationToProduct.Id)); public Task RemoveTransferDestinationToProductAsync(Guid transferDestinationToProductId) => TransactionAsync(ctx => ctx.RemoveTransferDestinationToProduct(transferDestinationToProductId)); #endregion TransferDestinationToProduct diff --git a/TIAM.Database/DbSets/Products/IProductDbSet.cs b/TIAM.Database/DbSets/Products/IProductDbSet.cs index 3b7a7b03..94701b8b 100644 --- a/TIAM.Database/DbSets/Products/IProductDbSet.cs +++ b/TIAM.Database/DbSets/Products/IProductDbSet.cs @@ -1,12 +1,13 @@ using Microsoft.EntityFrameworkCore; using TIAM.Database.DbSets.Profiles; +using TIAM.Database.DbSets.Transfers; using TIAM.Database.DbSets.Users; using TIAM.Entities.Addresses; using TIAM.Entities.Products; namespace TIAM.Database.DbSets.Products; -public interface IProductDbSet : IProfileDbSet, IUserProductMappingDbSet +public interface IProductDbSet : IProfileDbSet, IUserProductMappingDbSet, ITransferDestinationDbSet { public DbSet Products { get; set; } } \ No newline at end of file diff --git a/TIAM.Database/DbSets/Products/ProductDbSetExtensions.cs b/TIAM.Database/DbSets/Products/ProductDbSetExtensions.cs index 3d8a74b8..e6d722a3 100644 --- a/TIAM.Database/DbSets/Products/ProductDbSetExtensions.cs +++ b/TIAM.Database/DbSets/Products/ProductDbSetExtensions.cs @@ -5,6 +5,7 @@ using AyCode.Interfaces.Entities; using AyCode.Interfaces.Profiles; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.ChangeTracking; +using TIAM.Database.DbSets.Transfers; using TIAM.Database.DbSets.Users; using TIAM.Entities.Addresses; using TIAM.Entities.Products; @@ -39,6 +40,7 @@ public static class ProductDbSetExtensions { ctx.RemoveProfile(product.ProfileId); ctx.RemoveUserProductMappingsByProductId(product.Id); + ctx.RemoveTransferDestinationToProductByProductId(product.Id); //TODO: Transfer, etc... - J. return ctx.Products.Remove(product).State == EntityState.Deleted; diff --git a/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs b/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs index 440a2667..408ce2fc 100644 --- a/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs +++ b/TIAM.Database/DbSets/Transfers/TransferDbSetExtensions.cs @@ -47,6 +47,7 @@ public static class TransferDbSetExtensions { if (removeAddress) ctx.Addresses.Remove(transferDestination.Address); + ctx.RemoveTransferDestinationToProductByTransferDestinationId(transferDestination.Id); return ctx.TransferDestinations.Remove(transferDestination).State == EntityState.Deleted; } @@ -70,7 +71,7 @@ public static class TransferDbSetExtensions public static bool UpdateTransferDestinationToProduct(this ITransferDestinationToProductDbSet ctx, TransferDestinationToProduct transferDestinationToProduct) => ctx.TransferDestinationToProducts.Update(transferDestinationToProduct).State == EntityState.Modified; - public static bool RemoveTransferDestinationToProduct(this ITransferDestinationToProductDbSet ctx, TransferDestinationToProduct transferDestinationToProduct) + private static bool RemoveTransferDestinationToProduct(this ITransferDestinationToProductDbSet ctx, TransferDestinationToProduct transferDestinationToProduct) { return ctx.TransferDestinationToProducts.Remove(transferDestinationToProduct).State == EntityState.Deleted; } @@ -80,5 +81,18 @@ public static class TransferDbSetExtensions var transferDestinationToProduct = ctx.GetTransferDestinationToProductById(transferDestinationToProductId); return transferDestinationToProduct == null || ctx.RemoveTransferDestinationToProduct(transferDestinationToProduct); } + + public static bool RemoveTransferDestinationToProductByProductId(this ITransferDestinationToProductDbSet ctx, Guid productId) + { + ctx.TransferDestinationToProducts.RemoveRange(ctx.TransferDestinationToProducts.Where(x => x.ProductId == productId)); + return true; + } + + public static bool RemoveTransferDestinationToProductByTransferDestinationId(this ITransferDestinationToProductDbSet ctx, Guid transferDestinationId) + { + ctx.TransferDestinationToProducts.RemoveRange(ctx.TransferDestinationToProducts.Where(x => x.TransferDestinationId == transferDestinationId)); + return true; + } + #endregion TransferDestinationToProduct } \ No newline at end of file diff --git a/TIAMSharedUI/Pages/User/SysAdmins/ManageTransferDestinationToProducts.razor b/TIAMSharedUI/Pages/User/SysAdmins/ManageTransferDestinationToProducts.razor index 3e6d63c3..66f0d67f 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/ManageTransferDestinationToProducts.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/ManageTransferDestinationToProducts.razor @@ -37,7 +37,7 @@ Click="ColumnChooserButton_Click" /> - + diff --git a/TIAMSharedUI/Pages/User/SysAdmins/ProductDetailGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/ProductDetailGridComponent.razor index e1517cbf..88543310 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/ProductDetailGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/ProductDetailGridComponent.razor @@ -17,13 +17,14 @@ @using TIAMWebApp.Shared.Application.Services @using AyCode.Interfaces.Addresses @using AyCode.Core +@using AyCode.Core.Extensions @inject IStringLocalizer Localizer @inject IEnumerable LogWriters @inject AdminSignalRClient AdminSignalRClient; OnGridEditModelSaving { get; set; } [Parameter] public int GetAllTag { get; set; } = SignalRTags.GetProductsByContextId; diff --git a/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductGridComponent.razor index cff12132..7f2dcf88 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductGridComponent.razor @@ -10,26 +10,25 @@ @using AyCode.Services.Loggers @using TIAM.Core.Loggers @using AyCode.Core +@using AyCode.Core.Extensions @using TIAMSharedUI.Shared.Components.Grids @inject IServiceProviderDataService ServiceProviderDataService @inject IEnumerable LogWriters @inject AdminSignalRClient AdminSignalRClient; + Logger="_logger" + SignalRClient="AdminSignalRClient" + ContextIds="@(ContextId.IsNullOrEmpty() ? throw new InvalidDataException($"ContextId.IsNullOrEmpty(); ContextId: {ContextId}") : [ContextId.Value])" + PageSize="10" + KeyboardNavigationEnabled="KeyboardNavigationEnabled" + KeyFieldName="Id" + ValidationEnabled="false" + EditMode="GridEditMode.EditForm" + ColumnResizeMode="GridColumnResizeMode.NextColumn"> - + @@ -38,37 +37,30 @@ - - - - - + @{ - var serviceProvider = (Company)EditFormContext.EditModel; + var transferDestinationToProduct = (TransferDestinationToProduct)editFormContext.EditModel; } - @EditFormContext.GetEditor("Price") + @editFormContext.GetEditor("Price") - @EditFormContext.GetEditor("Price2") + @editFormContext.GetEditor("Price2") - @EditFormContext.GetEditor("Price3") + @editFormContext.GetEditor("Price3") - @EditFormContext.GetEditor("ProductCommis") + @editFormContext.GetEditor("ProductCommis") - - - @@ -79,65 +71,12 @@ [Parameter] public Guid? ContextId { get; set; } - [Parameter] public int GetAllTag { get; set; } - - public Guid[]? ContextIds = new Guid[1]; - private LoggerClient _logger = null!; - protected override async Task OnInitializedAsync() + protected override void OnInitialized() { _logger = new LoggerClient(LogWriters.ToArray()); - // ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract - //_detailGridData = UserModelDtoDetail.ServiceProviders ?? []; - //_availableServices = await ServiceProviderDataService.GetServiceProvidersAsync(); - - //_logger.Info($"DetailGridData: {_detailGridData.Count}"); + base.OnInitialized(); } - - protected override void OnParametersSet() - { - ContextIds[0] = (Guid)ContextId!; - base.OnParametersSet(); - } - - // void CustomizeEditModel(GridCustomizeEditModelEventArgs e) - // { - // if (!e.IsNew) return; - - // var newProductMapping = new UserProductMapping - // { - // ProductId = Guid.NewGuid(), - // UserId = UserModelDtoDetail.Id, - // Permissions = 1 - // }; - - // e.EditModel = newProductMapping; - // } - - // async Task EditModelSaving(GridEditModelSavingEventArgs e) - // { - // if (e.IsNew) - // //add new orderData to orderData array - // _logger.Info("New orderData added"); - // else - // _logger.Info("orderData updated"); - - // await UpdateDataAsync(); - // } - - // async Task DataItemDeleting(GridDataItemDeletingEventArgs e) - // { - // //remove orderData from orderData array - // _logger.Info("orderData deleted"); - // //await UpdateDataAsync(); - // } - - // async Task UpdateDataAsync() - // { - // //refresh grid - // _logger.Info("orderData grid refreshed"); - // } - } \ No newline at end of file diff --git a/TIAMSharedUI/Shared/Components/Grids/TransferDestinationToProductGrid.cs b/TIAMSharedUI/Shared/Components/Grids/TransferDestinationToProductGrid.cs index d77c845a..0951ba30 100644 --- a/TIAMSharedUI/Shared/Components/Grids/TransferDestinationToProductGrid.cs +++ b/TIAMSharedUI/Shared/Components/Grids/TransferDestinationToProductGrid.cs @@ -9,10 +9,10 @@ public class TransferDestinationToProductGrid : TiamGrid GetTransferDestinationById(Guid transferDestinationId) { - var transferDestination = _adminDal.GetTransferDestinationById(transferDestinationId); + var transferDestination = await _adminDal.GetTransferDestinationByIdAsync(transferDestinationId); return transferDestination; } diff --git a/Tiam.Services.Client.Tests/SignalRClientTest.cs b/Tiam.Services.Client.Tests/SignalRClientTest.cs index 5193707e..dd2f7dbe 100644 --- a/Tiam.Services.Client.Tests/SignalRClientTest.cs +++ b/Tiam.Services.Client.Tests/SignalRClientTest.cs @@ -93,10 +93,10 @@ namespace Tiam.Services.Client.Tests [DataTestMethod] [DataRow(["cfb27fc2-54c2-4f07-8471-587d6b79b019", "7385c4e3-3c1e-4c5e-9926-8c0ea60dcb38"])] - public async Task TransferDestinationCrudTest(string[] transferDestIdaddressIdStrings) + public async Task TransferDestinationCrudTest(string[] transferDestIdAddressIdStrings) { - var transferDestId = Guid.Parse(transferDestIdaddressIdStrings[0]); - var addressId = Guid.Parse(transferDestIdaddressIdStrings[1]); + var transferDestId = Guid.Parse(transferDestIdAddressIdStrings[0]); + var addressId = Guid.Parse(transferDestIdAddressIdStrings[1]); var transferDest = TestHelper.CreateTransferDestination(transferDestId, addressId); @@ -129,5 +129,44 @@ namespace Tiam.Services.Client.Tests transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById, transferDestId); Assert.IsNull(transferDest); //a korábbi törlés miatt NULL kell legyen - J. } + + [DataTestMethod] + [DataRow(["cfb27fc2-54c2-4f07-8471-587d6b79b019", "7385c4e3-3c1e-4c5e-9926-8c0ea60dcb38"])] + public async Task TransferDestinationToProductCrudTest(string[] transferDestIdAddressIdStrings) + { + var transferDestId = Guid.Parse(transferDestIdAddressIdStrings[0]); + var addressId = Guid.Parse(transferDestIdAddressIdStrings[1]); + + var transferDest = TestHelper.CreateTransferDestination(transferDestId, addressId); + + await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestinationToProduct, transferDest); + + transferDest = await _signalRClient.PostDataAsync(SignalRTags.CreateTransferDestination, transferDest); + Assert.IsNotNull(transferDest); + + transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById, transferDestId); + + Assert.IsNotNull(transferDest); + Assert.IsNotNull(transferDest.Address); + + var modifiedAddress = "modified; " + transferDest.Address.AddressText; + + transferDest.Price = 20000; + transferDest.Address.AddressText = modifiedAddress; + + transferDest = await _signalRClient.PostDataAsync(SignalRTags.UpdateTransferDestination, transferDest); + + Assert.IsNotNull(transferDest); + Assert.IsNotNull(transferDest.Address); + + Assert.IsTrue((int)transferDest.Price == 20000); + Assert.IsTrue(transferDest.Address.AddressText == modifiedAddress); + Assert.IsTrue(transferDest.Id == transferDestId, "transferDest.Id != transferDestId"); + + await _signalRClient.PostDataAsync(SignalRTags.RemoveTransferDestination, transferDest); //mielõbb kitöröljük, h ne maradjon szemét a db-ben - J. + + transferDest = await _signalRClient.GetByIdAsync(SignalRTags.GetTransferDestinationById, transferDestId); + Assert.IsNull(transferDest); //a korábbi törlés miatt NULL kell legyen - J. + } } } \ No newline at end of file