mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using Blazorise;
|
|
using Marechai.Shared;
|
|
using Marechai.ViewModels;
|
|
using Microsoft.AspNetCore.Components;
|
|
|
|
namespace Marechai.Pages.Admin.Details
|
|
{
|
|
public partial class MachineFamily
|
|
{
|
|
List<CompanyViewModel> _companies;
|
|
bool _editing;
|
|
bool _loaded;
|
|
MachineFamilyViewModel _model;
|
|
[Parameter]
|
|
public int Id { get; set; }
|
|
|
|
protected override async Task OnAfterRenderAsync(bool firstRender)
|
|
{
|
|
if(_loaded)
|
|
return;
|
|
|
|
_loaded = true;
|
|
|
|
if(Id <= 0)
|
|
return;
|
|
|
|
_companies = await CompaniesService.GetAsync();
|
|
_model = await Service.GetAsync(Id);
|
|
|
|
_editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
|
StartsWith("admin/machine_families/edit/", StringComparison.InvariantCulture);
|
|
|
|
StateHasChanged();
|
|
}
|
|
|
|
void OnEditClicked()
|
|
{
|
|
_editing = true;
|
|
StateHasChanged();
|
|
}
|
|
|
|
async void OnCancelClicked()
|
|
{
|
|
_editing = false;
|
|
_model = await Service.GetAsync(Id);
|
|
StateHasChanged();
|
|
}
|
|
|
|
async void OnSaveClicked()
|
|
{
|
|
if(string.IsNullOrWhiteSpace(_model.Name) ||
|
|
_model.Name?.Length > 255)
|
|
return;
|
|
|
|
_editing = false;
|
|
await Service.UpdateAsync(_model);
|
|
_model = await Service.GetAsync(Id);
|
|
StateHasChanged();
|
|
}
|
|
|
|
void ValidateName(ValidatorEventArgs e) =>
|
|
Validators.ValidateString(e, L["Family name must contain less than 255 characters."], 255);
|
|
}
|
|
} |