add Opportunities
parent
3af421b189
commit
c0cf03adb3
@ -0,0 +1,106 @@
|
|||||||
|
@page "/Opportunities"
|
||||||
|
@using Gremlin_BlazorServer.Data.EntityClasses
|
||||||
|
@inherits LayoutComponentBase
|
||||||
|
|
||||||
|
@inject ILoadingIndicatorService ApplicationLoadingIndicatorService
|
||||||
|
|
||||||
|
<AuthorizeView>
|
||||||
|
<Authorized Context="_">
|
||||||
|
<Div Margin="Margin.Is3"
|
||||||
|
Border="Border.Dark.OnAll"
|
||||||
|
Padding="Padding.Is3"
|
||||||
|
style="box-shadow: 10px 10px #343A40">
|
||||||
|
|
||||||
|
<Heading Size="HeadingSize.Is4">Opportunities</Heading>
|
||||||
|
<Paragraph>
|
||||||
|
<DataGrid TItem="Opportunity"
|
||||||
|
Data="@opportunities"
|
||||||
|
SelectedRow="@selectedOpportunity"
|
||||||
|
SelectedRowChanged="@OnSelectedOpportunityChanged"
|
||||||
|
RowInserted="@OnRowInsertedAsync"
|
||||||
|
RowUpdated="@OnRowUpdatedAsync"
|
||||||
|
RowRemoved="@OnRowRemovedAsync"
|
||||||
|
CommandMode="DataGridCommandMode.ButtonRow"
|
||||||
|
EditMode="DataGridEditMode.Popup"
|
||||||
|
UseValidation Narrow Editable ShowPager Hoverable Sortable Filterable Striped Responsive>
|
||||||
|
|
||||||
|
<DataGridColumns>
|
||||||
|
<DataGridCommandColumn NewCommandAllowed="false" EditCommandAllowed="false" DeleteCommandAllowed="false">
|
||||||
|
<SaveCommandTemplate>
|
||||||
|
<Button ElementId="btnSave" PreventDefaultOnSubmit Color="Color.Primary" Clicked="context.Clicked">@context.LocalizationString</Button>
|
||||||
|
</SaveCommandTemplate>
|
||||||
|
<CancelCommandTemplate>
|
||||||
|
<Button ElementId="btnCancel" Color="Color.Secondary" Clicked="context.Clicked">@context.LocalizationString</Button>
|
||||||
|
</CancelCommandTemplate>
|
||||||
|
</DataGridCommandColumn>
|
||||||
|
|
||||||
|
<DataGridColumn Field="@nameof(Opportunity.OpportunityId)" Caption="OpportunityId" Filterable Sortable/>
|
||||||
|
|
||||||
|
@* <DataGridColumn Field="@nameof(Opportunity.OpportunityName)" Caption="OpportunityName" Filterable Sortable Editable/> *@
|
||||||
|
@* *@
|
||||||
|
@* <DataGridColumn Field="@nameof(Opportunity.Street)" Caption="Street" Filterable Sortable Editable/> *@
|
||||||
|
@* *@
|
||||||
|
@* <DataGridColumn Field="@nameof(Opportunity.Zip)" Caption="Zip" Filterable Sortable Editable> *@
|
||||||
|
@* <EditTemplate> *@
|
||||||
|
@* <NumericEdit TValue="uint" Value="Convert.ToUInt32(context.CellValue)" ValueChanged="v => context.CellValue = v"/> *@
|
||||||
|
@* </EditTemplate> *@
|
||||||
|
@* </DataGridColumn> *@
|
||||||
|
|
||||||
|
@* <DataGridColumn Field="@nameof(Opportunity.City)" Caption="City" Filterable Sortable Editable/> *@
|
||||||
|
@* *@
|
||||||
|
@* <DataGridColumn Field="@nameof(Opportunity.PhoneNumber)" Caption="PhoneNumber" Filterable Sortable Editable/> *@
|
||||||
|
@* *@
|
||||||
|
@* <DataGridColumn Field="@nameof(Opportunity.EMail)" Caption="EMail" Filterable Sortable Editable/> *@
|
||||||
|
@* *@
|
||||||
|
@* <DataGridColumn Field="@nameof(Opportunity.FaxNumber)" Caption="FaxNumber" Filterable Sortable Editable/> *@
|
||||||
|
@* *@
|
||||||
|
@* <DataGridColumn Field="@nameof(Opportunity.Webpage)" Caption="Webpage" Filterable Sortable Editable/> *@
|
||||||
|
|
||||||
|
<DataGridColumn Field="@nameof(Opportunity.SapOpportunityNumber)" Caption="SapOpportunityNumber" Filterable Sortable Editable>
|
||||||
|
<EditTemplate>
|
||||||
|
<NumericEdit TValue="uint" Value="Convert.ToUInt32(context.CellValue)" ValueChanged="v => context.CellValue = v"/>
|
||||||
|
</EditTemplate>
|
||||||
|
</DataGridColumn>
|
||||||
|
|
||||||
|
<DataGridColumn Field="@nameof(Opportunity.DataModificationDate)" Caption="DataModificationDate" Filterable Sortable/>
|
||||||
|
</DataGridColumns>
|
||||||
|
|
||||||
|
<ButtonRowTemplate>
|
||||||
|
<Button Color="Color.Primary" Clicked="context.NewCommand.Clicked">New</Button>
|
||||||
|
<Button Color="Color.Warning" Disabled="selectedOpportunity is null" Clicked="context.EditCommand.Clicked">Edit</Button>
|
||||||
|
<Button Color="Color.Danger" Disabled="selectedOpportunity is null" Clicked="context.DeleteCommand.Clicked">Delete</Button>
|
||||||
|
<Button Color="Color.Secondary" Clicked="context.ClearFilterCommand.Clicked">Clear Filter</Button>
|
||||||
|
</ButtonRowTemplate>
|
||||||
|
</DataGrid>
|
||||||
|
</Paragraph>
|
||||||
|
</Div>
|
||||||
|
|
||||||
|
<Div Margin="Margin.Is3"
|
||||||
|
Border="Border.Dark.OnAll"
|
||||||
|
Padding="Padding.Is3"
|
||||||
|
style="box-shadow: 10px 10px #343A40">
|
||||||
|
|
||||||
|
<Paragraph>
|
||||||
|
<Button Color="Color.Primary" Clicked="@OnRemoveDublicates">Remove Dublicates</Button>
|
||||||
|
</Paragraph>
|
||||||
|
|
||||||
|
<Heading Size="HeadingSize.Is6">Import Opportunities from TSV</Heading>
|
||||||
|
<Paragraph>
|
||||||
|
<Field>
|
||||||
|
<FileEdit Filter=".csv" Changed="@OnImportOpportunities"/>
|
||||||
|
</Field>
|
||||||
|
</Paragraph>
|
||||||
|
</Div>
|
||||||
|
</Authorized>
|
||||||
|
|
||||||
|
<NotAuthorized>
|
||||||
|
<Div Margin="Margin.Is3"
|
||||||
|
Border="Border.Dark.OnAll"
|
||||||
|
Padding="Padding.Is3"
|
||||||
|
style="box-shadow: 10px 10px #343A40">
|
||||||
|
|
||||||
|
<Heading Size="HeadingSize.Is3">Authentication Failure!</Heading>
|
||||||
|
<Paragraph>You're not signed in. Please click on the upper right to either register or log in.</Paragraph>
|
||||||
|
</Div>
|
||||||
|
</NotAuthorized>
|
||||||
|
</AuthorizeView>
|
||||||
@ -0,0 +1,86 @@
|
|||||||
|
using System.Security.Claims;
|
||||||
|
using Blazorise;
|
||||||
|
using Blazorise.DataGrid;
|
||||||
|
using Gremlin_BlazorServer.Data.EntityClasses;
|
||||||
|
using Gremlin_BlazorServer.Services;
|
||||||
|
using Microsoft.AspNetCore.Components;
|
||||||
|
using Microsoft.AspNetCore.Components.Authorization;
|
||||||
|
using NuGet.Packaging;
|
||||||
|
|
||||||
|
namespace Gremlin_BlazorServer.Pages;
|
||||||
|
|
||||||
|
public partial class Opportunities {
|
||||||
|
private readonly IList<Opportunity> opportunities = new List<Opportunity>();
|
||||||
|
private Opportunity? selectedOpportunity;
|
||||||
|
private static int ImportProgress { get; set; }
|
||||||
|
|
||||||
|
[CascadingParameter] private Task<AuthenticationState>? AuthenticationStateTask { get; set; }
|
||||||
|
|
||||||
|
protected override async Task OnInitializedAsync() {
|
||||||
|
if (AuthenticationStateTask != null) {
|
||||||
|
ClaimsPrincipal user = (await AuthenticationStateTask).User;
|
||||||
|
if (user.Identity is { IsAuthenticated: true }) {
|
||||||
|
ImportProgress = 0;
|
||||||
|
await ApplicationLoadingIndicatorService.Show();
|
||||||
|
opportunities.AddRange(await GenericController.GetAllAsync<Opportunity>());
|
||||||
|
selectedOpportunity = opportunities.FirstOrDefault();
|
||||||
|
await OnSelectedOpportunityChanged(selectedOpportunity);
|
||||||
|
await ApplicationLoadingIndicatorService.Hide();
|
||||||
|
}
|
||||||
|
await base.OnInitializedAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task OnSelectedOpportunityChanged(Opportunity? newSelectedOpportunity) => Task.FromResult(selectedOpportunity = newSelectedOpportunity);
|
||||||
|
|
||||||
|
private async Task OnImportOpportunities(FileChangedEventArgs fileChangedEventArgs) {
|
||||||
|
try {
|
||||||
|
foreach (IFileEntry? file in fileChangedEventArgs.Files) {
|
||||||
|
using MemoryStream stream = new();
|
||||||
|
await file.WriteToStreamAsync(stream);
|
||||||
|
_ = stream.Seek(0, SeekOrigin.Begin);
|
||||||
|
using StreamReader reader = new(stream);
|
||||||
|
string fileContent = await reader.ReadToEndAsync();
|
||||||
|
GenericImporter.ImportCsv<Opportunity>(fileContent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception exception) {
|
||||||
|
Console.WriteLine(exception.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Task OnRowInsertedAsync(SavedRowItem<Opportunity, Dictionary<string, object>> opportunity) {
|
||||||
|
Opportunity newOpportunity = ResolveOpportunityAsync(opportunity.Item);
|
||||||
|
// if (newOpportunity.OpportunityType is null || newOpportunity.SubMarket is null) return;
|
||||||
|
int count = GenericController.Insert(newOpportunity);
|
||||||
|
Console.WriteLine($"Inserted {count} properties for new Opportunity {newOpportunity.OpportunityId}: {newOpportunity.Description}.");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Task OnRowUpdatedAsync(SavedRowItem<Opportunity, Dictionary<string, object>> opportunity) {
|
||||||
|
Opportunity newOpportunity = ResolveOpportunityAsync(opportunity.Item);
|
||||||
|
int count = GenericController.Update(opportunity.Item);
|
||||||
|
Console.WriteLine($"Updated {count} properties in Opportunity {newOpportunity.OpportunityId}: {newOpportunity.Description}.");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task OnRowRemovedAsync(Opportunity opportunity) {
|
||||||
|
int count = await GenericController.RemoveAsync(opportunity);
|
||||||
|
Console.WriteLine($"Removed {count} properties and Opportunity {opportunity.OpportunityId}: {opportunity.Description}.");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Opportunity ResolveOpportunityAsync(Opportunity newOpportunity) {
|
||||||
|
newOpportunity.DataModificationByUser = "Gremlin Blazor Server GUI";
|
||||||
|
newOpportunity.DataVersionNumber++;
|
||||||
|
// newOpportunity.OpportunityType = await GenericController.GetAsync<OpportunityType>(aT => aT.OpportunityTypeCode.Equals("SUP"));
|
||||||
|
// newOpportunity.SubMarket = await GenericController.GetAsync<SubMarket>(sM => sM.SubMarketCode.Equals("VEN"));
|
||||||
|
return newOpportunity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task OnRemoveDublicates() {
|
||||||
|
int i = await GenericController.RemoveDublicatesAsync<Opportunity>();
|
||||||
|
Console.WriteLine($"Removed {i} dublicates from Opportunities.");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue