diff --git a/TIAM.Database/DataLayers/Admins/AdminDal.cs b/TIAM.Database/DataLayers/Admins/AdminDal.cs index b0fce43f..25e2ab7d 100644 --- a/TIAM.Database/DataLayers/Admins/AdminDal.cs +++ b/TIAM.Database/DataLayers/Admins/AdminDal.cs @@ -148,10 +148,11 @@ namespace TIAM.Database.DataLayers.Admins #region TransferDestination - public List GetTransferDestinations() => Session(ctx => ctx.GetTransferDestinations().ToList()); + 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 59d6b1fd..fcee6203 100644 --- a/TIAM.Services/Interfaces/ITransferApiControllerClient.cs +++ b/TIAM.Services/Interfaces/ITransferApiControllerClient.cs @@ -1,5 +1,9 @@ -namespace TIAM.Services.Interfaces; +using TIAM.Entities.Transfers; -public interface ITransferApiControllerClient : IUserApiControllerCommon +namespace TIAM.Services.Interfaces; + +public interface ITransferApiControllerClient : ITransferApiControllerCommon { + 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 a2925269..430e755c 100644 --- a/TIAM.Services/Interfaces/ITransferApiControllerCommon.cs +++ b/TIAM.Services/Interfaces/ITransferApiControllerCommon.cs @@ -26,7 +26,8 @@ public interface ITransferApiControllerCommon #endregion Drivers #region TransferDestination - public List GetTransferDestinations(); + 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 1e540bd6..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; @@ -113,8 +114,13 @@ public class SignalRTags : AcSignalRTags public const int GetTransferDestinationToProductsByTransferDestinationId = 96; public const int GetAllUsers = 120; - public const int GetAllUserModelDtoDetails = 121; - public const int GetAllUserModelDtoEmails = 125; + public const int GetAllUserModelDto = 121; + public const int GetAllUserModelDtoDetails = 122; + public const int GetAllUserModelDtoEmails = 123; + public const int GetUserModelDtoById = 126; + public const int GetUserModelDtoByEmail = 127; + public const int GetUserModelDtoDetailById = 128; + public const int GetUserModelDtoDetailByEmail = 129; public const int AddUser = 130; public const int AddUserModelDtoDetail = 131; public const int UpdateUser = 135; @@ -125,5 +131,6 @@ public class SignalRTags : AcSignalRTags public const int GuestUpdateTransfer = 150; public const int DriverUpdateTransfer = 151; + public const int AuthenticateUser = 160; public const int GetAllLogItemsByFilterText = 1000; } diff --git a/TIAMMobileApp/Services/UserDataServiceMobile.cs b/TIAMMobileApp/Services/UserDataServiceMobile.cs index 07f5ae4f..dba4f1e3 100644 --- a/TIAMMobileApp/Services/UserDataServiceMobile.cs +++ b/TIAMMobileApp/Services/UserDataServiceMobile.cs @@ -17,7 +17,7 @@ using TIAMWebApp.Shared.Application.Utility; namespace TIAMMobileApp.Services { - public class UserDataServiceMobile(HttpClient http, ISessionService sessionService, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable logWriters) - : UserDataServiceClientBase(http, sessionService, secureStorageHandler, serviceProviderDataService, logWriters); + public class UserDataServiceMobile(HttpClient http, AdminSignalRClient adminSignalRClient, ISessionService sessionService, ISecureStorageHandler secureStorageHandler, IServiceProviderDataService serviceProviderDataService, IEnumerable logWriters) + : UserDataServiceClientBase(http, adminSignalRClient, sessionService, secureStorageHandler, serviceProviderDataService, logWriters); } diff --git a/TIAMSharedUI/Pages/Login.razor.cs b/TIAMSharedUI/Pages/Login.razor.cs index 0a81b8d1..0ce4884f 100644 --- a/TIAMSharedUI/Pages/Login.razor.cs +++ b/TIAMSharedUI/Pages/Login.razor.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Components; using System.IdentityModel.Tokens.Jwt; using System.Text.Json; +using AyCode.Core.Extensions; using AyCode.Core.Helpers; using TIAMWebApp.Shared.Application.Models.ClientSide; using TIAMWebApp.Shared.Application.Models; @@ -64,80 +65,79 @@ namespace TIAMSharedUI.Pages { _currentStep = 1; BrowserConsoleLogWriter.Info("Login started: " + "Email: " + _loginModel.Email + ", Password: " + _loginModel.Password); - var response = await userDataService.AuthenticateUser(_loginModel); + + var mainResponse = await userDataService.AuthenticateUser(_loginModel); + //var response = await UserDataservice.TestUserApi(30); BrowserConsoleLogWriter.Info("Login started"); - BrowserConsoleLogWriter.Info(response); + //BrowserConsoleLogWriter.Info(response); - if (!string.IsNullOrEmpty(response)) + //if (!string.IsNullOrEmpty(response)) + if (mainResponse != null) { //get token and save to local storage //parse to Mainresponse from json string //var Mainresponse = JsonSerializer.Deserialize(response); - var mainResponse = JsonSerializer.Deserialize(response, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + //var mainResponse = JsonSerializer.Deserialize(response, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); - if (mainResponse != null) + if (!mainResponse.IsSuccess) { + //await App.Current.MainPage.DisplayAlert("Error", "Invalid credentials", "Ok"); + //display error message via jsinterop + BrowserConsoleLogWriter.Info("Invalid credentials"); + messageClass = "text-danger"; + resultMessage = "Invalid credentials"; + await InvokeAsync(StateHasChanged); + //navManager.NavigateTo("login"); + } + else + { + string authResponseJson = mainResponse.Content.ToJson(); //JsonSerializer.Serialize(mainResponse.Content); - if (!mainResponse.IsSuccess) + var authResponse = authResponseJson.JsonTo(); //JsonSerializer.Deserialize(authResponseJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + + string accessToken = authResponse.AccessToken; + + var token = ProcessToken(accessToken); + + string userId = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value; + string email = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; + + var myId = Guid.Parse(userId); + //userDataService.User.Email = _email; + + var userBasicDetails = new UserBasicDetails(userId, email, authResponse.AccessToken, authResponse.RefreshToken); + + string userBasicDetailsJson = JsonSerializer.Serialize(userBasicDetails); + + + //save to local storage + await secureStorageHandler.SaveToSecureStorageAsync(nameof(Setting.UserBasicDetails), userBasicDetailsJson); + + await AuthStateProvider.GetAuthenticationStateAsync(); + + + //await App.Current.MainPage.DisplayAlert("Success", "Successful login", "Ok"); + //display success message via jsinterop + BrowserConsoleLogWriter.Info("Successful login"); + var user = await userDataService.IsLoggedInAsync(myId); + + _adminSignalRClient.GetByIdAsync(SignalRTags.GetSiteViewModelByUserId, signalResponseMessage => { - //await App.Current.MainPage.DisplayAlert("Error", "Invalid credentials", "Ok"); - //display error message via jsinterop - BrowserConsoleLogWriter.Info("Invalid credentials"); - messageClass = "text-danger"; - resultMessage = "Invalid credentials"; - await InvokeAsync(StateHasChanged); - //navManager.NavigateTo("login"); - } - else - { - string authResponseJson = JsonSerializer.Serialize(mainResponse.Content); + sessionService.SiteViewModel.Initialize(signalResponseMessage.ResponseData!); + BrowserConsoleLogWriter.Debug($"UnreadMessages: {sessionService.SiteViewModel.UnreadMessages.Count}"); - var authResponse = JsonSerializer.Deserialize(authResponseJson, new JsonSerializerOptions { PropertyNameCaseInsensitive = true }); + componentUpdateService.CallRequestRefreshAll(); + return Task.CompletedTask; + }, user.UserId).Forget(); - string accessToken = authResponse.AccessToken; + messageClass = "text-success"; + resultMessage = "Successful login"; - var token = ProcessToken(accessToken); - - string userId = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.NameId).Value; - string email = token.Claims.First(claim => claim.Type == JwtRegisteredClaimNames.Email).Value; - - var myId = Guid.Parse(userId); - //userDataService.User.Email = _email; - - var userBasicDetails = new UserBasicDetails(userId, email, authResponse.AccessToken, authResponse.RefreshToken); - - string userBasicDetailsJson = JsonSerializer.Serialize(userBasicDetails); - - - //save to local storage - await secureStorageHandler.SaveToSecureStorageAsync(nameof(Setting.UserBasicDetails), userBasicDetailsJson); - - await AuthStateProvider.GetAuthenticationStateAsync(); - - - //await App.Current.MainPage.DisplayAlert("Success", "Successful login", "Ok"); - //display success message via jsinterop - BrowserConsoleLogWriter.Info("Successful login"); - var user = await userDataService.IsLoggedInAsync(myId); - - _adminSignalRClient.GetByIdAsync(SignalRTags.GetSiteViewModelByUserId, signalResponseMessage => - { - sessionService.SiteViewModel.Initialize(signalResponseMessage.ResponseData!); - BrowserConsoleLogWriter.Debug($"UnreadMessages: {sessionService.SiteViewModel.UnreadMessages.Count}"); - - componentUpdateService.CallRequestRefreshAll(); - return Task.CompletedTask; - }, user.UserId).Forget(); - - messageClass = "text-success"; - resultMessage = "Successful login"; - - SaveToSessionInfo(user).Forget(); - navManager.NavigateTo("/"); - } + SaveToSessionInfo(user).Forget(); + navManager.NavigateTo("/"); } } else @@ -145,10 +145,9 @@ namespace TIAMSharedUI.Pages //api error //await App.Current.MainPage.DisplayAlert("Error", "An error occured while trying to login", "Ok"); //display error message via jsinterop - BrowserConsoleLogWriter.Info("An error occured while trying to login"); + BrowserConsoleLogWriter.Warning("An error occured while trying to login"); navManager.NavigateTo("login"); } - } protected override void OnInitialized() diff --git a/TIAMSharedUI/Pages/TransferPage.razor b/TIAMSharedUI/Pages/TransferPage.razor index 06412237..c652b4a5 100644 --- a/TIAMSharedUI/Pages/TransferPage.razor +++ b/TIAMSharedUI/Pages/TransferPage.razor @@ -11,22 +11,24 @@ @using TIAMWebApp.Shared.Application.Models.ClientSide.UI @using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels @using AyCode.Services.Loggers +@using TIAMSharedUI.Pages.User.Hotels @using TIAMWebApp.Shared.Application.Models.PageModels @using TIAMWebApp.Shared.Application.Services +@using TIAMWebApp.Shared.Application.Utility @inherits BasePageComponent @inject NavigationManager navManager -@inject IAcLogWriterClientBase BrowserConsoleLogWriter +@inject IEnumerable LogWriters @inject IWizardProcessor WizardProcessor @inject IUserDataService UserDataService @inject AdminSignalRClient _adminSignalRClient Transfer - +
- + @{ - if (displayHelp) + if (_displayHelp) {
@@ -164,18 +166,18 @@ - - + + - + - + @@ -187,8 +189,8 @@ SubtitleResourceString="TransferSubtitle"> *@ -
- +
+
@@ -234,83 +236,88 @@ @code { - public TransferWizardModel myModel = new TransferWizardModel(); + private LoggerClient _logger; - public List sliders = new List - { - new HeroSliderItem - { - Title = "Welcome to TIAM", - ImageUrl = "_content/TIAMSharedUI/images/f1_1.png" - }, - new HeroSliderItem - { - Title = "Welcome to TIAM", - ImageUrl = "_content/TIAMSharedUI/images/f1_2.png" - }, -new HeroSliderItem - { - Title = "Welcome to TIAM", - ImageUrl = "_content/TIAMSharedUI/images/f1_3.png" - }, - }; + private readonly TransferWizardModel _myModel = new TransferWizardModel(); - public List TransferIgnorList1 = new List - { - "Id", - "Destination", - "UserId", - "ProductId", - "PaymentId", - "TripDate", - "FirstName", - "LastName", - "UserProductMappingId", - "UserProductToCarId", - "ReferralId", - "Price" - }; + private readonly List _sliders = + [ + new HeroSliderItem + { + Title = "Welcome to TIAM", + ImageUrl = "_content/TIAMSharedUI/images/f1_1.png" + }, - public List TransferIgnorList2 = new List - { - "Id", - "PickupAddress", - "UserId", - "ProductId", - "PaymentId", - "TripDate", - "FirstName", - "LastName", - "UserProductMappingId", - "UserProductToCarId", - "ReferralId", - "Price" - }; + new HeroSliderItem + { + Title = "Welcome to TIAM", + ImageUrl = "_content/TIAMSharedUI/images/f1_2.png" + }, + + new HeroSliderItem + { + Title = "Welcome to TIAM", + ImageUrl = "_content/TIAMSharedUI/images/f1_3.png" + } + ]; + + private readonly List _transferIgnorList1 = + [ + "Id", + "Destination", + "UserId", + "ProductId", + "PaymentId", + "TripDate", + "FirstName", + "LastName", + "UserProductMappingId", + "UserProductToCarId", + "ReferralId", + "Price" + ]; + + private readonly List _transferIgnorList2 = + [ + "Id", + "PickupAddress", + "UserId", + "ProductId", + "PaymentId", + "TripDate", + "FirstName", + "LastName", + "UserProductMappingId", + "UserProductToCarId", + "ReferralId", + "Price" + ]; /*protected override void OnAfterRender(bool isFirst) { message = " Target destination is " + slider.SliderElementId.ToString(); }*/ - private bool toAirport = true; + private bool _toAirport = true; - private bool displayHelp = false; + private bool _displayHelp = false; public void ToAirport() { - toAirport = true; - myModel.Destination = "Budapest, 1185"; + _toAirport = true; + _myModel.Destination = "Budapest, 1185"; } public void FromAirport() { - toAirport = false; - myModel.PickupAddress = "Budapest, 1185"; + _toAirport = false; + _myModel.PickupAddress = "Budapest, 1185"; } - public async Task SubmitForm(object Result) + public async Task SubmitForm(object result) { - TransferWizardModel resModel = (TransferWizardModel)Result; + var resModel = (TransferWizardModel)result; + //let's check if user exists with this email var user = await UserDataService.GetUserByEmailAsync(resModel.EmailAddress!); if (user != null && user.Id != Guid.Empty) @@ -371,7 +378,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 @@ -381,6 +389,7 @@ new HeroSliderItem //something wrong } } + resModel.ReferralId = userDetail.UserDto.RefferalId; } @@ -393,20 +402,23 @@ new HeroSliderItem } } } - var transfer = await WizardProcessor.ProcessWizardAsync(Result.GetType(), Result); - BrowserConsoleLogWriter.Info($"Submitted nested form: {Result.GetType().FullName}"); + + var transfer = await WizardProcessor.ProcessWizardAsync(result.GetType(), result); + _logger.Info($"Submitted nested form: {result.GetType().FullName}"); navManager.NavigateTo($"/transfer2/{resModel.Id}"); } protected override Task OnInitializedAsync() { + _logger = new LoggerClient(LogWriters.ToArray()); + ToAirport(); return base.OnInitializedAsync(); } private void ShowHelp_Click() { - displayHelp = !displayHelp; + _displayHelp = !_displayHelp; } } diff --git a/TIAMSharedUI/Pages/User/CardComponents/ProductCardComponent.razor b/TIAMSharedUI/Pages/User/CardComponents/ProductCardComponent.razor index e505c230..fe39c4ab 100644 --- a/TIAMSharedUI/Pages/User/CardComponents/ProductCardComponent.razor +++ b/TIAMSharedUI/Pages/User/CardComponents/ProductCardComponent.razor @@ -1,4 +1,5 @@ -@using BlazorAnimation +@using AyCode.Core.Helpers +@using BlazorAnimation @using TIAM.Core.Enums @using TIAM.Entities.Addresses @using TIAM.Entities.Products @@ -42,7 +43,7 @@

Information

- @RenderDetailsItem("fa-solid fa-user", "Contact Name", productProfile.FullName) + @RenderDetailsItem("fa-solid fa-user", "Contact Name", _productProfile.FullName) @RenderDetailsItem("fa-solid fa-circle-info", "Description", Context.Description)
@@ -79,16 +80,16 @@
@{ - if (!isAddressTransferDestination) + if (!_isAddressTransferDestination) { - + } }
-

@msg

+

@_msg

@@ -120,11 +121,11 @@ AccordionExpandMode ExpandMode { get; set; } = AccordionExpandMode.SingleOrNone; AccordionExpandCollapseAction ExpandCollapseAction { get; set; } = AccordionExpandCollapseAction.HeaderClick; - private Profile productProfile = new Profile(); - private List destinations = new List(); - string msg; - private bool isSaveActive = false; - private bool isAddressTransferDestination = false; + private Profile _productProfile = new Profile(); + private readonly List _destinations = []; + string _msg; + private bool _isSaveActive = false; + private bool _isAddressTransferDestination = false; private async Task CopyUrl(string url) { @@ -139,19 +140,20 @@ protected override async Task OnInitializedAsync() { var productOwner = await AdminSignalRClient.GetByIdAsync>(SignalRTags.GetCompaniesById, Context.ServiceProviderId); - var ProductProfiles = await AdminSignalRClient.GetByIdAsync>(SignalRTags.GetProfileById, Context.ProfileId); - await AdminSignalRClient.GetAllIntoAsync(destinations, SignalRTags.GetAllTransferDestinations); + var productProfiles = await AdminSignalRClient.GetByIdAsync>(SignalRTags.GetProfileById, Context.ProfileId); + if (productOwner != null) { - ImageSource = await ServiceProviderDataService.GetQRCodeByProductIdAndOwnerAffiliateIdAsync(new Guid[] { productOwner[0].AffiliateId, Context.Id }); - } - if (ProductProfiles != null) - { - productProfile = ProductProfiles[0]; - var AddressId = productProfile.AddressId; - isAddressTransferDestination = CheckDestinations(AddressId); + ImageSource = await ServiceProviderDataService.GetQRCodeByProductIdAndOwnerAffiliateIdAsync([productOwner[0].AffiliateId, Context.Id]); } + if (productProfiles != null) + { + _productProfile = productProfiles[0]; + _isAddressTransferDestination = CheckDestinations(_productProfile.AddressId); + } + + AdminSignalRClient.GetTransferDestinationsAsync(_destinations).Forget(); await base.OnInitializedAsync(); } @@ -163,40 +165,27 @@ RenderFragment RenderDetailsItem(string iconCssClass, string caption, string value) { return @
-
- -
-
- -
@value
-
-
; +
+ +
+
+ +
@value
+
+ ; } private bool CheckDestinations(Guid addressId) { - if (destinations != null) - { - if (destinations.Any(d => d.AddressId == addressId)) - { - return true; - } - else - { - return false; - } - } - else - { - return false; - } + return _destinations.Any(d => d.AddressId == addressId); } private async Task SaveAsDestination(Address address, Product product) { - TransferDestination transferDestination = new TransferDestination(); + var transferDestination = new TransferDestination(); transferDestination.Id = Guid.NewGuid(); transferDestination.Name = product.Name; + if (!string.IsNullOrEmpty(product.Profile.Description)) { transferDestination.Description = product.Profile.Description; @@ -205,8 +194,10 @@ { transferDestination.Description = "No description available"; } + transferDestination.AddressId = address.Id; transferDestination.AddressString = address.AddressText; + var result = await AdminSignalRClient.PostDataAsync(SignalRTags.CreateTransferDestination, transferDestination); await InvokeAsync(StateHasChanged); } diff --git a/TIAMSharedUI/Pages/User/CardComponents/TransferCardComponent.razor b/TIAMSharedUI/Pages/User/CardComponents/TransferCardComponent.razor index 71f5f2cc..744be4c9 100644 --- a/TIAMSharedUI/Pages/User/CardComponents/TransferCardComponent.razor +++ b/TIAMSharedUI/Pages/User/CardComponents/TransferCardComponent.razor @@ -109,10 +109,10 @@ @RenderDetailsItem("fa-solid fa-hashtag", "Comment", Context.Comment)
- @RenderDetailsItem("fa-solid fa-list-check", "Status", AllStatuses.FirstOrDefault(x => x.StatusValue == (byte)Context.TransferStatusType).StatusName) + @RenderDetailsItem("fa-solid fa-list-check", "Status", TransferStatusModel.GetStatusModel(Context.TransferStatusType).StatusName)
- Statuses = new[] - { - new TransferStatusModel(Convert.ToByte(TransferStatusType.DriverConfirmed), "Driver confirmed"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.DriverEnRoute), "Driver enroute"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.PassengerPickup), "Passenger in car"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.Finished), "Finished"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.UserCanceled), "User cancelled"), - }; + private static readonly IEnumerable DriverStatuses = TransferStatusModel.AllStatuses.Values.Where(x => x.StatusValue is TransferStatusType.DriverConfirmed or + TransferStatusType.DriverEnRoute or TransferStatusType.PassengerPickup or TransferStatusType.Finished or TransferStatusType.UserCanceled); + + // private static readonly IEnumerable Statuses = new[] + // { + // new TransferStatusModel(TransferStatusType.DriverConfirmed, "Driver confirmed"), + // new TransferStatusModel(TransferStatusType.DriverEnRoute, "Driver enroute"), + // new TransferStatusModel(TransferStatusType.PassengerPickup, "Passenger in car"), + // new TransferStatusModel(TransferStatusType.Finished, "Finished"), + // new TransferStatusModel(TransferStatusType.UserCanceled, "User cancelled"), + // }; - private static readonly List AllStatuses = new() - { - new TransferStatusModel(Convert.ToByte(TransferStatusType.OrderSubmitted), "Order submitted"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.OrderConfirmed), "Order confirmed"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.AssignedToDriver), "Assigned to driver"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.DriverConfirmed), "Driver confirmed"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.DriverEnRoute), "Driver enroute"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.PassengerPickup), "Passenger in car"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.Finished), "Finished"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.UserCanceled), "User cancelled"), - new TransferStatusModel(Convert.ToByte(TransferStatusType.AdminDenied), "Admin cancelled") - }; private TransferStatusModel _currentStatusType; public TransferStatusModel CurrentStatusType @@ -245,7 +236,7 @@ var result = await AdminSignalRClient.PostDataAsync(SignalRTags.UpdateTransfer, Context); if (result != null) { - if (AllStatuses.FirstOrDefault(x => x.StatusValue == (byte)result.TransferStatusType) == CurrentStatusType) + if (TransferStatusModel.GetStatusModel(result.TransferStatusType) == CurrentStatusType) { msg = $"Stataus saved"; StateHasChanged(); @@ -282,13 +273,14 @@ { _logger = new LoggerClient(LogWriters.ToArray()); sysAdmins = await AdminSignalRClient.GetByIdAsync>(SignalRTags.GetAllUserModelDtoDetails, TiamConstClient.SysAdmins[0]); + await base.OnInitializedAsync(); } protected override Task OnParametersSetAsync() { - CurrentStatusType = AllStatuses.FirstOrDefault(x => x.StatusValue == (byte)Context.TransferStatusType); - + CurrentStatusType = TransferStatusModel.GetStatusModel(Context.TransferStatusType); + return base.OnParametersSetAsync(); } diff --git a/TIAMSharedUI/Pages/User/Drivers/DriverManageTransfers.razor b/TIAMSharedUI/Pages/User/Drivers/DriverManageTransfers.razor index b51b7cd3..54121d0e 100644 --- a/TIAMSharedUI/Pages/User/Drivers/DriverManageTransfers.razor +++ b/TIAMSharedUI/Pages/User/Drivers/DriverManageTransfers.razor @@ -227,19 +227,6 @@ "ContextId", ]; - private static readonly List Statuses = - [ - new(Convert.ToByte(TransferStatusType.OrderSubmitted), "Order submitted"), - new(Convert.ToByte(TransferStatusType.OrderConfirmed), "Order confirmed"), - new(Convert.ToByte(TransferStatusType.AssignedToDriver), "Assigned to driver"), - new(Convert.ToByte(TransferStatusType.DriverConfirmed), "Driver confirmed"), - new(Convert.ToByte(TransferStatusType.DriverEnRoute), "Driver enroute"), - new(Convert.ToByte(TransferStatusType.PassengerPickup), "Passenger in car"), - new(Convert.ToByte(TransferStatusType.Finished), "Finished"), - new(Convert.ToByte(TransferStatusType.UserCanceled), "User cancelled"), - new(Convert.ToByte(TransferStatusType.AdminDenied), "Admin cancelled") - ]; - void Grid_CustomizeElement(GridCustomizeElementEventArgs e) { try diff --git a/TIAMSharedUI/Pages/User/Hotels/CreateAndManageTransfer.razor b/TIAMSharedUI/Pages/User/Hotels/CreateAndManageTransfer.razor index 059a5530..e9b0e3ec 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,67 +67,68 @@ @code { private LoggerClient _logger; - private TransferWizardModel Data = new(); - private List Hotels = new List(); - private Product selectedHotel { get; set; } - public Product SelectedHotel + private TransferWizardModel _data = new(); + private List _hotels = []; + + private static Product? _selectedHotel; + public Product? SelectedHotel { - get - { - return selectedHotel; - } + get => _selectedHotel; set { - selectedHotel = value; + 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; 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) - { - SelectedHotel = Hotels[0]; - SelectedHotelInitialized = true; - } + _hotels = _sessionService.GetHotels(); + SelectedHotel = _hotels.FirstOrDefault(x => x.Id == _selectedHotel?.Id) ?? _hotels[0]; } } } - Data = new TransferWizardModel(); base.OnInitialized(); - } public async Task SubmitForm(object result) { + if (_selectedHotel == null) + { + _logger.Error($"_selectedHotel == null"); + return; + } + var valami = ((TransferWizardModel)result).CopyToTransfer(); valami.Id = Guid.NewGuid(); - valami.ProductId = SelectedHotel.Id; + valami.ProductId = _selectedHotel.Id; + var user = await UserDataService.GetUserByEmailAsync(valami.ContactEmail); if (user != null && user.Id != Guid.Empty) { @@ -152,7 +154,7 @@ registration.PhoneNumber = valami.ContactPhone; registration.Password = password; //get list with one member! - var productOwner = await _adminSignalRClient.GetByIdAsync>(SignalRTags.GetCompaniesById, SelectedHotel.ServiceProviderId); + var productOwner = await _adminSignalRClient.GetByIdAsync>(SignalRTags.GetCompaniesById, _selectedHotel.ServiceProviderId); registration.ReferralId = productOwner[0].AffiliateId; @@ -166,18 +168,19 @@ } _logger.Info("New user created added"); } + //valami.ProductId = SessionService.User.UserId; //TODO ProductID! // await WizardProcessor.ProcessWizardAsync(result.GetType(), result); 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/Hotels/HotelComponent.razor b/TIAMSharedUI/Pages/User/Hotels/HotelComponent.razor index 03d8bdb8..1aadcc6d 100644 --- a/TIAMSharedUI/Pages/User/Hotels/HotelComponent.razor +++ b/TIAMSharedUI/Pages/User/Hotels/HotelComponent.razor @@ -44,9 +44,9 @@
-

Hotel name: @hotelName

-

Address: @hotelAddress

-

Contact name: @hotelContactName

+

Hotel name: @_hotelName

+

Address: @_hotelAddress

+

Contact name: @_hotelContactName

@@ -79,7 +79,7 @@
-