This commit is contained in:
Loretta 2024-08-02 17:58:37 +02:00
commit 24ae96df0c
6 changed files with 229 additions and 23 deletions

View File

@ -0,0 +1,190 @@
@page "/public/transfer/{referralId:guid}/{productId:guid}"
@using AyCode.Core.Consts
@using AyCode.Core.Helpers
@using TIAM.Entities.Products
@using TIAM.Entities.ServiceProviders
@using TIAM.Entities.Transfers
@using TIAM.Services
@using TIAMSharedUI.Pages.Components.EditComponents
@using TIAMSharedUI.Shared
@using AyCode.Services.Loggers
@using TIAMWebApp.Shared.Application.Interfaces;
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
@using TIAMWebApp.Shared.Application.Models.PageModels
@using TIAMWebApp.Shared.Application.Services
@using TIAMWebApp.Shared.Application.Utility
@using AyCode.Core.Extensions
@layout AdminLayout
@inject IPopulationStructureDataProvider DataProvider
@inject ISessionService SessionService
@inject IUserDataService UserDataService
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
@inject AdminSignalRClient _adminSignalRClient
@inject NavigationManager navManager
<PageTitle>Create transfer</PageTitle>
<div class="text-center m-5">
<h1>Create transfer</h1>
<h2 style="font-size:small">Order a new transfer here!</h2>
</div>
<!--We need to check if the user is owner of a swerviceprovider-->
<div class="container-fluid">
<div class="row d-flex justify-content-center">
<div class="col-12 col-md-6">
<h3>Partner:</h3>
<p>@SelectedHotel</p>
<div class="row py-3">
<DynamicEditForm Data="Data" isEditing="true" IgnoreReflection="TransferIgnorList" OnSubmit="SubmitForm"></DynamicEditForm>
</div>
<div class="row py-3">
<DxButton RenderStyle="ButtonRenderStyle.Primary" Click="@Reload" Visible="@isReloadVisible">Reload</DxButton>
</div>
</div>
</div>
</div>
@code {
[Parameter] public Guid referralId { get; set; }
[Parameter] public Guid productId { get; set; }
private LoggerClient<PublicCreateAndManageTransfer> _logger;
private TransferWizardModel Data = new();
private Product SelectedHotel;
public List<string> TransferIgnorList = new List<string>
{
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<PublicCreateAndManageTransfer>(LogWriters.ToArray());
Data = new TransferWizardModel();
base.OnInitialized();
}
protected override async Task OnParametersSetAsync()
{
if(productId.IsNullOrEmpty())
{
var result = await _adminSignalRClient.GetByIdAsync<Product>(SignalRTags.GetCompaniesById, productId);
if (result != null)
{
SelectedHotel = result;
}
else
{
SelectedHotel = null;
}
}
if (!referralId.IsNullOrEmpty())
{
//check if storage has some other referralId already TODO
//if not, store referralId in device for 30 days (?)
//check if user is logged in
if (SessionService.IsAuthenticated)
{
if (SessionService.User != null)
{
if(SessionService.User.UserModelDto.UserDto.RefferalId == null)
{
//update user referralId
}
}
}
}
await base.OnParametersSetAsync();
}
public async Task SubmitForm(object result)
{
var valami = ((TransferWizardModel)result).CopyToTransfer();
valami.Id = Guid.NewGuid();
valami.ProductId = SelectedHotel.Id;
var user = await UserDataService.GetUserByEmailAsync(valami.ContactEmail);
if (user != null && user.Id != Guid.Empty)
{
//user exists already
var userDetail = await UserDataService.GetUserDetailByIdAsync(user.Id);
valami.ReferralId = userDetail.UserDto.RefferalId;
valami.UserId = userDetail.Id;
}
else
{
//create a guest user and set referralId
var registration = new RegistrationModel();
//TODO: Refractor to userDataService
// var random = new Random();
// const string chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
// var password = new string(Enumerable.Repeat(chars, 10)
// .Select(s => s[random.Next(s.Length)]).ToArray());
var password = AcCharsGenerator.NewPassword(AcConst.MinPasswordLength, 16);
registration.Email = valami.ContactEmail;
registration.PhoneNumber = valami.ContactPhone;
registration.Password = password;
//get list with one member!
var productOwner = await _adminSignalRClient.GetByIdAsync<List<Company>>(SignalRTags.GetCompaniesById, SelectedHotel.ServiceProviderId);
registration.ReferralId = productOwner[0].AffiliateId;
var createResult = await UserDataService.CreateGuestUser(registration);
if(createResult.isSuccess)
{
if (createResult.user != null)
{
valami.UserId = createResult.user.Id;
}
}
_logger.Info("New user created added");
}
//valami.ProductId = SessionService.User.UserId; //TODO ProductID!
// await WizardProcessor.ProcessWizardAsync<TransferDestinationWizardModel>(result.GetType(), result);
var saveResult = await _adminSignalRClient.PostDataAsync<Transfer>(SignalRTags.AddTransfer, valami);
_logger.Info($"Submitted form: {result.GetType().FullName}, {valami.ToAddress}, {valami.FromAddress}, {valami.ProductId}");
isReloadVisible = true;
}
public void Reload()
{
Data = new TransferWizardModel();
isReloadVisible = false;
StateHasChanged();
}
}

View File

@ -33,16 +33,18 @@
</div>
<div class="col-9 col-md-4">
<DxTextBox
@bind-Text="@NewPassword"
NullText="New password"
BindValueMode="BindValueMode.OnDelayedInput"
InputDelay="300"
Password="true"
CssClass="form-field"
/>
<DxTextBox @bind-Text="@OldPassword"
NullText="Old password"
Password="true"
CssClass="form-field" />
<DxTextBox @bind-Text="@NewPassword"
NullText="New password"
BindValueMode="BindValueMode.OnDelayedInput"
InputDelay="300"
Password="true"
CssClass="form-field" />
<DxTextBox @bind-Text="@ConfirmNewPassword"
ReadOnly="@PasswordNotSet"
ReadOnly="@PasswordNotSet"
NullText="Confirm new password"
BindValueMode="BindValueMode.OnDelayedInput"
InputDelay="300"
@ -107,7 +109,7 @@
void OnPasswordConfirmed(string password)
{
if(NewPassword == ConfirmNewPassword)
if (NewPassword == ConfirmNewPassword)
{
PasswordNotConfirmed = false;
isSaveActive = true;
@ -131,8 +133,8 @@
if (result != null)
{
msg = $"Password saved";
StateHasChanged();
msg = $"Password saved";
StateHasChanged();
}
else
{

View File

@ -114,7 +114,7 @@
<AddressDetailGridComponent ParentData="resultCompany.Profile" />
</DxTabPage>
<DxTabPage Text="Services">
<ProductDetailGridComponent GetAllTag="SignalRTags.GetProductsByOwnerId" ContextId="@resultCompany.Id" ParentData="@resultCompany" />
<ProductDetailGridComponent GetAllTag="SignalRTags.GetProductsByOwnerId" ShowManageButtons="true" ContextId="@resultCompany.Id" ParentData="@resultCompany" />
</DxTabPage>
</DxTabs>
</div>

View File

@ -69,7 +69,7 @@
<DxTabs>
<DxTabPage Text="Products">
<ProductDetailGridComponent DetailExpandButtonDisplayMode="GridDetailExpandButtonDisplayMode.Auto" ParentData="(Company)context.DataItem" ContextId="((Company)context.DataItem).Id" />
<ProductDetailGridComponent ShowManageButtons="true" DetailExpandButtonDisplayMode="GridDetailExpandButtonDisplayMode.Auto" ParentData="(Company)context.DataItem" ContextId="((Company)context.DataItem).Id" />
</DxTabPage>
</DxTabs>

View File

@ -45,7 +45,7 @@
<DxGridDataColumn FieldName="@nameof(Product.ServiceProvider.Name)" Caption="Company name" />
<DxGridDataColumn Caption=@Localizer.GetString(ResourceKeys.ProductName) FieldName="Name" SortIndex="0"/>
<DxGridDataColumn Caption=@Localizer.GetString(ResourceKeys.ProductType) FieldName="ProductType" Width="130" />
<DxGridDataColumn FieldName="Id" Width="180">
<DxGridDataColumn FieldName="Id" Visible="@ShowManageButtons" Width="180">
<CellDisplayTemplate>
@{
Product product = (Product)context.DataItem;
@ -61,6 +61,19 @@
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn Caption=@Localizer.GetString(ResourceKeys.Price) FieldName="Price" Width="100" />
<DxGridDataColumn Caption="ReferralLink" FieldName="Id" Width="100" >
<CellDisplayTemplate>
@*
/public/transfer/{referralId:guid}/{productId:guid}
*@
@{
Product product = (Product)context.DataItem;
<p>@Setting.BaseUrl/public/transfer/@product.ServiceProvider.AffiliateId/@product.Id</p>
}
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn Caption="Options">
<CellDisplayTemplate>
@{
@ -132,6 +145,7 @@
[Parameter] public EventCallback<GridEditModelSavingEventArgs> OnGridEditModelSaving { get; set; }
[Parameter] public int GetAllTag { get; set; } = SignalRTags.GetProductsByOwnerId;
[Parameter] public GridDetailExpandButtonDisplayMode DetailExpandButtonDisplayMode { get; set; } = GridDetailExpandButtonDisplayMode.Never;
[Parameter] public bool ShowManageButtons { get; set; } = false;
private List<TransferDestination> destinations = [];

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<ExchangeRate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<EURtoHUF>380</EURtoHUF>
<EURtoHUF>390</EURtoHUF>
</ExchangeRate>