235 lines
7.8 KiB
C#
235 lines
7.8 KiB
C#
using AyCode.Services.Loggers;
|
|
using DevExpress.Blazor;
|
|
using Microsoft.AspNetCore.Components;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.Runtime.CompilerServices;
|
|
using AyCode.Utils.Extensions;
|
|
using TIAM.Core.Enums;
|
|
using TIAM.Entities.Products;
|
|
using TIAM.Entities.ServiceProviders;
|
|
using TIAM.Services;
|
|
using TIAMWebApp.Shared.Application.Interfaces;
|
|
using TIAMWebApp.Shared.Application.Models;
|
|
using TIAMWebApp.Shared.Application.Models.ClientSide.UI;
|
|
using TIAMWebApp.Shared.Application.Services;
|
|
using TIAMWebApp.Shared.Application.Utility;
|
|
|
|
namespace TIAMSharedUI.Pages.User.Hotels
|
|
{
|
|
public partial class HotelComponent : ComponentBase
|
|
{
|
|
|
|
[Parameter] public Guid Id { get; set; }
|
|
|
|
[Parameter] public bool ShowSeriesPointMarkers { get; set; }
|
|
[Parameter] public bool ShowSeriesLabels { get; set; }
|
|
|
|
[Inject] ISupplierService SupplierService { get; set; }
|
|
|
|
[Inject] IUserDataService UserDataService { get; set; }
|
|
|
|
[Inject] IServiceProviderDataService ServiceProviderDataService { get; set; }
|
|
|
|
[Inject] AdminSignalRClient AdminSignalRClient { get; set; }
|
|
|
|
[Inject] IEnumerable<IAcLogWriterClientBase> LogWriters { get; set; }
|
|
|
|
[Inject] ISessionService SessionService { get; set; }
|
|
|
|
private LoggerClient<HotelComponent> _logger;
|
|
|
|
private object? _orderData;
|
|
private object? _affiliateData;
|
|
|
|
private object? _data;
|
|
|
|
public string ImageSource { get; set; } = "";
|
|
|
|
public Guid ProductId { get; set; }
|
|
|
|
private Product? _hotel;
|
|
private string _hotelName = string.Empty;
|
|
private string _hotelAddress = "No address set";
|
|
private string _hotelContactName = "No contact name set yet";
|
|
|
|
private bool _isProductAdmin;
|
|
private bool _accessDenied = true;
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
ProductId = Id;
|
|
base.OnParametersSet();
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_logger = new LoggerClient<HotelComponent>(LogWriters.ToArray());
|
|
|
|
_hotel = await AdminSignalRClient.GetByIdAsync<Product>(SignalRTags.GetProductById, Id);
|
|
if (_hotel != null)
|
|
{
|
|
if (!_hotel.Name.IsNullOrWhiteSpace()) _hotelName = _hotel.Name;
|
|
|
|
_hotelAddress = !_hotel.Profile.Address.AddressText.IsNullOrWhiteSpace() ? _hotel.Profile.Address.AddressText : "Address is empty";
|
|
_hotelContactName = !_hotel.Profile.FullName.IsNullOrWhiteSpace() ? _hotel.Profile.FullName : "No contact name has been set yet";
|
|
}
|
|
|
|
//TEMPORARY
|
|
_isProductAdmin = SessionService.User?.UserModelDto.UserProductMappings.Any(m => m.ProductId == Id && m.Permissions == 1) ?? false;
|
|
_accessDenied = !_isProductAdmin;
|
|
|
|
_logger.Debug($"{_hotel?.Name}, {_isProductAdmin}");
|
|
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"
|
|
},
|
|
};
|
|
|
|
_affiliateData = new object[]
|
|
{
|
|
new
|
|
{
|
|
AffiliateId = 1,
|
|
IncomeThisMonth = "$5",
|
|
IncomeAlltime = "9425",
|
|
CompanyName = "Upgen Ltd.",
|
|
Status = "Active"
|
|
},
|
|
new
|
|
{
|
|
AffiliateId = 2,
|
|
IncomeThisMonth = "$538",
|
|
IncomeAlltime = "13425",
|
|
CompanyName = "Kovacs hotel Ltd.",
|
|
Status = "Active"
|
|
},
|
|
new
|
|
{
|
|
AffiliateId = 3,
|
|
IncomeThisMonth = "$0",
|
|
IncomeAlltime = "134200",
|
|
CompanyName = "Innosaurus Ltd.",
|
|
Status = "Passive"
|
|
},
|
|
};
|
|
|
|
var suppliers = await SupplierService.GetSuppliersAsync();
|
|
_data = suppliers.Select(s => new
|
|
{
|
|
s.CompanyName,
|
|
s.ContactName,
|
|
s.ContactTitle,
|
|
s.Country,
|
|
s.City,
|
|
s.Address,
|
|
s.Phone
|
|
});
|
|
|
|
var productOwner = await AdminSignalRClient.GetByIdAsync<List<Company>>(SignalRTags.GetCompaniesById, _hotel.ServiceProviderId);
|
|
if (productOwner != null)
|
|
{
|
|
ImageSource = await ServiceProviderDataService.GetQRCodeByProductIdAsync(productOwner[0].AffiliateId);
|
|
}
|
|
else
|
|
{
|
|
const int width = 128;
|
|
const int height = 128;
|
|
var base64String = "";
|
|
|
|
// Create a new bitmap
|
|
using (var bitmap = new Bitmap(width, height))
|
|
{
|
|
// Set all pixels to black
|
|
using (var gfx = Graphics.FromImage(bitmap))
|
|
{
|
|
gfx.Clear(Color.Black);
|
|
}
|
|
|
|
// Convert bitmap to Base64 string
|
|
base64String = BitmapToBase64(bitmap);
|
|
Console.WriteLine(base64String);
|
|
}
|
|
|
|
ImageSource = base64String;
|
|
}
|
|
//SKBitmap bitmap = await ServiceProviderDataService.GetQRCodeByProductIdAsync(Guid.NewGuid());
|
|
|
|
}
|
|
|
|
private string BitmapToBase64(Bitmap bitmap)
|
|
{
|
|
using (var memoryStream = new MemoryStream())
|
|
{
|
|
// Save bitmap to memory stream
|
|
bitmap.Save(memoryStream, ImageFormat.Png);
|
|
|
|
// Convert memory stream to Base64 string
|
|
var imageBytes = memoryStream.ToArray();
|
|
return Convert.ToBase64String(imageBytes);
|
|
}
|
|
}
|
|
|
|
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
if (e.ElementType == GridElementType.HeaderCell)
|
|
{
|
|
e.Style = "background-color: rgba(0, 0, 0, 0.08)";
|
|
e.CssClass = "header-bold";
|
|
}
|
|
|
|
if (e.ElementType != GridElementType.DataRow) return;
|
|
|
|
var transferStatus = e.Grid?.GetRowValue(e.VisibleIndex, "TransferStatusType");
|
|
if (transferStatus == null) return;
|
|
|
|
var transferStatusByte = (byte)transferStatus;
|
|
|
|
switch (transferStatusByte)
|
|
{
|
|
case 5:
|
|
e.CssClass = "bg-important";
|
|
break;
|
|
case > 5 and < 35:
|
|
e.CssClass = "bg-attention";
|
|
break;
|
|
case 35:
|
|
e.CssClass = "bg-finished";
|
|
break;
|
|
case > 35:
|
|
e.CssClass = "bg-cancel";
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.Error($"Grid_CustomizeElement; {ex.Message}", ex);
|
|
}
|
|
}
|
|
}
|
|
}
|