@page "/NoteSetType"
@using EView360.Services;
@inject NoteSetTypeService service
NoteSetType
@*
*@
@code {
private List noteSetTypes = new();
private DbModels.NoteSetType? selectedNoteSetType;
private bool isEditMode = false;
private DataGrid? dataGridRef;
string? selectedUser;
protected override async void OnInitialized()
{
noteSetTypes = await service.GetNoteSetTypeListAsync();
await base.OnInitializedAsync();
}
private string HeaderCellClass()
{
return "tableHeader";
}
private bool CustomUserFilter(object itemValue, object searchValue)
{
if (searchValue is string userFilter)
{
return userFilter == "*" || userFilter == itemValue?.ToString();
}
return true;
}
public void CheckName(ValidatorEventArgs validationArgs)
{
ValidationRule.IsNotEmpty(validationArgs);
if (validationArgs.Status == ValidationStatus.Error)
{
validationArgs.ErrorText = "This field is required";
}
else if (noteSetTypes.Count(x => x.NoteSetTypeName.Trim().ToLower() == validationArgs.Value.ToString().Trim().ToLower()) > 1)
{
validationArgs.ErrorText = "Note type name already exists. Please provide unique name";
validationArgs.Status = ValidationStatus.Error;
}
}
private async Task OnEditBtn(DbModels.NoteSetType noteSetType)
{
isEditMode = true;
await dataGridRef.Edit(noteSetType);
}
private async Task OnCancelBtn(DbModels.NoteSetType noteSetType)
{
isEditMode = false;
await dataGridRef.Cancel();
}
async Task OnRowInserted(SavedRowItem> savedRow)
{
savedRow.Item.CreationTime = DateTime.Now;
service.InsertNoteSetType(savedRow.Item);
}
async Task OnRowUpdated(SavedRowItem> savedRow)
{
isEditMode = false;
service.UpdateNoteSetType(savedRow.Item, savedRow.Item.NoteSetTypeId);
}
async Task OnRowRemoving(CancellableRowChange cancellableRow)
{
if (service.IfAtmExistForNoteSetType(cancellableRow.Item.NoteSetTypeId).Result)
{
cancellableRow.Cancel = true;
}
}
async Task OnRowRemoved(DbModels.NoteSetType noteSetType)
{
service.DeleteNoteSetType(noteSetType.NoteSetTypeId);
}
}