diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index d3cccfdc..25e2ab7d 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -149,9 +149,10 @@ namespace TIAM.Database.DataLayers.Admins #region TransferDestination public Task> GetTransferDestinationsAsync() => SessionAsync(ctx => ctx.GetTransferDestinations().ToList()); + 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> GetPublicTransferDestinationsAsync(Guid productId) => SessionAsync(ctx => ctx.GetTransferDestinations().Where(x => !x.ProductId.HasValue || x.ProductId == productId).ToList()); public Task AddTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.AddTransferDestination(transferDestination)); public Task UpdateTransferDestinationAsync(TransferDestination transferDestination) => TransactionAsync(ctx => ctx.UpdateTransferDestination(transferDestination)); diff --git a/TIAM.Entities/Transfers/TransferDestination.cs b/TIAM.Entities/Transfers/TransferDestination.cs index 6a4432f3..999aad33 100644 --- a/TIAM.Entities/Transfers/TransferDestination.cs +++ b/TIAM.Entities/Transfers/TransferDestination.cs @@ -16,6 +16,7 @@ namespace TIAM.Entities.Transfers [ForeignKey(nameof(AddressId))] public virtual Address Address { get; set; } + public Guid? ProductId { get; set; } //public virtual List Products { get; set; } //public virtual List TransferDestinationToProducts { get; set; } diff --git a/TIAM.Services/Interfaces/ITransferApiControllerClient.cs b/TIAM.Services/Interfaces/ITransferApiControllerClient.cs index 2104fb72..fcee6203 100644 --- a/TIAM.Services/Interfaces/ITransferApiControllerClient.cs +++ b/TIAM.Services/Interfaces/ITransferApiControllerClient.cs @@ -4,5 +4,6 @@ namespace TIAM.Services.Interfaces; public interface ITransferApiControllerClient : ITransferApiControllerCommon { - Task GetTransferDestinationsInto(List intoDestinationList, Action? callback = null); + Task GetTransferDestinationsAsync(List intoDestinationList, Action? callback = null); + Task GetPublicTransferDestinationsAsync(List intoDestinationList, Guid includeProductId, Action? callback = null); } \ No newline at end of file diff --git a/TIAM.Services/Interfaces/ITransferApiControllerCommon.cs b/TIAM.Services/Interfaces/ITransferApiControllerCommon.cs index 02b8158e..430e755c 100644 --- a/TIAM.Services/Interfaces/ITransferApiControllerCommon.cs +++ b/TIAM.Services/Interfaces/ITransferApiControllerCommon.cs @@ -27,6 +27,7 @@ public interface ITransferApiControllerCommon #region TransferDestination public Task> GetTransferDestinations(); + public Task> GetPublicTransferDestinations(Guid includeProductId); public Task GetTransferDestinationById(Guid transferDestinationId); public Task CreateTransferDestination(TransferDestination transferDestination); public Task UpdateTransferDestination(TransferDestination transferDestination); diff --git a/TIAM.Services/SignalRTags.cs b/TIAM.Services/SignalRTags.cs index 3dd95968..7d95d595 100644 --- a/TIAM.Services/SignalRTags.cs +++ b/TIAM.Services/SignalRTags.cs @@ -100,9 +100,10 @@ public class SignalRTags : AcSignalRTags public const int GetTransferDestinationById = 80; public const int GetAllTransferDestinations = 81; - public const int CreateTransferDestination = 82; - public const int UpdateTransferDestination = 83; - public const int RemoveTransferDestination = 84; //set permissions to 0 + public const int GetAllTransferDestinationsByProductId = 82; + public const int CreateTransferDestination = 83; + public const int UpdateTransferDestination = 84; + public const int RemoveTransferDestination = 85; //set permissions to 0 public const int CreateTransferDestinationToProduct = 90; public const int UpdateTransferDestinationToProduct = 91; diff --git a/TIAMSharedUI/Pages/TransferPage.razor b/TIAMSharedUI/Pages/TransferPage.razor index 06412237..5541caa3 100644 --- a/TIAMSharedUI/Pages/TransferPage.razor +++ b/TIAMSharedUI/Pages/TransferPage.razor @@ -371,7 +371,8 @@ new HeroSliderItem if (createdUserDetail != null) { createdUserDetail.UserDto.RefferalId = userDetail.UserDto.RefferalId; - var updatedNewUser = await _adminSignalRClient.PostDataAsync(SignalRTags.UpdateUserModelDtoDetail, userDetail); + + var updatedNewUser = await _adminSignalRClient.UpdateUserModelDtoDetail(userDetail); if (updatedNewUser != null) { //referral set diff --git a/TIAMSharedUI/Pages/User/CardComponents/ProductCardComponent.razor b/TIAMSharedUI/Pages/User/CardComponents/ProductCardComponent.razor index a9c95b7b..fe39c4ab 100644 --- a/TIAMSharedUI/Pages/User/CardComponents/ProductCardComponent.razor +++ b/TIAMSharedUI/Pages/User/CardComponents/ProductCardComponent.razor @@ -153,7 +153,7 @@ _isAddressTransferDestination = CheckDestinations(_productProfile.AddressId); } - AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget(); + AdminSignalRClient.GetTransferDestinationsAsync(_destinations).Forget(); await base.OnInitializedAsync(); } diff --git a/TIAMSharedUI/Pages/User/Hotels/CreateAndManageTransfer.razor b/TIAMSharedUI/Pages/User/Hotels/CreateAndManageTransfer.razor index 059a5530..ea310d37 100644 --- a/TIAMSharedUI/Pages/User/Hotels/CreateAndManageTransfer.razor +++ b/TIAMSharedUI/Pages/User/Hotels/CreateAndManageTransfer.razor @@ -8,6 +8,7 @@ @using TIAMSharedUI.Pages.Components.EditComponents @using TIAMSharedUI.Shared @using AyCode.Services.Loggers +@using TIAM.Core.Enums @using TIAMWebApp.Shared.Application.Interfaces; @using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels @using TIAMWebApp.Shared.Application.Models.PageModels @@ -38,7 +39,7 @@

Selected Hotel:

- - +
- Reload + Reload
@@ -66,60 +67,58 @@ @code { private LoggerClient _logger; - private TransferWizardModel Data = new(); - private List Hotels = new List(); + private TransferWizardModel _data = new(); + private List _hotels = []; private Product selectedHotel { get; set; } public Product SelectedHotel { - get - { - return selectedHotel; - } + get => selectedHotel; set { + if (selectedHotel == value) return; + selectedHotel = value; StateHasChanged(); } } - public List TransferIgnorList = new List - { - nameof(TransferWizardModel.Id), - nameof(TransferWizardModel.UserId), - nameof(TransferWizardModel.ProductId), - nameof(TransferWizardModel.FirstName), - nameof(TransferWizardModel.LastName), - nameof(TransferWizardModel.UserProductMappingId), - nameof(TransferWizardModel.UserProductToCarId), - nameof(TransferWizardModel.ReferralId), - nameof(TransferWizardModel.Price) - }; - private bool isReloadVisible = false; - private bool SelectedHotelInitialized = false; + public List TransferIgnorList = + [ + nameof(TransferWizardModel.Id), + nameof(TransferWizardModel.UserId), + nameof(TransferWizardModel.ProductId), + nameof(TransferWizardModel.FirstName), + nameof(TransferWizardModel.LastName), + nameof(TransferWizardModel.UserProductMappingId), + nameof(TransferWizardModel.UserProductToCarId), + nameof(TransferWizardModel.ReferralId), + nameof(TransferWizardModel.Price) + ]; + + private bool _isReloadVisible = false; + private bool _selectedHotelInitialized = false; protected override void OnInitialized() { _logger = new LoggerClient(LogWriters.ToArray()); + if (_sessionService.User != null) { - - if (_sessionService.User.UserModelDto.Products.Count() > 0) + if (_sessionService.User.UserModelDto.Products.Any()) { - if (_sessionService.User.UserModelDto.Products.Any(x => x.ProductType == TIAM.Core.Enums.ProductType.Hotel)) + if (_sessionService.User.UserModelDto.Products.Any(x => x.ProductType == ProductType.Hotel)) { - Hotels = _sessionService.GetHotels(); - if (!SelectedHotelInitialized) + _hotels = _sessionService.GetHotels(); + if (!_selectedHotelInitialized) { - SelectedHotel = Hotels[0]; - SelectedHotelInitialized = true; + SelectedHotel = _hotels[0]; + _selectedHotelInitialized = true; } } } } - Data = new TransferWizardModel(); base.OnInitialized(); - } public async Task SubmitForm(object result) @@ -171,13 +170,13 @@ var saveResult = await _adminSignalRClient.PostDataAsync(SignalRTags.AddTransfer, valami); _logger.Info($"Submitted form: {result.GetType().FullName}, {valami.ToAddress}, {valami.FromAddress}, {valami.ProductId}"); - isReloadVisible = true; + _isReloadVisible = true; } public void Reload() { - Data = new TransferWizardModel(); - isReloadVisible = false; + _data = new TransferWizardModel(); + _isReloadVisible = false; StateHasChanged(); } diff --git a/TIAMSharedUI/Pages/User/SysAdmins/ProductDetailGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/ProductDetailGridComponent.razor index 7927f52e..2aa0916e 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/ProductDetailGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/ProductDetailGridComponent.razor @@ -158,7 +158,7 @@ { _logger = new LoggerClient(LogWriters.ToArray()); - AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget(); + AdminSignalRClient.GetTransferDestinationsAsync(_destinations).Forget(); //DataSource = new List
(); } diff --git a/TIAMSharedUI/Pages/User/SysAdmins/ProductGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/ProductGridComponent.razor index 0165a30e..ca534687 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/ProductGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/ProductGridComponent.razor @@ -160,7 +160,7 @@ { _logger = new LoggerClient(LogWriters.ToArray()); - AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget(); + AdminSignalRClient.GetTransferDestinationsAsync(_destinations).Forget(); } private bool CheckDestinations(Guid addressId) diff --git a/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductDetailGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductDetailGridComponent.razor index 93135d5c..4fe9d82b 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductDetailGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductDetailGridComponent.razor @@ -124,7 +124,7 @@ { _logger = new LoggerClient(LogWriters.ToArray()); - AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget(); + AdminSignalRClient.GetTransferDestinationsAsync(_destinations).Forget(); AdminSignalRClient.GetAllIntoAsync(_products, SignalRTags.GetAllProducts).Forget(); base.OnInitialized(); diff --git a/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductGridComponent.razor b/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductGridComponent.razor index f7d0f55d..4bcc3094 100644 --- a/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductGridComponent.razor +++ b/TIAMSharedUI/Pages/User/SysAdmins/TransferDestinationToProductGridComponent.razor @@ -109,7 +109,7 @@ { _logger = new LoggerClient(LogWriters.ToArray()); - AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget(); + AdminSignalRClient.GetTransferDestinationsAsync(_destinations).Forget(); AdminSignalRClient.GetAllIntoAsync(_products, SignalRTags.GetAllProducts).Forget(); await base.OnInitializedAsync(); diff --git a/TIAMSharedUI/Shared/ComboboxItemSelector.razor b/TIAMSharedUI/Shared/ComboboxItemSelector.razor index 90e9d01c..538b5bf8 100644 --- a/TIAMSharedUI/Shared/ComboboxItemSelector.razor +++ b/TIAMSharedUI/Shared/ComboboxItemSelector.razor @@ -110,37 +110,19 @@ // StateHasChanged(); } - protected override async Task OnInitializedAsync() + protected override Task OnInitializedAsync() { _logger = new LoggerClient(LogWriters.ToArray()); - Guid? productAddressId = Guid.Empty; - if (!ProductId.IsNullOrEmpty()) + if (ProductId.IsNullOrEmpty()) _adminSignalRClient.GetTransferDestinationsAsync(_destinations, GetTransferDestinationsCallback()).Forget(); + else _adminSignalRClient.GetPublicTransferDestinationsAsync(_destinations, ProductId.Value, GetTransferDestinationsCallback()).Forget(); + + return Task.CompletedTask; + + Action GetTransferDestinationsCallback() { - var currentProduct = await _adminSignalRClient.GetByIdAsync(SignalRTags.GetProductById, ProductId); - if (currentProduct != null) - { - if (!currentProduct.Profile.AddressId.IsNullOrEmpty()) - { - productAddressId = currentProduct.Profile.AddressId; - } - } + return () => { SelectedDestination = ProductId.IsNullOrEmpty() ? _destinations.FirstOrDefault() : _destinations.FirstOrDefault(x => x.ProductId == ProductId); }; } - - _adminSignalRClient.GetTransferDestinationsInto(_destinations, () => - { - SelectedDestination = productAddressId.IsNullOrEmpty() ? _destinations.FirstOrDefault() : _destinations.FirstOrDefault(x => x.AddressId == productAddressId); - }).Forget(); - - // _adminSignalRClient.GetAllIntoAsync(_destinations, SignalRTags.GetAllTransferDestinations, null, resultData => - // { - // if (resultData == null) SelectedDestination = null; - // else SelectedDestination = productAddressId.IsNullOrEmpty() ? _destinations.FirstOrDefault() : _destinations.FirstOrDefault(x => x.AddressId == productAddressId); - - // return Task.CompletedTask; - // }).Forget(); - - //await _adminSignalRClient.GetAllIntoAsync(Data, SignalRTags.GetAllTransferDestinations); } // RenderFragment GetSelectedItemDescription() diff --git a/TIAMSharedUI/Shared/Components/BaseComponents/BasePageComponent.cs b/TIAMSharedUI/Shared/Components/BaseComponents/BasePageComponent.cs index d1d42989..f6954e1f 100644 --- a/TIAMSharedUI/Shared/Components/BaseComponents/BasePageComponent.cs +++ b/TIAMSharedUI/Shared/Components/BaseComponents/BasePageComponent.cs @@ -47,9 +47,16 @@ namespace TIAMSharedUI.Shared.Components.BaseComponents protected override void OnInitialized() { + Initialize(); base.OnInitialized(); + } + + private void Initialize() + { _logger = new LoggerClient(_logWriters.ToArray()); + var currentUrl = _navManager.ToBaseRelativePath(_navManager.Uri); + _pageState.AddPageToHistory(currentUrl); _logger.Debug(_pageState.GetGoBackPage()); } diff --git a/TIAMSharedUI/Shared/Components/BaseComponents/UserBasePageComponent.cs b/TIAMSharedUI/Shared/Components/BaseComponents/UserBasePageComponent.cs index b3a52997..027f9d34 100644 --- a/TIAMSharedUI/Shared/Components/BaseComponents/UserBasePageComponent.cs +++ b/TIAMSharedUI/Shared/Components/BaseComponents/UserBasePageComponent.cs @@ -17,20 +17,20 @@ namespace TIAMSharedUI.Shared.Components.BaseComponents { [Authorize] public class UserBasePageComponent : BasePageComponent - { - + { private LoggerClient _logger = null!; + public UserBasePageComponent() { - + } protected override void OnInitialized() { - base.OnInitialized(); _logger = new LoggerClient(_logWriters.ToArray()); - + + base.OnInitialized(); } } } diff --git a/TIAMSharedUI/Shared/NavHelperComponent.razor b/TIAMSharedUI/Shared/NavHelperComponent.razor index 431246c3..357cf255 100644 --- a/TIAMSharedUI/Shared/NavHelperComponent.razor +++ b/TIAMSharedUI/Shared/NavHelperComponent.razor @@ -24,17 +24,17 @@ protected override void OnInitialized() { - if(pageHistoryState.CanGoBack()) + if (pageHistoryState.CanGoBack()) { isBackVisible = true; - } + } } private void GoBack() { @if (pageHistoryState.CanGoBack()) { - NavManager.NavigateTo(pageHistoryState.GetGoBackPage()); - } + NavManager.NavigateTo(pageHistoryState.GetGoBackPage()!); + } } } diff --git a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs index a04aa8f8..65ed3eb8 100644 --- a/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs +++ b/TIAMWebApp/Server/Controllers/TransferDataAPIController.cs @@ -82,6 +82,13 @@ namespace TIAMWebApp.Server.Controllers return await _adminDal.GetTransferDestinationsAsync(); } + [NonAction] + [SignalR(SignalRTags.GetAllTransferDestinationsByProductId)] + public async Task> GetPublicTransferDestinations(Guid includeProductId) + { + return await _adminDal.GetPublicTransferDestinationsAsync(includeProductId); + } + //[Authorize] //[HttpGet] //[Route(APIUrls.GetTransferDriversByTransferIdRouteName)] diff --git a/TIAMWebApp/Shared/Services/AdminSignalRClient.cs b/TIAMWebApp/Shared/Services/AdminSignalRClient.cs index 8e423118..1a14b69c 100644 --- a/TIAMWebApp/Shared/Services/AdminSignalRClient.cs +++ b/TIAMWebApp/Shared/Services/AdminSignalRClient.cs @@ -127,9 +127,15 @@ namespace TIAMWebApp.Shared.Application.Services public async Task> GetTransferDestinations() => await GetAllAsync>(SignalRTags.GetAllTransferDestinations) ?? []; - public Task GetTransferDestinationsInto(List intoDestinationList, Action? callback = null) + + public Task GetTransferDestinationsAsync(List intoDestinationList, Action? callback = null) => GetAllIntoAsync(intoDestinationList, SignalRTags.GetAllTransferDestinations, null, callback); + public async Task> GetPublicTransferDestinations(Guid includeProductId) + => await GetAllAsync>(SignalRTags.GetAllTransferDestinationsByProductId, [includeProductId]) ?? []; + + public Task GetPublicTransferDestinationsAsync(List intoDestinationList, Guid includeProductId, Action? callback = null) + => GetAllIntoAsync(intoDestinationList, SignalRTags.GetAllTransferDestinationsByProductId, [includeProductId], callback); public async Task GetTransferDestinationById(Guid transferDestinationId) { diff --git a/TIAMWebApp/Shared/Services/SessionServiceClientBase.cs b/TIAMWebApp/Shared/Services/SessionServiceClientBase.cs index fa0bec25..d5014e7f 100644 --- a/TIAMWebApp/Shared/Services/SessionServiceClientBase.cs +++ b/TIAMWebApp/Shared/Services/SessionServiceClientBase.cs @@ -1,4 +1,5 @@ using System.Net; +using TIAM.Core.Enums; using TIAM.Entities.Products; using TIAM.Models; using TIAMWebApp.Shared.Application.Interfaces; @@ -23,7 +24,7 @@ public abstract class SessionServiceClientBase : ISessionService public virtual List GetHotels() { - return User != null ? User.UserModelDto.Products.Where(x => x.ProductType == TIAM.Core.Enums.ProductType.Hotel).ToList() : []; + return User != null ? User.UserModelDto.Products.Where(x => x.ProductType == ProductType.Hotel).ToList() : []; } public virtual void ClearAll() diff --git a/TIAMWebApp/Shared/Utility/PageHistoryState.cs b/TIAMWebApp/Shared/Utility/PageHistoryState.cs index 6a8be99d..fff7834d 100644 --- a/TIAMWebApp/Shared/Utility/PageHistoryState.cs +++ b/TIAMWebApp/Shared/Utility/PageHistoryState.cs @@ -8,32 +8,24 @@ namespace TIAMWebApp.Shared.Application.Utility { public class PageHistoryState { - private List previousPages; + private readonly List _previousPages = []; public PageHistoryState() + { } + + public void AddPageToHistory(string pageUrl) { - previousPages = new List(); - } - public void AddPageToHistory(string pageName) - { - previousPages.Add(pageName); + _previousPages.Add(pageUrl); } public string GetGoBackPage() { - if (previousPages.Count > 1) - { - // You add a page on initialization, so you need to return the 2nd from the last - return previousPages.ElementAt(previousPages.Count - 2); - } - - // Can't go back because you didn't navigate enough - return previousPages.FirstOrDefault(); + return _previousPages.Count > 1 ? _previousPages[^2] : _previousPages.FirstOrDefault() ?? string.Empty; } public bool CanGoBack() { - return previousPages.Count > 1; + return _previousPages.Count > 1; } } }