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 myModel = new TransferDestinationWizardModel(); bool PopupVisible { get; set; } public List ignoreList = new List { "ReceiverId" }; public MessageWizardModel messageWizardModel = new MessageWizardModel(); [Inject] public ITransferDataService transferDataService { get; set; } private LoggerClient _logger; object? TransferDataFromDb = new TransferDestinationWizardModel[] { }; 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) { 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) { if (e.IsNew) { //add new row to grid myModel = (TransferDestinationWizardModel)e.EditModel; //add new orderData to orderData array //await NwindDataService.InsertEmployeeAsync((EditableEmployee)e.EditModel); await transferDataService.CreateTransferDestination(TransferDestinationWizardModel.CopyToTransferDestination(myModel)); //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 TransferDataFromDb = ((TransferDestinationWizardModel[])TransferDataFromDb).Append(myModel).ToArray(); } 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 (TransferDestinationWizardModel[])TransferDataFromDb) { myModel = (TransferDestinationWizardModel)e.EditModel; if (transferToModify.Id == myModel.Id) { transferToModify.Id = myModel.Id; transferToModify.Name = myModel.Name; transferToModify.Description = myModel.Description; transferToModify.AddressString = myModel.AddressString; transferToModify.Price = myModel.Price; transferToModify.PriceType = myModel.PriceType; await transferDataService.UpdateTransferDestination(TransferDestinationWizardModel.CopyToTransferDestination(transferToModify)); } } } //await NwindDataService.UpdateEmployeeAsync((EditableEmployee)e.DataItem, (EditableEmployee)e.EditModel); await UpdateDataAsync(); } async Task Grid_DataItemDeleting(GridDataItemDeletingEventArgs e) { //await NwindDataService.RemoveEmployeeAsync((EditableEmployee)e.DataItem); //remove orderData from orderData array _logger.Info("orderData deleted"); //await UpdateDataAsync(); } async Task UpdateDataAsync() { //DataSource = await NwindDataService.GetEmployeesEditableAsync(); await transferDataService.GetDestinationsAsync(); //refresh grid _logger.Info("orderData grid refreshed"); } protected override async Task OnInitializedAsync() { base.OnInitialized(); _logger = new LoggerClient(LogWriters.ToArray()); var a = await transferDataService.GetDestinationsAsync(); _logger.Info($"TransferDataFromDb: {((TransferDestinationWizardModel[])TransferDataFromDb).Length}"); foreach (var item in a) { //add new transferwizardmodel to transferData array TransferDataFromDb = ((TransferDestinationWizardModel[])TransferDataFromDb).Append( new TransferDestinationWizardModel(item.Id, item.Name, item.Description, item.AddressString, item.Price, item.Price2, item.Price3, item.Address)).ToArray(); _logger.DetailConditional($"TransferDataFromDb: {item.Name}"); } _logger.Info($"TransferDataFromDb: {((TransferDestinationWizardModel[])TransferDataFromDb).Length}"); } void ColumnChooserButton_Click() { Grid.ShowColumnChooser(); } } }