@using AyCode.Core.Helpers @using TIAM.Entities.Products @using TIAM.Entities.ServiceProviders @using TIAM.Entities.Transfers @using TIAM.Entities.Drivers @using TIAM.Entities.Users @using TIAM.Models.Dtos.Users @using TIAM.Resources @using TIAM.Services @using TIAMWebApp.Shared.Application.Interfaces @using TIAMWebApp.Shared.Application.Utility @using AyCode.Services.Loggers @using TIAM.Core.Loggers @using Address = TIAM.Entities.Addresses.Address @using Profile = TIAM.Entities.Profiles.Profile @using TIAMSharedUI.Shared.Components.Grids @using TIAMSharedUI.Pages.Components.EditComponents @using TIAMWebApp.Shared.Application.Services @using AyCode.Interfaces.Addresses @using AyCode.Core @using AyCode.Core.Extensions @inject IStringLocalizer Localizer @inject IEnumerable LogWriters @inject AdminSignalRClient AdminSignalRClient; @inject IJSRuntime JsRuntime; @{ //check if has transferdestination var AddressId = ((Product)context.DataItem).Profile.AddressId; var result = CheckDestinations(AddressId); //if not, display button Product product = (Product)context.DataItem; var _url = $"{Setting.BaseUrl}/public/transfer/{product.ServiceProvider.AffiliateId}/{product.Id}"; Copy referral url if (!result) { //

Address:

//

@(((Product)context.DataItem).Profile.Address.AddressText)

} // else // { //

Address: @(((Product)context.DataItem).Profile.Address.AddressText)

// } if (product.ProductType == TIAM.Core.Enums.ProductType.Hotel) { } else if (product.ProductType == TIAM.Core.Enums.ProductType.Transfer) { } }
@{ Product product = (Product)context.DataItem; var _url = $"{Setting.BaseUrl}/public/transfer/{product.ServiceProvider.AffiliateId}/{product.Id}";

Referral link

@_url
Copy URL }
@{ var transfer2 = (Product)editFormContext.EditModel; } @editFormContext.GetEditor("Name") @editFormContext.GetEditor("ProductType") @editFormContext.GetEditor("Price")

@(((Product)editFormContext.EditModel).ServiceProviderId)

@editFormContext.GetEditor("Description")
@code { [Parameter] public Guid? ContextId { get; set; } [Parameter] public IProductsRelation? ParentData { get; set; } = null!; [Parameter] public EventCallback 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 _destinations = []; private ProductDetailGrid _productGrid = null!; private LoggerClient _logger = null!; private async Task CopyUrl(string url) { await JsRuntime.InvokeVoidAsync("copyToClipboard", url); } protected override void OnInitialized() { _logger = new LoggerClient(LogWriters.ToArray()); AdminSignalRClient.GetTransferDestinationsAsync(_destinations).Forget(); //DataSource = new List
(); } private bool CheckDestinations(Guid addressId) { if(_destinations!=null) { if (_destinations.Any(d => d.AddressId == addressId)) { return true; } else { return false; } } else { return false; } } private async Task SaveAsDestination(Address address, Product product) { TransferDestination transferDestination = new TransferDestination(); transferDestination.Id = Guid.NewGuid(); transferDestination.ProductId = product.Id; transferDestination.Name = product.Name; if (!string.IsNullOrEmpty(product.Profile.Description)) { transferDestination.Description = product.Profile.Description; } else { transferDestination.Description = "No description available"; } transferDestination.AddressId = address.Id; transferDestination.AddressString = address.AddressText; var result = await AdminSignalRClient.PostDataAsync(SignalRTags.CreateTransferDestination, transferDestination); _productGrid.Reload(); await InvokeAsync(StateHasChanged); } protected override async Task OnParametersSetAsync() { // if (ParentData != null) // { // productList.AddRange(ParentData.Products); // } // else if (ContextId != null) // { // //_productGrid.ContextIds = new Guid[1]; // //_productGrid.ContextIds[0] = (Guid)ContextId; // var data = await serviceProviderDataService.GetProductByIdAsync((Guid)ContextId); // List result = new List(); // result.Add(data); // _productGrid.DataSource = result; // } // else await base.OnParametersSetAsync(); } private void DataItemChanged(GridDataItemChangedEventArgs args) { _logger.Debug($"Saving: {args.DataItem.Name}, {args.DataItem.ServiceProviderId}"); } public async Task DataItemSaving(GridEditModelSavingEventArgs e) { await OnGridEditModelSaving.InvokeAsync(e); if (e.Cancel) return; var product = ((Product)e.EditModel); if (e.IsNew) { _logger.Debug($"DataItemSaving"); // product.ServiceProviderId = ((Company)ParentData).Id; // var profileId = Guid.NewGuid(); // product.Profile = new Profile(profileId, product.Name); // product.ProfileId = profileId; // var addressId = Guid.NewGuid(); // product.Profile.Address = new Address(addressId); // product.Profile.AddressId = addressId; //((Product)e.EditModel).UserProductMappings.Add(new UserProductMapping(Guid.NewGuid, ParentData.)); } else { } _logger.Debug($"Saving: {product.Name}, {product.ServiceProviderId}"); //var result = serviceProviderDataService.CreateProductAsync((Product)e.EditModel); //_logger.Debug($"saved product: {product.ServiceProviderId}"); } private void DataItemDeleting(GridDataItemDeletingEventArgs obj) { _logger.Debug($"DataItemDeleting"); } void CustomizeEditModel(GridCustomizeEditModelEventArgs e) { if (!e.IsNew) return; var newProduct = (Product)e.EditModel; newProduct.Id = Guid.NewGuid(); newProduct.Name = "Type a name"; newProduct.ServiceProviderId = (Guid)ContextId!; newProduct.Price = 0; newProduct.ProductType = TIAM.Core.Enums.ProductType.Hotel; newProduct.Description = "Type a description"; } }