improvements, fixes, etc...

This commit is contained in:
Loretta 2024-08-30 16:29:39 +02:00
parent eeeea7b037
commit 5355bd09cd
13 changed files with 147 additions and 164 deletions

View File

@ -148,7 +148,7 @@ namespace TIAM.Database.DataLayers.Admins
#region TransferDestination
public List<TransferDestination> GetTransferDestinations() => Session(ctx => ctx.GetTransferDestinations().ToList());
public Task<List<TransferDestination>> GetTransferDestinationsAsync() => SessionAsync(ctx => ctx.GetTransferDestinations().ToList());
public TransferDestination? GetTransferDestinationById(Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationById(transferDestinationId));
public Task<TransferDestination?> GetTransferDestinationByIdAsync(Guid transferDestinationId) => SessionAsync(ctx => ctx.GetTransferDestinationById(transferDestinationId));
public string? GetTransferDestinationJsonById(Guid transferDestinationId) => Session(ctx => ctx.GetTransferDestinationById(transferDestinationId)?.ToJson());

View File

@ -1,5 +1,8 @@
namespace TIAM.Services.Interfaces;
using TIAM.Entities.Transfers;
public interface ITransferApiControllerClient : IUserApiControllerCommon
namespace TIAM.Services.Interfaces;
public interface ITransferApiControllerClient : ITransferApiControllerCommon
{
Task GetTransferDestinationsInto(List<TransferDestination> intoDestinationList, Action? callback = null);
}

View File

@ -26,7 +26,7 @@ public interface ITransferApiControllerCommon
#endregion Drivers
#region TransferDestination
public List<TransferDestination> GetTransferDestinations();
public Task<List<TransferDestination>> GetTransferDestinations();
public Task<TransferDestination?> GetTransferDestinationById(Guid transferDestinationId);
public Task<TransferDestination?> CreateTransferDestination(TransferDestination transferDestination);
public Task<TransferDestination?> UpdateTransferDestination(TransferDestination transferDestination);

View File

@ -1,4 +1,5 @@
@using BlazorAnimation
@using AyCode.Core.Helpers
@using BlazorAnimation
@using TIAM.Core.Enums
@using TIAM.Entities.Addresses
@using TIAM.Entities.Products
@ -42,7 +43,7 @@
<div class="row">
<div class="col-12 col-md-3">
<h4>Information</h4>
@RenderDetailsItem("fa-solid fa-user", "Contact Name", productProfile.FullName)
@RenderDetailsItem("fa-solid fa-user", "Contact Name", _productProfile.FullName)
@RenderDetailsItem("fa-solid fa-circle-info", "Description", Context.Description)
</div>
@ -79,16 +80,16 @@
</div>
<div class="col-4">
@{
if (!isAddressTransferDestination)
if (!_isAddressTransferDestination)
{
<DxButton Click="() => SaveAsDestination(productProfile.Address, Context)" Text="Save as destination" RenderStyle="ButtonRenderStyle.Primary" />
<DxButton Click="() => SaveAsDestination(_productProfile.Address, Context)" Text="Save as destination" RenderStyle="ButtonRenderStyle.Primary" />
}
}
</div>
<div class="col-4"></div>
</div>
</div>
<p>@msg</p>
<p>@_msg</p>
</div>
</div>
@ -120,11 +121,11 @@
AccordionExpandMode ExpandMode { get; set; } = AccordionExpandMode.SingleOrNone;
AccordionExpandCollapseAction ExpandCollapseAction { get; set; } = AccordionExpandCollapseAction.HeaderClick;
private Profile productProfile = new Profile();
private List<TransferDestination> destinations = new List<TransferDestination>();
string msg;
private bool isSaveActive = false;
private bool isAddressTransferDestination = false;
private Profile _productProfile = new Profile();
private readonly List<TransferDestination> _destinations = [];
string _msg;
private bool _isSaveActive = false;
private bool _isAddressTransferDestination = false;
private async Task CopyUrl(string url)
{
@ -139,19 +140,20 @@
protected override async Task OnInitializedAsync()
{
var productOwner = await AdminSignalRClient.GetByIdAsync<List<Company>>(SignalRTags.GetCompaniesById, Context.ServiceProviderId);
var ProductProfiles = await AdminSignalRClient.GetByIdAsync<List<Profile>>(SignalRTags.GetProfileById, Context.ProfileId);
await AdminSignalRClient.GetAllIntoAsync<TransferDestination>(destinations, SignalRTags.GetAllTransferDestinations);
var productProfiles = await AdminSignalRClient.GetByIdAsync<List<Profile>>(SignalRTags.GetProfileById, Context.ProfileId);
if (productOwner != null)
{
ImageSource = await ServiceProviderDataService.GetQRCodeByProductIdAndOwnerAffiliateIdAsync(new Guid[] { productOwner[0].AffiliateId, Context.Id });
}
if (ProductProfiles != null)
{
productProfile = ProductProfiles[0];
var AddressId = productProfile.AddressId;
isAddressTransferDestination = CheckDestinations(AddressId);
ImageSource = await ServiceProviderDataService.GetQRCodeByProductIdAndOwnerAffiliateIdAsync([productOwner[0].AffiliateId, Context.Id]);
}
if (productProfiles != null)
{
_productProfile = productProfiles[0];
_isAddressTransferDestination = CheckDestinations(_productProfile.AddressId);
}
AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget();
await base.OnInitializedAsync();
}
@ -175,28 +177,15 @@
private bool CheckDestinations(Guid addressId)
{
if (destinations != null)
{
if (destinations.Any(d => d.AddressId == addressId))
{
return true;
}
else
{
return false;
}
}
else
{
return false;
}
return _destinations.Any(d => d.AddressId == addressId);
}
private async Task SaveAsDestination(Address address, Product product)
{
TransferDestination transferDestination = new TransferDestination();
var transferDestination = new TransferDestination();
transferDestination.Id = Guid.NewGuid();
transferDestination.Name = product.Name;
if (!string.IsNullOrEmpty(product.Profile.Description))
{
transferDestination.Description = product.Profile.Description;
@ -205,8 +194,10 @@
{
transferDestination.Description = "No description available";
}
transferDestination.AddressId = address.Id;
transferDestination.AddressString = address.AddressText;
var result = await AdminSignalRClient.PostDataAsync<TransferDestination>(SignalRTags.CreateTransferDestination, transferDestination);
await InvokeAsync(StateHasChanged);
}

View File

@ -143,7 +143,7 @@
[Parameter] public GridDetailExpandButtonDisplayMode DetailExpandButtonDisplayMode { get; set; } = GridDetailExpandButtonDisplayMode.Never;
[Parameter] public bool ShowManageButtons { get; set; } = false;
private List<TransferDestination> destinations = [];
private List<TransferDestination> _destinations = [];
private ProductDetailGrid _productGrid = null!;
private LoggerClient<ProductDetailGridComponent> _logger = null!;
@ -157,7 +157,8 @@
protected override void OnInitialized()
{
_logger = new LoggerClient<ProductDetailGridComponent>(LogWriters.ToArray());
AdminSignalRClient.GetAllIntoAsync<TransferDestination>(destinations, SignalRTags.GetAllTransferDestinations).Forget();
AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget();
//DataSource = new List<Address>();
}
@ -166,9 +167,9 @@
{
if(destinations!=null)
if(_destinations!=null)
{
if (destinations.Any(d => d.AddressId == addressId))
if (_destinations.Any(d => d.AddressId == addressId))
{
return true;
}

View File

@ -144,7 +144,7 @@
[Parameter] public EventCallback<GridEditModelSavingEventArgs> OnGridEditModelSaving { get; set; }
[Parameter] public GridDetailExpandButtonDisplayMode DetailExpandButtonDisplayMode { get; set; } = GridDetailExpandButtonDisplayMode.Never;
private List<TransferDestination> destinations = [];
private List<TransferDestination> _destinations = [];
private ProductGrid _productGrid = null!;
private LoggerClient<ProductGridComponent> _logger = null!;
@ -159,16 +159,17 @@
protected override void OnInitialized()
{
_logger = new LoggerClient<ProductGridComponent>(LogWriters.ToArray());
AdminSignalRClient.GetAllIntoAsync<TransferDestination>(destinations, SignalRTags.GetAllTransferDestinations).Forget();
AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget();
}
private bool CheckDestinations(Guid addressId)
{
if (destinations != null)
if (_destinations != null)
{
if (destinations.Any(d => d.AddressId == addressId))
if (_destinations.Any(d => d.AddressId == addressId))
{
return true;
}

View File

@ -36,10 +36,10 @@
<DxGridDataColumn FieldName="ProductId" Caption="ServiceId">
<CellEditTemplate>
@{
var TransferDestinationToProductEditModel = (TransferDestinationToProduct)context.EditModel;
var transferDestinationToProductEditModel = (TransferDestinationToProduct)context.EditModel;
}
<DxComboBox Data="@_products" TextFieldName="Name" ValueFieldName="Id" @bind-Value="TransferDestinationToProductEditModel.ProductId" ReadOnly="@ProductIdReadOnly"
<DxComboBox Data="@_products" TextFieldName="Name" ValueFieldName="Id" @bind-Value="transferDestinationToProductEditModel.ProductId" ReadOnly="@_productIdReadOnly"
SearchFilterCondition="ListSearchFilterCondition.Contains" SearchMode="ListSearchMode.AutoSearch">
</DxComboBox>
</CellEditTemplate>
@ -47,10 +47,10 @@
<DxGridDataColumn FieldName="TransferDestinationId">
<CellEditTemplate>
@{
var TransferDestinationToProductEditModel = (TransferDestinationToProduct)context.EditModel;
var transferDestinationToProductEditModel = (TransferDestinationToProduct)context.EditModel;
}
<DxComboBox Data="@_transferDestinations" TextFieldName="Name" ValueFieldName="Id" @bind-Value="TransferDestinationToProductEditModel.TransferDestinationId" ReadOnly="@DestinationIdReadOnly"
<DxComboBox Data="@_destinations" TextFieldName="Name" ValueFieldName="Id" @bind-Value="transferDestinationToProductEditModel.TransferDestinationId" ReadOnly="@_destinationIdReadOnly"
SearchFilterCondition="ListSearchFilterCondition.Contains" SearchMode="ListSearchMode.AutoSearch">
</DxComboBox>
</CellEditTemplate>
@ -111,11 +111,11 @@
[Parameter] public bool IsProductIdReadonly { get; set; } = false;
[Parameter] public bool IsDestinationIdReadonly { get; set; } = false;
private bool ProductIdReadOnly = false;
private bool DestinationIdReadOnly = false;
private bool _productIdReadOnly = false;
private bool _destinationIdReadOnly = false;
//private bool? _isNewState = null;
private List<TransferDestination> _transferDestinations = [];
private List<TransferDestination> _destinations = [];
private List<Product> _products = [];
private LoggerClient<TransferDestinationToProductGridComponent> _logger = null!;
@ -123,8 +123,10 @@
protected override void OnInitialized()
{
_logger = new LoggerClient<TransferDestinationToProductGridComponent>(LogWriters.ToArray());
AdminSignalRClient.GetAllIntoAsync(_transferDestinations, SignalRTags.GetAllTransferDestinations).Forget();
AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget();
AdminSignalRClient.GetAllIntoAsync(_products, SignalRTags.GetAllProducts).Forget();
base.OnInitialized();
}
@ -132,9 +134,9 @@
{
if (!e.IsNew)
{
DestinationIdReadOnly = true;
_destinationIdReadOnly = true;
ProductIdReadOnly = true;
_productIdReadOnly = true;
}
else
@ -143,12 +145,12 @@
{
((TransferDestinationToProduct)(e.EditModel)).TransferDestinationId = (Guid)ContextIds[0];
}
DestinationIdReadOnly = IsDestinationIdReadonly;
_destinationIdReadOnly = IsDestinationIdReadonly;
if (IsProductIdReadonly)
{
((TransferDestinationToProduct)(e.EditModel)).ProductId = (Guid)ContextIds[0];
}
ProductIdReadOnly = IsProductIdReadonly;
_productIdReadOnly = IsProductIdReadonly;
}
if (!e.IsNew) return;
@ -157,14 +159,14 @@
private void OnGridEditModelSaving(GridEditModelSavingEventArgs e)
{
DestinationIdReadOnly = false;
ProductIdReadOnly = false;
_destinationIdReadOnly = false;
_productIdReadOnly = false;
}
private void EditCanceling(GridEditCancelingEventArgs e)
{
DestinationIdReadOnly = false;
ProductIdReadOnly = false;
_destinationIdReadOnly = false;
_productIdReadOnly = false;
}

View File

@ -47,7 +47,7 @@
var TransferDestinationToProductEditModel = (TransferDestinationToProduct)context.EditModel;
}
<DxComboBox Data="@_transferDestinations" TextFieldName="Name" ValueFieldName="Id" @bind-Value="TransferDestinationToProductEditModel.TransferDestinationId" ReadOnly="@(!_isNewState!.Value)"
<DxComboBox Data="@_destinations" TextFieldName="Name" ValueFieldName="Id" @bind-Value="TransferDestinationToProductEditModel.TransferDestinationId" ReadOnly="@(!_isNewState!.Value)"
SearchFilterCondition="ListSearchFilterCondition.Contains" SearchMode="ListSearchMode.AutoSearch">
</DxComboBox>
</CellEditTemplate>
@ -101,15 +101,17 @@
private LoggerClient<TransferDestinationToProductGridComponent> _logger = null!;
private bool? _isNewState = null;
private List<TransferDestination> _transferDestinations = [];
private List<TransferDestination> _destinations = [];
private List<Product> _products = [];
protected override async Task OnInitializedAsync()
{
_logger = new LoggerClient<TransferDestinationToProductGridComponent>(LogWriters.ToArray());
AdminSignalRClient.GetAllIntoAsync(_transferDestinations, SignalRTags.GetAllTransferDestinations).Forget();
AdminSignalRClient.GetTransferDestinationsInto(_destinations).Forget();
AdminSignalRClient.GetAllIntoAsync(_products, SignalRTags.GetAllProducts).Forget();
await base.OnInitializedAsync();
}

View File

@ -25,7 +25,7 @@
<DxTabPage Text="Preset addresses">
<DxComboBox Data="@Data"
<DxComboBox Data="@_destinations"
CssClass="p-3"
InputCssClass="@CssClass"
@bind-Value="@SelectedDestination"
@ -56,7 +56,7 @@
</DxTabPage>
</DxTabs>
<p>Selected address: @Address</p>
<p>Selected address: @_address</p>
@* <p class="demo-text cw-480 mt-3">
@ -81,18 +81,16 @@
[Parameter] public Guid? ProductId { get; set; }
public List<TransferDestination> Destinations = [];
public DxTextBox TextField;
TransferDestination Result;
ILogger _logger;
List<TransferDestination> Data { get; set; } = [];
readonly List<TransferDestination> _destinations = [];
private string Address { get; set; }
private string ValidationMessage { get; set; }
private string _address = string.Empty;
private string _validationMessage = string.Empty;
private TransferDestination? _selectedDestination;
public TransferDestination? SelectedDestination
@ -129,25 +127,19 @@
}
}
_adminSignalRClient.GetAllAsync<List<TransferDestination>>(SignalRTags.GetAllTransferDestinations, response =>
_adminSignalRClient.GetTransferDestinationsInto(_destinations, () =>
{
Data.Clear();
SelectedDestination = null;
if (response.Status != SignalResponseStatus.Success || response.ResponseData == null)
{
_logger.Error($"OnInitializedAsync->GetAllTransferDestinations; response.Status: {response.Status}");
return Task.CompletedTask;
}
Data.AddRange(response.ResponseData);
_logger.Debug($"TransferDestinations Data length: {Data.Count}");
SelectedDestination = productAddressId.IsNullOrEmpty() ? Data.FirstOrDefault() : Data.FirstOrDefault(x => x.AddressId == productAddressId);
return Task.CompletedTask;
SelectedDestination = productAddressId.IsNullOrEmpty() ? _destinations.FirstOrDefault() : _destinations.FirstOrDefault(x => x.AddressId == productAddressId);
}).Forget();
// _adminSignalRClient.GetAllIntoAsync(_destinations, SignalRTags.GetAllTransferDestinations, null, resultData =>
// {
// if (resultData == null) SelectedDestination = null;
// else SelectedDestination = productAddressId.IsNullOrEmpty() ? _destinations.FirstOrDefault() : _destinations.FirstOrDefault(x => x.AddressId == productAddressId);
// return Task.CompletedTask;
// }).Forget();
//await _adminSignalRClient.GetAllIntoAsync(Data, SignalRTags.GetAllTransferDestinations);
}
@ -170,13 +162,13 @@
public void OnSelectedAddressChanged(string address)
{
Address = address;
_address = address;
OnSliderChanged.InvokeAsync(address);
}
public void SetNewDestination(string address)
{
Address = address;
_address = address;
OnSliderChanged.InvokeAsync(address);
}

View File

@ -497,64 +497,69 @@ namespace TIAMWebApp.Server.Controllers
[Tags("In-Progress", "Product")]
public async Task<IActionResult> GetQRCodeByProductId([FromBody] Guid productId)
{
_logger.Info(@"GetQRCode called");
_logger.Info($"GetQRCode called; productId: {productId}");
return BadRequest("OBSOLATE");
if (productId.IsNullOrEmpty()) return BadRequest("Product is required");
if (productId == Guid.Empty)
{
return BadRequest("Product is required");
}
else
{
//var result = _serviceProviderDal.GetQRCodeAsync(productId);
var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode($"https://touriam.com/{productId}", QRCodeGenerator.ECCLevel.Q);
var qrCode = new QRCode(qrCodeData);
//Bitmap qrCodeImage = qrCode.GetGraphic(20);
//var rootpath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "assets");
var rootpath = System.IO.Path.Combine(env.WebRootPath, "assets");
var rootpath = Path.Combine(env.WebRootPath, "assets");
var qrCodeImage = qrCode.GetGraphic(20, Color.DarkMagenta, Color.White, (Bitmap)Bitmap.FromFile(rootpath + "/myimage.png"));
_logger.Info($@"qrCodeLogo: {rootpath}/myimage.png");
var ms = new MemoryStream();
_logger.Debug($@"qrCodeLogo: {rootpath}/myimage.png");
byte[] byteImage;
using (var ms = new MemoryStream())
{
qrCodeImage.Save(ms, ImageFormat.Jpeg);
var byteImage = ms.ToArray();
byteImage = ms.ToArray();
}
var sigBase64 = Convert.ToBase64String(byteImage); // Get Base64
return Ok(sigBase64);
}
}
[AllowAnonymous]
[HttpPost]
[Route(APIUrls.GetQrCodeByProductIdAndOwnerAffiliateIdRouteName)]
public async Task<IActionResult> GetQrCodeByProductIdAndOwnerAffiliateId([FromBody] Guid[] Ids)
public async Task<IActionResult> GetQrCodeByProductIdAndOwnerAffiliateId([FromBody] Guid[] ids)
{
_logger.Info(@"GetQRCode called");
if (Ids[0].IsNullOrEmpty() || Ids[1].IsNullOrEmpty())
if (ids[0].IsNullOrEmpty() || ids[1].IsNullOrEmpty())
{
return BadRequest("Product is required");
}
else
{
var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode($"{Setting.BaseUrl}/public/transfer/{Ids[0]}/{Ids[1]}", QRCodeGenerator.ECCLevel.Q);
var qrCodeData = qrGenerator.CreateQrCode($"{Setting.BaseUrl}/public/transfer/{ids[0]}/{ids[1]}", QRCodeGenerator.ECCLevel.Q);
var qrCode = new QRCode(qrCodeData);
//Bitmap qrCodeImage = qrCode.GetGraphic(20);
//var rootpath = System.IO.Path.Combine(System.IO.Directory.GetCurrentDirectory(), "assets");
var rootpath = System.IO.Path.Combine(env.WebRootPath, "assets");
var rootpath = Path.Combine(env.WebRootPath, "assets");
var qrCodeImage = qrCode.GetGraphic(20, Color.DarkMagenta, Color.White, (Bitmap)Bitmap.FromFile(rootpath + "/myimage.png"));
_logger.Info($@"qrCodeLogo: {rootpath}/myimage.png");
var ms = new MemoryStream();
byte[] byteImage;
using (var ms = new MemoryStream())
{
qrCodeImage.Save(ms, ImageFormat.Jpeg);
var byteImage = ms.ToArray();
byteImage = ms.ToArray();
}
var sigBase64 = Convert.ToBase64String(byteImage); // Get Base64
return Ok(sigBase64);
}
}
}
}

View File

@ -77,9 +77,9 @@ namespace TIAMWebApp.Server.Controllers
[HttpGet]
[Route(APIUrls.GetTransferDestinationsRouteName)]
[SignalR(SignalRTags.GetAllTransferDestinations)]
public List<TransferDestination> GetTransferDestinations()
public async Task<List<TransferDestination>> GetTransferDestinations()
{
return _adminDal.GetTransferDestinations();
return await _adminDal.GetTransferDestinationsAsync();
}
//[Authorize]

View File

@ -2,7 +2,6 @@
using AyCode.Core.Consts;
using AyCode.Core.Helpers;
using AyCode.Services.Loggers;
using AyCode.Services.SignalRs;
using TIAM.Entities.Drivers;
using TIAM.Entities.Transfers;
using TIAM.Entities.Users;
@ -58,19 +57,7 @@ namespace TIAMWebApp.Shared.Application.Services
{
Logger.Detail($"GetAllCarsByProductIdAsync client called; productId: {productId}");
//TODO: AdminSignalRClient.GetAllIntoAsync<Car>(_cars, SignalRTags.GetAllCarsByProductId, [productId]) - J.
return GetAllAsync<List<Car>>(SignalRTags.GetAllCarsByProductId, response =>
{
intoCars.Clear();
if (response is { Status: SignalResponseStatus.Success, ResponseData: not null })
{
intoCars.AddRange(response.ResponseData);
}
callback?.Invoke();
return Task.CompletedTask;
}, [productId]);
return GetAllIntoAsync(intoCars, SignalRTags.GetAllCarsByProductId, [productId], callback);
}
#endregion ICompanyApiController
@ -137,10 +124,12 @@ namespace TIAMWebApp.Shared.Application.Services
throw new NotImplementedException();
}
public List<TransferDestination> GetTransferDestinations()
{
throw new NotImplementedException();
}
public async Task<List<TransferDestination>> GetTransferDestinations()
=> await GetAllAsync<List<TransferDestination>>(SignalRTags.GetAllTransferDestinations) ?? [];
public Task GetTransferDestinationsInto(List<TransferDestination> intoDestinationList, Action? callback = null)
=> GetAllIntoAsync(intoDestinationList, SignalRTags.GetAllTransferDestinations, null, callback);
public async Task<TransferDestination?> GetTransferDestinationById(Guid transferDestinationId)
{

View File

@ -199,8 +199,6 @@ namespace TIAMWebApp.Shared.Application.Services
public async Task<string> GetQRCodeByProductIdAsync(Guid productId)
{
var url = APIUrls.GetQrCodeByProductId;
var response = await http.PostAsJsonAsync(url, productId);
if (response.IsSuccessStatusCode)
@ -215,11 +213,10 @@ namespace TIAMWebApp.Shared.Application.Services
}
}
public async Task<string> GetQRCodeByProductIdAndOwnerAffiliateIdAsync(Guid[] Ids)
public async Task<string> GetQRCodeByProductIdAndOwnerAffiliateIdAsync(Guid[] ids)
{
var url = APIUrls.GetQrCodeByProductIdAndOwnerAffiliateId;
var response = await http.PostAsJsonAsync(url, Ids);
var response = await http.PostAsJsonAsync(url, ids);
if (response.IsSuccessStatusCode)
{
var result = await response.Content.ReadAsStringAsync();