TourIAm/TIAMSharedUI/Pages/TransferPage.razor

215 lines
8.1 KiB
Plaintext

@page "/transfer"
@using AyCode.Core.Consts
@using AyCode.Core.Helpers
@using TIAM.Models.Dtos.Users
@using TIAM.Services
@using TIAMSharedUI.Pages.Components
@using TIAMSharedUI.Pages.Components.EditComponents
@using TIAMSharedUI.Shared
@using TIAMSharedUI.Shared.Components.BaseComponents
@using TIAMWebApp.Shared.Application.Interfaces
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
@using AyCode.Services.Loggers
@using TIAMWebApp.Shared.Application.Models.PageModels
@using TIAMWebApp.Shared.Application.Services
@inherits BasePageComponent
@inject NavigationManager navManager
@inject IAcLogWriterClientBase BrowserConsoleLogWriter
@inject IWizardProcessor WizardProcessor
@inject IUserDataService UserDataService
@inject AdminSignalRClient _adminSignalRClient
<PageTitle>Transfer</PageTitle>
<HeroSlider SliderItems="sliders" Height="30vh"></HeroSlider>
<div class="container-fluid" style="position: relative; z-index: 2;">
<div class="row d-flex justify-content-center">
<div class="col-12 col-lg-6">
@* <InputWizard Data=@myModel
OnSubmit="SubmitForm"
IgnoreReflection="@TransferIgnorList"
SubmitButtonText="ButtonSend"
TitleResourceString="TransferTitle"
SubtitleResourceString="TransferSubtitle"></InputWizard> *@
<DynamicEditForm Data="myModel" isEditing="true" IgnoreReflection="TransferIgnorList" OnSubmit="SubmitForm"></DynamicEditForm>
</div>
</div>
</div>
<div class="container mt-5">
<div class="row align-items-center">
<div class="col-12 col-sm-6 p-5">
<h1>Book an Airport Transfer</h1>
<p>Welcome to Tour I Am! Book your airport transfer with us for a smooth and stress-free experience. Our professional drivers are ready to take you to and from the airport in comfort and style. We offer competitive rates and reliable service, ensuring you get to your destination on time.</p>
<h2>Why Choose Tour I Am?</h2>
<ul class="list-unstyled">
<li><strong>Reliable Service:</strong> Punctual pickups and drop-offs.</li>
<li><strong>Professional Drivers:</strong> Experienced and courteous drivers.</li>
<li><strong>Affordable Rates:</strong> Competitive pricing with no hidden fees.</li>
<li><strong>Comfortable Vehicles:</strong> Clean, modern, and well-maintained cars.</li>
</ul>
</div>
<div class="col-12 col-sm-6 p-5">
<img class="img-fluid" src="_content/TIAMSharedUI/images/about1.jpg" />
</div>
<div class="col-12 col-sm-6 p-5">
<img class="img-fluid" src="_content/TIAMSharedUI/images/about2.jpg" />
</div>
<div class="col-12 col-sm-6 p-5">
<h2>How to Book</h2>
<p>Booking your airport transfer is easy! Simply visit our <a href="/transfer">booking page</a>, enter your details, and confirm your reservation. You can also contact us at <a href="mailto:info@touriam.com">info@touriam.com</a> or call us at (123) 456-7890 for assistance.</p>
<p>Experience the convenience and reliability of Tour I Am. Book your airport transfer today and travel with peace of mind!</p>
</div>
</div>
</div>
@code {
public TransferWizardModel myModel = new TransferWizardModel();
public List<HeroSliderItem> sliders = new List<HeroSliderItem>
{
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"
},
};
public List<string> TransferIgnorList = new List<string>
{
"Id",
"UserId",
"ProductId",
"PaymentId",
"TripDate",
"FirstName",
"LastName",
"UserProductMappingId",
"UserProductToCarId",
"ReferralId",
"Price"
};
/*protected override void OnAfterRender(bool isFirst)
{
message = " Target destination is " + slider.SliderElementId.ToString();
}*/
public async Task SubmitForm(object Result)
{
TransferWizardModel 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)
{
resModel.UserId = user.Id;
//user exists already
if(_sessionService.User != null)
{
if(_sessionService.User.UserId == user.Id)
{
//I have ordered for myself
resModel.ReferralId = null;
}
else
{
//if I am logged in and different user I become referrer (if no referrer already)
var transferUserDetail = await UserDataService.GetUserDetailByIdAsync(user.Id);
var userDetail = await UserDataService.GetUserDetailByIdAsync(_sessionService.User.UserId);
if (transferUserDetail.UserDto.RefferalId != null)
{
//user has aready a referrer so we use that
resModel.ReferralId = transferUserDetail.UserDto.RefferalId;
}
else
{
//user has no referrer so I am the referrer
resModel.ReferralId = userDetail.UserDto.RefferalId;
}
}
}
}
else
{
//create a guest user and set referralId
var registration = new RegistrationModel();
var password = AcCharsGenerator.NewPassword(AcConst.MinPasswordLength, 16);
registration.Email = resModel.EmailAddress;
registration.PhoneNumber = resModel.PhoneNumber;
registration.Password = password;
//get list with one member!
var createResult = await UserDataService.CreateGuestUser(registration);
if (createResult.isSuccess)
{
if (createResult.user != null)
{
if (_sessionService.User != null)
{
//if I am logged in user I become referrer
var userDetail = await UserDataService.GetUserDetailByIdAsync(_sessionService.User.UserId);
var createdUserDetail = await UserDataService.GetUserDetailByIdAsync(createResult.user.Id);
if(createdUserDetail != null)
{
createdUserDetail.UserDto.RefferalId = userDetail.UserDto.RefferalId;
var updatedNewUser = await _adminSignalRClient.PostDataAsync<UserModelDtoDetail>(SignalRTags.UpdateUserModelDtoDetail, userDetail);
if (updatedNewUser != null)
{
//referral set
}
else
{
//something wrong
}
}
resModel.ReferralId = userDetail.UserDto.RefferalId;
}
resModel.UserId = createResult.user.Id;
}
else
{
//some error handling
}
}
}
var transfer = await WizardProcessor.ProcessWizardAsync<TransferWizardModel>(Result.GetType(), Result);
BrowserConsoleLogWriter.Info($"Submitted nested form: {Result.GetType().FullName}");
navManager.NavigateTo($"/transfer2/{resModel.Id}");
}
}