356 lines
14 KiB
Plaintext
356 lines
14 KiB
Plaintext
@page "/sysadmin/companies"
|
|
@using BlazorAnimation
|
|
@using TIAM.Entities.ServiceProviders
|
|
@using TIAM.Resources
|
|
@using TIAM.Services
|
|
@using TIAMSharedUI.Pages.Components
|
|
@using TIAMSharedUI.Shared
|
|
@using TIAMWebApp.Shared.Application.Interfaces
|
|
@using TIAMWebApp.Shared.Application.Models.ClientSide.UI.WizardModels
|
|
@using TIAMWebApp.Shared.Application.Utility
|
|
@using AyCode.Services.Loggers
|
|
@using TIAMWebApp.Shared.Application.Services
|
|
@using AyCode.Core.Extensions;
|
|
@using TIAM.Entities.Addresses
|
|
@using TIAMSharedUI.Shared.Components.Grids
|
|
@using AyCode.Core
|
|
@using TIAM.Entities.Products
|
|
@using TIAM.Entities.Users
|
|
@using TIAM.Services
|
|
@layout AdminLayout
|
|
@inject IEnumerable<IAcLogWriterClientBase> LogWriters
|
|
@inject IStringLocalizer<TIAMResources> localizer
|
|
@inject IWizardProcessor wizardProcessor
|
|
@inject IServiceProviderDataService serviceProviderDataService
|
|
@inject IUserDataService userDataService
|
|
@inject ISessionService sessionService
|
|
@inject AdminSignalRClient AdminSignalRClient;
|
|
<PageTitle>Admin - Companies</PageTitle>
|
|
|
|
<div class="text-center m-5">
|
|
<h1>Partners</h1>
|
|
<h2 style="font-size:small">Manage partners here!</h2>
|
|
</div>
|
|
|
|
<DxPopup @bind-Visible="@_setOwnerPopupVisible"
|
|
ShowFooter="true"
|
|
HeaderText="Set owner by adding E-mail address">
|
|
<BodyContentTemplate>
|
|
<label for="emailID" class="demo-text mt-4 mb-1">
|
|
Put user email here
|
|
</label>
|
|
<DxMaskedInput @bind-Value="@Email"
|
|
CssClass="cw-320"
|
|
Mask="@EmailMask"
|
|
InputId="emailID"
|
|
MaskMode="MaskMode.RegEx" />
|
|
|
|
</BodyContentTemplate>
|
|
<FooterContentTemplate>
|
|
<DxButton CssClass="popup-button my-1 ms-2" RenderStyle="ButtonRenderStyle.Primary" Text="OK" Click="@SetOwner" />
|
|
@* <DxButton CssClass="popup-button my-1 ms-2" RenderStyle="ButtonRenderStyle.Secondary" Text="Cancel" Click="@(() => SetOwnerPopupVisible = false)" /> *@
|
|
</FooterContentTemplate>
|
|
</DxPopup>
|
|
|
|
<DxPopup CssClass="popup-demo-events"
|
|
@bind-Visible="@_sendMailPopupVisible"
|
|
ShowFooter="true"
|
|
CloseOnEscape="true"
|
|
CloseOnOutsideClick="false"
|
|
ShowCloseButton="false"
|
|
HeaderText="MessageBox"
|
|
Closing="EulaPopupClosing"
|
|
Closed="EulaPopupClosed">
|
|
<BodyContentTemplate>
|
|
<InputWizard Data=@_messageWizardModel
|
|
OnSubmit="SubmitForm"
|
|
IgnoreReflection=@IgnoreList
|
|
TitleResourceString="NewMessage"
|
|
SubtitleResourceString="NewMessageSubtitle"
|
|
SubmitButtonText="@localizer.GetString("ButtonSend")"></InputWizard>
|
|
</BodyContentTemplate>
|
|
<FooterContentTemplate Context="Context">
|
|
<div class="popup-demo-events-footer">
|
|
<!--DxCheckBox CssClass="popup-demo-events-checkbox" @bind-Checked="@EulaAccepted">I accept the terms of the EULA</!--DxCheckBox-->
|
|
<!--DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Primary" Text="OK" Click="Context.CloseCallback" /-->
|
|
<DxButton CssClass="popup-demo-events-button ms-2" RenderStyle="ButtonRenderStyle.Secondary" Text="Cancel" Click="CancelCreateClick" />
|
|
</div>
|
|
</FooterContentTemplate>
|
|
</DxPopup>
|
|
|
|
<div class="container-fluid">
|
|
<div class="row">
|
|
<div class=" col-12">
|
|
<Animation Effect="@Effect.FadeIn" Speed="@Speed.Fast" Delay="@TimeSpan.FromMilliseconds(250)">
|
|
<div class="card">
|
|
<CompanyGrid @ref="_gridCompany"
|
|
|
|
Logger="_logger"
|
|
SignalRClient="AdminSignalRClient"
|
|
CustomizeElement="Grid_CustomizeElement"
|
|
CustomizeEditModel="Grid_CustomizeEditModel"
|
|
EditMode="GridEditMode.EditForm"
|
|
ColumnResizeMode="GridColumnResizeMode.NextColumn"
|
|
ShowFilterRow="true">
|
|
|
|
<Columns>
|
|
<DxGridCommandColumn Width="135" MinWidth="135" FixedPosition="GridColumnFixedPosition.Left" />
|
|
<DxGridDataColumn FieldName="Id" SortIndex="0" ShowInColumnChooser="AcDomain.IsDeveloperVersion" Visible="AcDomain.IsDeveloperVersion" DisplayFormat="N" />
|
|
<DxGridDataColumn FieldName="Name" />
|
|
<DxGridDataColumn FieldName="OwnerId" DisplayFormat="N">
|
|
<CellDisplayTemplate>
|
|
@{
|
|
var keyField = context.Value as Guid?;
|
|
|
|
if (keyField.IsNullOrEmpty())
|
|
{
|
|
<DxButton Click="() => SetOwnerPopup((Company)context.DataItem)" Text="Set owner" RenderStyle="ButtonRenderStyle.Primary" />
|
|
}
|
|
else
|
|
{
|
|
<text>@keyField.Value.ToString("N")</text>
|
|
}
|
|
}
|
|
</CellDisplayTemplate>
|
|
</DxGridDataColumn>
|
|
<DxGridDataColumn FieldName="AffiliateId" DisplayFormat="N" />
|
|
<DxGridDataColumn FieldName="CommissionPercent" />
|
|
<DxGridDataColumn FieldName="Created" DisplayFormat="g" Width="140" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
|
|
<DxGridDataColumn FieldName="Modified" DisplayFormat="g" Width="140" CaptionAlignment="GridTextAlignment.Center" TextAlignment="GridTextAlignment.Center" />
|
|
@* <DxGridDataColumn FieldName="ContactEmail">
|
|
|
|
</DxGridDataColumn> *@
|
|
|
|
</Columns>
|
|
@* <DetailRowTemplate>
|
|
<CompaniesNestedUserProductMapping CurrentCompany="(TIAM.Entities.ServiceProviders.Company)context.DataItem" />
|
|
</DetailRowTemplate> *@
|
|
<DetailRowTemplate>
|
|
<DxTabs ActiveTabIndexChanged="ActiveTabIndexChanged">
|
|
<DxTabPage Text="Profile">
|
|
<ProfileGridComponent ParentData="((Company)context.DataItem)" />
|
|
</DxTabPage>
|
|
<DxTabPage Text="Products">
|
|
<ProductDetailGridComponent @ref="_productDetailGridComponent" DetailExpandButtonDisplayMode="GridDetailExpandButtonDisplayMode.Auto" GetAllTag="SignalRTags.GetProductsByOwnerId" OnGridEditModelSaving="OnProductGridItemSaving" ContextId="((Company)context.DataItem).Id" ParentData="(Company)context.DataItem" />
|
|
</DxTabPage>
|
|
<DxTabPage Text="Address">
|
|
<AddressDetailGridComponent ParentData="((Company)context.DataItem).Profile" />
|
|
</DxTabPage>
|
|
</DxTabs>
|
|
</DetailRowTemplate>
|
|
<EditFormTemplate Context="EditFormContext">
|
|
@{
|
|
var transfer2 = (Company)EditFormContext.EditModel;
|
|
}
|
|
<DxFormLayout CssClass="w-100">
|
|
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.LastName) ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
|
|
@EditFormContext.GetEditor("Name")
|
|
</DxFormLayoutItem>
|
|
<DxFormLayoutItem Caption=@localizer.GetString(ResourceKeys.LastName) ColSpanMd="6" ColSpanLg="6" ColSpanSm="12">
|
|
@EditFormContext.GetEditor("CommissionPercent")
|
|
</DxFormLayoutItem>
|
|
</DxFormLayout>
|
|
</EditFormTemplate>
|
|
</CompanyGrid>
|
|
</div>
|
|
</Animation>
|
|
</div>
|
|
<div class=" col-12 col-xl-6">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
|
|
@code {
|
|
private LoggerClient<ManageServiceProviders> _logger;
|
|
|
|
private ProductDetailGridComponent? _productDetailGridComponent;
|
|
|
|
//public Transfer myModel = new Transfer();
|
|
|
|
//public List<Company> ServiceProviderDataList { get; set; }
|
|
|
|
private bool _sendMailPopupVisible;
|
|
private bool _setOwnerPopupVisible;
|
|
|
|
private CompanyGrid _gridCompany;
|
|
|
|
private Company _companyToSetOwner = null;
|
|
|
|
public List<string> IgnoreList =
|
|
[
|
|
"ReceiverEmailAddress",
|
|
"ReceiverFullName",
|
|
"ReceiverId",
|
|
"SenderEmailAddress",
|
|
"SenderFullName",
|
|
"SenderId",
|
|
"ContextId",
|
|
];
|
|
|
|
private MessageWizardModel _messageWizardModel = new();
|
|
private string Email { get; set; } = "email@email.com";
|
|
string EmailMask { get; set; } = @"(\w|[.-])+@(\w|-)+\.(\w|-){2,4}";
|
|
|
|
DateTime StartDate { get; set; } = DateTime.Today;
|
|
DxSchedulerDataStorage _dataStorage = new();
|
|
|
|
|
|
void SendMail(Company item)
|
|
{
|
|
_logger.Info($"Sending mail to {item.OwnerId}, {item.Id}");
|
|
_messageWizardModel.ReceiverId = Guid.Parse("");
|
|
_messageWizardModel.ContextId = item.Id;
|
|
_messageWizardModel.SenderEmailAddress = "";
|
|
_messageWizardModel.ReceiverEmailAddress = "";
|
|
_messageWizardModel.ReceiverFullName = "";
|
|
_sendMailPopupVisible = true;
|
|
}
|
|
|
|
void SetOwnerPopup(Company item)
|
|
{
|
|
_logger.Info($"Setting owner of {item.OwnerId}, {item.Id}");
|
|
_companyToSetOwner = item;
|
|
_setOwnerPopupVisible = true;
|
|
}
|
|
|
|
async Task<Company> SetOwner()
|
|
{
|
|
|
|
//get user id from DB
|
|
var userModelDto = await userDataService.GetUserByEmailAsync(Email);
|
|
|
|
//overwrite ServiceProvider ownerid
|
|
//var target = await serviceProviderDataService.GetServiceProviderByIdAsync(CompanyToSetOwner.Id);
|
|
if (_companyToSetOwner == null)
|
|
{
|
|
return null;
|
|
}
|
|
else
|
|
{
|
|
_companyToSetOwner.OwnerId = userModelDto.Id;
|
|
var result = await serviceProviderDataService.UpdateServiceProviderAsync(_companyToSetOwner);
|
|
_setOwnerPopupVisible = false;
|
|
_companyToSetOwner = null;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
void CancelCreateClick()
|
|
{
|
|
|
|
_sendMailPopupVisible = false;
|
|
}
|
|
void EulaPopupClosed()
|
|
{
|
|
//cancel clicked
|
|
|
|
}
|
|
void EulaPopupClosing(PopupClosingEventArgs args)
|
|
{
|
|
//myModel = new TransferWizardModel();
|
|
_messageWizardModel = new MessageWizardModel();
|
|
}
|
|
|
|
//-----------------------------------------------------------------------------------
|
|
|
|
|
|
public async Task SubmitForm(object result)
|
|
{
|
|
var messageModel = result as MessageWizardModel;
|
|
messageModel.ContextId = _messageWizardModel.ContextId;
|
|
//messageModel.SenderId = sessionService.User.UserId;
|
|
|
|
string FormatEmailContent()
|
|
{
|
|
return $@"
|
|
<html>
|
|
<body>
|
|
<p>Dear {messageModel.SenderFullName},</p>
|
|
<p>{messageModel.Content}:</p>
|
|
<p>Best regards,<br/>Tour I Am team</p>
|
|
</body>
|
|
</html>";
|
|
}
|
|
messageModel.Content = FormatEmailContent();
|
|
|
|
_logger.Info(messageModel.Content);
|
|
var email = await wizardProcessor.ProcessWizardAsync<MessageWizardModel>(result.GetType(), messageModel);
|
|
|
|
_logger.Info($"Submitted nested form: {result.GetType().FullName}");
|
|
}
|
|
|
|
void Grid_CustomizeElement(GridCustomizeElementEventArgs e)
|
|
{
|
|
//TODO mark non active partners
|
|
|
|
}
|
|
|
|
void Grid_CustomizeEditModel(GridCustomizeEditModelEventArgs e)
|
|
{
|
|
if (!e.IsNew)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
var companyEditModel = (Company)e.EditModel; //TODO not valid cast
|
|
companyEditModel.Id = Guid.NewGuid();
|
|
companyEditModel.AffiliateId = Guid.NewGuid();
|
|
companyEditModel.Name = "Company name";
|
|
companyEditModel.OwnerId = Guid.Empty;
|
|
companyEditModel.ProfileId = Guid.NewGuid();
|
|
}
|
|
}
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
_logger = new LoggerClient<ManageServiceProviders>(LogWriters.ToArray());
|
|
|
|
await base.OnInitializedAsync();
|
|
}
|
|
|
|
private void OnProductGridItemSaving(GridEditModelSavingEventArgs e)
|
|
{
|
|
_logger.Detail($"OnProductGridItemSaving");
|
|
|
|
var company = _productDetailGridComponent!.ParentData as Company;
|
|
if (company == null || company.OwnerId.IsNullOrEmpty())
|
|
{
|
|
e.Cancel = true;
|
|
_logger.Error($"OnProductGridItemSaving; company == null || company.OwnerId.IsNullOrEmpty(); company.OwnerId: {company?.OwnerId}");
|
|
return;
|
|
}
|
|
|
|
var product = ((Product)e.EditModel);
|
|
|
|
if (e.IsNew)
|
|
{
|
|
if (product.Id.IsNullOrEmpty()) product.Id = Guid.NewGuid();
|
|
|
|
product.ServiceProviderId = company.Id;
|
|
product.UserProductMappings.Add(new UserProductMapping(company.OwnerId.Value, product.Id) { IsAdmin = true });
|
|
}
|
|
else
|
|
{ }
|
|
}
|
|
|
|
void ColumnChooserButton_Click()
|
|
{
|
|
_gridCompany.ShowColumnChooser();
|
|
}
|
|
|
|
protected override void OnAfterRender(bool firstRender)
|
|
{
|
|
if (firstRender)
|
|
{
|
|
_gridCompany.ExpandDetailRow(0);
|
|
}
|
|
}
|
|
|
|
private void ActiveTabIndexChanged(int index)
|
|
{
|
|
_logger.Detail($"ActiveTabIndexChanged");
|
|
}
|
|
|
|
} |