194 lines
7.8 KiB
C#
194 lines
7.8 KiB
C#
using DevExpress.Blazor;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels;
|
|
using TIAMWebApp.Shared.Application.Models;
|
|
using TIAMWebApp.Shared.Application.Interfaces;
|
|
using Microsoft.AspNetCore.Components;
|
|
using TIAM.Core.Loggers;
|
|
using TIAMSharedUI.Pages.Components;
|
|
using TIAMWebApp.Shared.Application.Utility;
|
|
|
|
namespace TIAMSharedUI.Pages.User.SysAdmins
|
|
{
|
|
public partial class TransferDestinations
|
|
{
|
|
|
|
IGrid Grid { get; set; }
|
|
//object? TransferData { get; set; }
|
|
|
|
//public TransferDestinationWizardModel TransferDestinationWizardModel = new();
|
|
|
|
bool PopupVisible { get; set; }
|
|
public List<string> IgnoreList = ["ReceiverId"];
|
|
|
|
public MessageWizardModel MessageWizardModel = new();
|
|
|
|
[Inject]
|
|
public ITransferDataService TransferDataService { get; set; }
|
|
|
|
|
|
/*object? TransferData = new TransferDestinationWizardModel[]
|
|
{
|
|
new TransferDestinationWizardModel(Guid.NewGuid(), "Liszt Ferenc Airport", "International airport of Budapest", "1185, Budapest, Liszt Ferenc Repülőtér" ),
|
|
new TransferDestinationWizardModel(Guid.NewGuid(), "Buda Castle", "Historical site in the heart of Budapest", "1014 Budapest, Szent György tér 2" ),
|
|
new TransferDestinationWizardModel(Guid.NewGuid(), "Hungarian National Museum", "Historical site in the heart of Budapest", "1088 Budapest, Múzeum krt. 14-16" ),
|
|
new TransferDestinationWizardModel(Guid.NewGuid(), "Parliament of Hungary", "Historical site in the heart of Budapest", "1055 Budapest, Kossuth Lajos tér 1-3" ),
|
|
new TransferDestinationWizardModel(Guid.NewGuid(), "Heroes square", "Historical site in the heart of Budapest", "1146 Budapest, Hősök tere" ),
|
|
new TransferDestinationWizardModel(Guid.NewGuid(), "Gellert Hill", "Historical site in the heart of Budapest", "1118 Budapest, Gellérthegy" ),
|
|
new TransferDestinationWizardModel(Guid.NewGuid(), "Margaret Island", "Historical site in the heart of Budapest", "1138 Budapest, Margitsziget" ),
|
|
};*/
|
|
|
|
private LoggerClient<TransferDestinations> _logger;
|
|
|
|
private readonly List<TransferDestinationWizardModel> _transferDestinationWizardModels = [];
|
|
|
|
void CancelCreateClick()
|
|
{
|
|
PopupVisible = false;
|
|
}
|
|
|
|
void EulaPopupClosed()
|
|
{
|
|
//cancel clicked
|
|
}
|
|
|
|
void EulaPopupClosing(PopupClosingEventArgs args)
|
|
{
|
|
//myModel = new TransferWizardModel();
|
|
MessageWizardModel = new MessageWizardModel();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
|
|
public async Task SubmitForm(object Result)
|
|
{
|
|
//await WizardProcessor.ProcessWizardAsync(Result.GetType(), Result);
|
|
_logger.Info($"Submitted nested form: {Result.GetType().FullName}");
|
|
}
|
|
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
//if (firstRender)
|
|
// await Grid.StartEditRowAsync(0);
|
|
}
|
|
|
|
void Grid_CustomizeEditModel(GridCustomizeEditModelEventArgs e)
|
|
{
|
|
if (!e.IsNew) return;
|
|
|
|
var newDestination = (TransferDestinationWizardModel)e.EditModel;
|
|
newDestination.Id = Guid.NewGuid().ToString();
|
|
newDestination.Name = "Destination name";
|
|
newDestination.Description = "Type some description here";
|
|
newDestination.AddressString = "The address of the destination";
|
|
}
|
|
|
|
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
async Task Grid_EditModelSaving(GridEditModelSavingEventArgs e)
|
|
{
|
|
var transferDestinationWizardModel = (TransferDestinationWizardModel)e.EditModel;
|
|
|
|
if (e.IsNew)
|
|
{
|
|
await TransferDataService.CreateTransferDestination(TransferDestinationWizardModel.CopyToTransferDestination(transferDestinationWizardModel));
|
|
//await transferDataService.CreateTransferDestination(new TransferDestination
|
|
/*{
|
|
Id = Guid.NewGuid(),
|
|
Name = myModel.Name,
|
|
Description = myModel.Description,
|
|
AddressString = myModel.AddressString,
|
|
Price = myModel.Price,
|
|
PriceType = myModel.PriceType
|
|
});*/
|
|
_logger.Info("New orderData added");
|
|
|
|
//add mymodel to transferData array
|
|
_transferDestinationWizardModels.Add(transferDestinationWizardModel);
|
|
}
|
|
else
|
|
{
|
|
_logger.Info("orderData updated");
|
|
//modify transferData where transferData.Id == e.EditModel.Id
|
|
//get transfer from TransferData by Id
|
|
|
|
//var abg = ((TransferDestinationWizardModel[])TransferDataFromDb).Length;
|
|
|
|
foreach (var transferToModify in _transferDestinationWizardModels)
|
|
{
|
|
if (transferToModify.Id != transferDestinationWizardModel.Id)
|
|
continue;
|
|
|
|
transferToModify.Id = transferDestinationWizardModel.Id;
|
|
transferToModify.Name = transferDestinationWizardModel.Name;
|
|
transferToModify.Description = transferDestinationWizardModel.Description;
|
|
transferToModify.AddressString = transferDestinationWizardModel.AddressString;
|
|
transferToModify.Price = transferDestinationWizardModel.Price;
|
|
transferToModify.PriceType = transferDestinationWizardModel.PriceType;
|
|
|
|
await TransferDataService.UpdateTransferDestination(TransferDestinationWizardModel.CopyToTransferDestination(transferToModify));
|
|
}
|
|
}
|
|
|
|
//TODO: ne a teljes grid-et refresh-eljük, elég lenne csak az adott sort! - J.
|
|
await UpdateDataAsync();
|
|
}
|
|
|
|
async Task Grid_DataItemDeleting(GridDataItemDeletingEventArgs e)
|
|
{
|
|
//remove orderData from orderData array
|
|
_logger.Info("orderData deleted");
|
|
|
|
//var transferDestinationWizardModel = (TransferDestinationWizardModel)e.DataItem;
|
|
//await TransferDataService.CreateTransferDestination(TransferDestinationWizardModel.CopyToTransferDestination(transferDestinationWizardModel));
|
|
//await UpdateDataAsync();
|
|
}
|
|
|
|
async Task UpdateDataAsync()
|
|
{
|
|
//await TransferDataService.GetDestinationsAsync();
|
|
//refresh grid
|
|
|
|
await FillGridDataSource();
|
|
_logger.Info("orderData grid refreshed");
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
base.OnInitialized();
|
|
|
|
_logger = new LoggerClient<TransferDestinations>(LogWriters.ToArray());
|
|
|
|
await FillGridDataSource();
|
|
}
|
|
|
|
private async Task FillGridDataSource()
|
|
{
|
|
var destinations = await TransferDataService.GetDestinationsAsync();
|
|
|
|
foreach (var item in destinations)
|
|
{
|
|
_transferDestinationWizardModels.Add(new TransferDestinationWizardModel(item.Id, item.Name, item.Description, item.AddressString, item.Price, item.Price2, item.Price3, item.Address));
|
|
|
|
_logger.DetailConditional($"_transferDestinationWizardModels add: {item.Name}");
|
|
}
|
|
|
|
_logger.Info($"_transferDestinationWizardModels: {_transferDestinationWizardModels.Count}");
|
|
}
|
|
|
|
void ColumnChooserButton_Click()
|
|
{
|
|
Grid.ShowColumnChooser();
|
|
}
|
|
}
|
|
}
|