@page "/Teacher/TeacherContact"
@inject Blazored.SessionStorage.ISessionStorageService sessionStorage
@inject NavigationManager NavManager
@inherits Admin.ListBase;
@using System.ComponentModel.DataAnnotations
@using Syncfusion.Blazor.Grids;
@using Syncfusion.Blazor.Buttons;
@using Syncfusion.Blazor.Spinner;
@using Syncfusion.Blazor.Navigations;
@using Syncfusion.Blazor.Popups;
@using BlazorApp.Helper
@using BWPMModels;
Klassen und Klassengrösse
Bitte das Formular vollständig ausfüllen.
@code {
SfTab Tab;
SfGrid Grid { get; set; }
public int Value = 0;
public List GridData { get; set; }
public List Klasses { get; set; }
public int foundrow = 0;
public bool ContinuePaging = true;
public bool InitialRender { get; set; }
private List _schulhaus { get; set; } = BlazorApp.Controller.SchulhausController.GetAllData();
private Lehrer _lehrer { get; set; } = new BWPMModels.Lehrer();
public List Lehrerdaten { get; set; }
string userid = "";
public static int? pkey { get; set; }
public bool Initial { get; set; } = true;
private bool ShowErrorDialog { get; set; } = false;
private bool ShowErrorDialog_grid { get; set; } = false;
public void Submit()
{
BlazorApp.Controller.LehrerController.PUT(_lehrer);
Tab.EnableTab(1, true);
Tab.Select(1);
}
public void InvalidSubmit()
{
Tab.EnableTab(1, false);
Tab.Select(0);
ShowErrorDialog = true;
}
private void CloseDialog()
{
this.ShowErrorDialog = false;
}
private void SaveClick()
{
}
private void WeiterClick()
{
NavManager.NavigateTo("/Teacher/TeacherStudent");
}
protected override async void OnInitialized()
{
}
public async Task TabCreate()
{
await Tab.EnableTab(1, false);
@*await Tab.EnableTab(2, false);*@
@*Tab.EnableTab(3, false);*@
}
public async Task SelectTrainBack()
{
await Tab.Select(0);
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
userid = await sessionStorage.GetItemAsync("UserID");
if (userid == null)
{
var authState = await authenticationStateTask;
var userId = authState.User.Claims.FirstOrDefault().Value;
var user = authState.User;
if (user.Identity.IsAuthenticated)
{
await sessionStorage.SetItemAsync("UserID", userId);
userid = userId;
}
else
{
await sessionStorage.SetItemAsync("UserID", userId);
userid = userId;
}
}
if (firstRender)
{
Lehrerdaten = BlazorApp.Controller.LehrerController.GetByUserID(userid);
_lehrer = Lehrerdaten.First();
GridData = BlazorApp.Controller.KlasseController.GetByLehrerID(_lehrer.ID);
await sessionStorage.SetItemAsync("LehrerID", _lehrer.ID.ToString());
}
}
private async Task OnBeginHandler(ActionEventArgs Args)
{
@* try
{
if (_lehrer.ID == 0)
{
ShowErrorDialog_grid = true;
return;
}
}
catch
{
ShowErrorDialog_grid = true;
return;
}*@
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
if (Args.Action == "Add")
{
Args.Data.lehrerID = _lehrer.ID;
Args.Data.erstellt_am = DateTime.Now;
Args.Data.mutierer = userid;
Args.Data.mutiert_am = DateTime.Now;
Args.Data.aktiv = true;
Args.Data.ID = BlazorApp.Controller.KlasseController.POST(Args.Data);
Value = Args.Data.ID;
}
else
{
Args.Data.mutierer = userid.ToString();
Args.Data.mutiert_am = DateTime.Now;
BlazorApp.Controller.KlasseController.PUT(Args.Data);
Value = Args.Data.ID;
Grid.Refresh();
}
}
}
public async Task OnCompletedHandler(ActionEventArgs Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.Save)
{
await Grid.SetRowData(Args.Data.ID, Args.Data);
double xx = 0;
Value = Args.Data.ID;
xx = await DataHandler();
await Grid.SelectRow(xx);
}
}
public async void RowDataBoundHandler(BeforeDataBoundArgs args)
{
if (!Initial)
{
//await Task.Delay(100);
//var Idx = await this.Grid.GetRowIndexByPrimaryKey(Convert.ToDouble(Value)); //get index value
//this.Grid.SelectRow(Convert.ToDouble(Idx));
}
Initial = false;
}
public async Task DataHandler()
{
var PageCount = (GridData.Count / Grid.PageSettings.PageSize) + 1;
ContinuePaging = true;
var CurrentPage = 1;
Grid.Refresh();
await Grid.GoToPage(1);
for (int i = 1; i <= PageCount; i++)
{
List Rows = await Grid.GetCurrentViewRecords(); // returns the current view data
for (int j = 0; j < Grid.PageSettings.PageSize; j++)
{
if (j < Rows.Count && Rows[j].ID == Value)
{
foundrow = j;
ContinuePaging = false; // prevent the default navigation
break;
}
}
if (ContinuePaging)
{
if (i >= PageCount)
{
i = 0;
}
await Grid.GoToPage(i + 1);
}
else
{
return foundrow;
}
}
return foundrow;
}
}