WizardProcessor, small fixes

This commit is contained in:
Adam 2023-12-21 15:08:38 +01:00
parent 08b347e85b
commit 52572bd4b5
22 changed files with 262 additions and 88 deletions

View File

@ -49,6 +49,7 @@ namespace TIAMMobileApp
builder.Services.AddScoped<ISecureStorageHandler, SecureStorageHandler>();
builder.Services.AddScoped<ISessionService, SessionServiceMobile>();
builder.Services.AddSingleton<IComponentUpdateService, ComponentUpdateServiceMobile>();
builder.Services.AddScoped<IWizardProcessor, WizardProcessor>();
builder.Services.AddSingleton(x => new ResourceManager("TIAMWebApp.Shared.Application.Resources", typeof(Main).Assembly));
return builder.Build();
}

View File

@ -3,6 +3,7 @@ using TIAM.Entities.TransferDestinations;
using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide;
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
namespace TIAMMobileApp.Services
{
@ -16,6 +17,13 @@ namespace TIAMMobileApp.Services
this.http = http;
}
public async Task<bool> CreateTransferDestination(TransferDestinationWizardModel model)
{
var url = $"{Setting.BaseUrl}/{APIUrls.CreateTransferDestination}";
var response = await http.PostAsJsonAsync(url, model);
return response.IsSuccessStatusCode;
}
/// <summary>
/// calls the TransferDataAPI to get the list of destinations
public async Task<TransferDestination[]?> GetDestinationsAsync()
@ -24,6 +32,11 @@ namespace TIAMMobileApp.Services
return await http.GetFromJsonAsync<TransferDestination[]>(url);
}
public Task<TransferDestination> GetTransferDestinationbyAddressAsync(string destinationId)
{
throw new NotImplementedException();
}
public async Task<TransferDestination?> GetTransferDestinationbyCoordinatesAsync(string destinationId)
{
var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinationByCoordinates}";

View File

@ -0,0 +1,48 @@
using TIAM.Entities.TransferDestinations;
using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
namespace TIAMMobileApp.Services
{
public class WizardProcessor : IWizardProcessor
{
public ITransferDataService transferDataService { get; set; }
public IUserDataService userDataService { get; set; }
public WizardProcessor(ITransferDataService transferDataService, IUserDataService userDataService)
{
this.transferDataService = transferDataService;
this.userDataService = userDataService;
}
public async Task<string> ProcessWizardAsync(Type type, object data)
{
switch (type.Name)
{
case "TransferDestinationWizardModel":
var result = await transferDataService.CreateTransferDestination((TransferDestinationWizardModel)data);
if (result)
return "Success";
else
return "Failed";
case "ServiceProvider":
default:
return "Not implemented";
}
}
public Task<string> ValidateWizardStepAsync(Type type, string fieldName, object fieldValue)
{
//if type is TransferDestination, then validate the field name
//if (type.Name == "TransferDestination")
// return await TransferDataService.ValidateDestination(fieldName);
//if type is ServiceProvider, then validate the field name
//if type is something else, then throw an exception
throw new NotImplementedException();
}
}
}

View File

@ -95,5 +95,14 @@ namespace TIAM.Resources {
return ResourceManager.GetString("Test", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Wizard.
/// </summary>
public static string Wizard {
get {
return ResourceManager.GetString("Wizard", resourceCulture);
}
}
}
}

View File

@ -129,4 +129,7 @@
<data name="Test" xml:space="preserve">
<value>Müxik!</value>
</data>
<data name="Wizard" xml:space="preserve">
<value>Varázsló</value>
</data>
</root>

View File

@ -129,4 +129,7 @@
<data name="Test" xml:space="preserve">
<value>This works!</value>
</data>
<data name="Wizard" xml:space="preserve">
<value>Wizard</value>
</data>
</root>

View File

@ -1,8 +1,8 @@
@using System.Linq.Expressions
@using System.ComponentModel.DataAnnotations
@inject IStringLocalizer<TIAM.Resources.TIAMResources> Localizer
<h2>Edit Form</h2>
<div class="wrapper">
<div class="card cw-480">
<EditForm Model="@Data"
@ -11,9 +11,9 @@
Context="EditFormContext">
<DataAnnotationsValidator />
<div class="card-header text-center py-3">
<h4>Register with DevExpress</h4>
<h4>@localizer.GetString(TitleResourceString)</h4>
<p class="tm-8 mb-0 fw-normal fs-825">
Create a new account to see it in action
Sibtitle here
</p>
</div>
<div class="card-body">
@ -24,7 +24,7 @@
</div>
<p class="tm-8 cw-480 mt-2">
<h3> @Localizer.GetString("DestinationName")</h3>
<h3> @localizer.GetString("DestinationName")</h3>
@_formSubmitResult
</p>

View File

@ -9,6 +9,9 @@ using TIAMWebApp.Shared.Application.Utility;
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
using TIAMWebApp.Shared.Application.Models.PageModels;
using DevExpress.Pdf.Native.BouncyCastle.Asn1.X509.Qualified;
using Microsoft.Extensions.Localization;
using TIAM.Resources;
using TIAMWebApp.Shared.Application.Interfaces;
namespace TIAMSharedUI.Pages.Components
@ -18,12 +21,20 @@ namespace TIAMSharedUI.Pages.Components
[Inject]
public required LogToBrowserConsole LogToBrowserConsole { get; set; }
[Inject]
IStringLocalizer<TIAMResources> localizer { get; set; }
[Inject]
public IWizardProcessor WizardProcessor { get; set; }
public Dictionary<int, Guid> FormSteps { get; set; } = new Dictionary<int, Guid>();
public int CurrentStep { get; set; } = 0;
//TestUserData Data { get; set; } = new TestUserData();
[Parameter]
public string TitleResourceString { get; set; } = "Wizard";
[Parameter]
public object Data { get; set; } = new object();
@ -31,7 +42,7 @@ namespace TIAMSharedUI.Pages.Components
public EventCallback<object> OnSubmit { get; set; }
string _phoneMask = "(999)000-0000";
string _formSubmitResult = "";
private string _spinnerClass = "";
@ -39,6 +50,7 @@ namespace TIAMSharedUI.Pages.Components
{
_spinnerClass = "spinner-border spinner-border-sm";
await Task.Delay(500);
await WizardProcessor.ProcessWizardAsync(Data.GetType(), Data);
_formSubmitResult = "You have been registred successully.";
_spinnerClass = "";
@ -80,10 +92,10 @@ namespace TIAMSharedUI.Pages.Components
{
//if (property.Name == "Id" || property.Name == "Latitude" || property.Name == "Longitude" || property.Name == "Created" || property.Name == "Modified")
if (property.Name == "Id" || property.Name == "Created" || property.Name == "Modified")
{
continue;
}
//if (property.Name == "Id" || property.Name == "Created" || property.Name == "Modified")
//{
// continue;
//}
Guid _stepID = Guid.Empty;
@ -149,7 +161,7 @@ namespace TIAMSharedUI.Pages.Components
{
editor.OpenComponent<DxMaskedInput<string>>(j++);
editor.AddAttribute(j++, "Value", property.GetValue(Data));
editor.AddAttribute(j++, "Mask", _phoneMask);
editor.AddAttribute(j++, "Mask", TIAMRegularExpressions.PhoneNumberMask);
editor.AddAttribute(j++, "ValueExpression", lambda);
editor.AddAttribute(j++, "ValueChanged", EventCallback.Factory.Create<string>(this, str => { property.SetValue(Data, str); }));
editor.CloseComponent();

View File

@ -1,26 +0,0 @@
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TIAMWebApp.Shared.Application.Models.ClientSide.UI;
namespace TIAMSharedUI.Pages.Components
{
public partial class StepComponent : ComponentBase
{
[Parameter]
public RenderFragment ChildContent { get; set; }
[Parameter]
public ACStepModelBase StepModel { get; set; }
[Parameter]
public EventCallback OnNext { get; set; }
}
}

View File

@ -1,5 +0,0 @@
<h3>StepComponent</h3>
@code {
}

View File

@ -1,18 +0,0 @@
using Microsoft.AspNetCore.Components;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TIAMSharedUI.Pages.Components
{
public partial class StepComponentBase : ComponentBase
{
}
}

View File

@ -1,5 +0,0 @@
<h3>StepComponentBase</h3>
@code {
}

View File

@ -35,7 +35,7 @@ namespace TIAMSharedUI.Pages.User
OrderData = new object[]
{
new {
new {
Date = DateTime.Now.AddDays(3),
Income = "$5",
TransactionId = "POX987532582",

View File

@ -0,0 +1,72 @@
@page "/user/properties"
@using TIAMSharedUI.Shared
@layout AdminLayout
<h3>Properties</h3>
<h4>You have no properties yet...</h4>
<div class="container">
<div class="row">
<div class="card-body card-admin-body py-2 px-4">
<div class="d-flex flex-row mb-4 pb-2">
<DxGrid Data="@OrderData">
<Columns>
<DxGridDataColumn FieldName="Date" DisplayFormat="D" MinWidth="100">
<CellDisplayTemplate>
<a class="d-block text-left" href="transferdetails">@context.Value</a>
</CellDisplayTemplate>
</DxGridDataColumn>
<DxGridDataColumn FieldName="Income" Width="15%" />
<DxGridDataColumn FieldName="TransactionId" Width="15%" />
<DxGridDataColumn FieldName="Status" Width="10%" />
</Columns>
</DxGrid>
</div>
<div class="d-flex flex-row mb-4 pb-2">
<h4> Some <span class="small text-muted"> conclusion </span></h4>
</div>
</div>
</div>
</div>
@code {
object? OrderData { get; set; }
protected override void OnInitialized()
{
base.OnInitialized();
OrderData = new object[]
{
new {
Date = DateTime.Now.AddDays(3),
Income = "$5",
TransactionId = "POX987532582",
Status = "Finished"
},
new {
Date = DateTime.Today.AddDays(-2),
Income = "$5",
TransactionId = "POX645646382",
Status = "Finished"
},
new
{
Date = DateTime.Today.AddDays(-6),
Income = "$8",
TransactionId = "POX645766311",
Status = "Finished"
},
};
}
}

View File

@ -1,8 +0,0 @@
@page "/user/properties"
@using TIAMSharedUI.Shared
@layout AdminLayout
<h3>Properties</h3>
@code {
}

View File

@ -26,6 +26,7 @@ builder.Services.AddBlazoredLocalStorage();
builder.Services.AddSingleton<ISessionService, SessionServiceWeb>();
builder.Services.AddSingleton<IComponentUpdateService, ComponentUpdateServiceWeb>();
builder.Services.AddScoped<IServiceProviderDataService, ServiceProviderDataServiceWeb>();
builder.Services.AddScoped<IWizardProcessor, WizardProcessor>();
//WebSpecific
builder.Services.AddScoped<SessionStorageAccessor>();
builder.Services.AddSingleton(x => new ResourceManager("TIAMWebApp.Client.Resources.MyResources", typeof(Program).Assembly));

View File

@ -3,6 +3,7 @@ using TIAM.Entities.TransferDestinations;
using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide;
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
using TIAMWebApp.Shared.Application.Utility;
namespace TIAMWebApp.Client.Services
@ -37,5 +38,12 @@ namespace TIAMWebApp.Client.Services
var url = $"{Setting.BaseUrl}/{APIUrls.GetTransferDestinationByAddress}";
return await http.GetFromJsonAsync<TransferDestination>(url);
}
public async Task<bool> CreateTransferDestination(TransferDestinationWizardModel model)
{
var url = $"{Setting.BaseUrl}/{APIUrls.CreateTransferDestination}";
var response = await http.PostAsJsonAsync(url, model);
return response.IsSuccessStatusCode;
}
}
}

View File

@ -0,0 +1,48 @@
using TIAM.Entities.TransferDestinations;
using TIAMWebApp.Shared.Application.Interfaces;
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
namespace TIAMWebApp.Client.Services
{
public class WizardProcessor : IWizardProcessor
{
public ITransferDataService transferDataService { get; set; }
public IUserDataService userDataService { get; set; }
public WizardProcessor(ITransferDataService transferDataService, IUserDataService userDataService)
{
this.transferDataService = transferDataService;
this.userDataService = userDataService;
}
public async Task<string> ProcessWizardAsync(Type type, object data)
{
switch (type.Name)
{
case "TransferDestinationWizardModel":
var result = await transferDataService.CreateTransferDestination((TransferDestinationWizardModel)data);
if (result)
return "Success";
else
return "Failed";
case "ServiceProvider":
default:
return "Not implemented";
}
}
public Task<string> ValidateWizardStepAsync(Type type, string fieldName, object fieldValue)
{
//if type is TransferDestination, then validate the field name
//if (type.Name == "TransferDestination")
// return await TransferDataService.ValidateDestination(fieldName);
//if type is ServiceProvider, then validate the field name
//if type is something else, then throw an exception
throw new NotImplementedException();
}
}
}

View File

@ -12,6 +12,7 @@ using TIAM.Database.DbContexts;
using TIAM.Entities.TransferDestinations;
using TIAM.Entities.Users;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
using TIAMWebApp.Shared.Application.Models.PageModels;
namespace TIAMWebApp.Server.Controllers
@ -76,32 +77,29 @@ namespace TIAMWebApp.Server.Controllers
Console.WriteLine("CreateTransferDestination called!");
if (string.IsNullOrEmpty(SerializedTransferDestinationModel.GetRawText()))
{
return BadRequest("SerializedLoginModel is required");
return BadRequest("SerializedTramsferDestinationWizardModel is required");
}
else
{
TransferDestination? transferDestination = JObject.Parse(SerializedTransferDestinationModel.GetRawText()).ToObject<TransferDestination>();
TransferDestinationWizardModel? transferDestinationModel = JObject.Parse(SerializedTransferDestinationModel.GetRawText()).ToObject<TransferDestinationWizardModel>();
if (transferDestination != null)
if (transferDestinationModel != null)
{
var Id = Guid.NewGuid();
string? Name = transferDestination.Name;
string? Description = transferDestination.Description;
double? Latitude = transferDestination.Latitude;
double? Longitude = transferDestination.Longitude;
string? Address = transferDestination.Address;
TransferDestination transferDestination = new TransferDestination(Id, transferDestinationModel.Name, transferDestinationModel.Description, transferDestinationModel.Latitude, transferDestinationModel.Longitude, transferDestinationModel.Address);
if (Id == Guid.Empty || Latitude == null || Longitude == null)
if (string.IsNullOrEmpty(transferDestinationModel.Name) || string.IsNullOrEmpty(transferDestinationModel.Address))
{
return BadRequest("Invalid request");
}
else
{
Console.WriteLine($"TransferDestination to be created: {Id}");
Console.WriteLine($"TransferDestination to be created: {Latitude}");
Console.WriteLine($"TransferDestination to be created: {Longitude}");
Console.WriteLine($"TransferDestination to be created: {Address}");
Console.WriteLine($"TransferDestination to be created: {transferDestination.Latitude}");
Console.WriteLine($"TransferDestination to be created: {transferDestination.Longitude}");
Console.WriteLine($"TransferDestination to be created: {transferDestination.Address}");
//await _transferDestinationDal.Context.TransferDestinations.AddAsync(transferDestination);
await _transferDestinationDal.CreateTransferDestinationAsync(transferDestination);

View File

@ -1,10 +1,14 @@
using TIAM.Entities.TransferDestinations;
using TIAMWebApp.Shared.Application.Models;
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
namespace TIAMWebApp.Shared.Application.Interfaces
{
public interface ITransferDataService
{
Task<TransferDestination[]> GetDestinationsAsync();
Task<TransferDestination?> GetTransferDestinationbyCoordinatesAsync(string destinationId);
Task<TransferDestination?> GetTransferDestinationbyAddressAsync(string destinationId);
Task<bool> CreateTransferDestination(TransferDestinationWizardModel model);
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TIAMWebApp.Shared.Application.Interfaces
{
public interface IWizardProcessor
{
public Task<string> ProcessWizardAsync(Type type, object data);
public Task<string> ValidateWizardStepAsync(Type type, string fieldName, object fieldValue);
}
}

View File

@ -23,6 +23,7 @@ namespace TIAMWebApp.Shared.Application.Models
public const string GetTransferDestinations = "api/TransferDataAPI/GetTransferDestinations";
public const string GetTransferDestinationByCoordinates = "api/TransferDataAPI/GetTransferDestinationByCoordinates";
public const string GetTransferDestinationByAddress = "api/TransferDataAPI/GetTransferDestinationByAddress";
public const string CreateTransferDestination = "api/TransferDataAPI/CreateTransferDestination";
public const string GetServiceProvidersByOwnerId = "api/ServiceProviderAPI/GetServiceProvidersByOwnerId";