mirror of
https://github.com/claunia/marechai.git
synced 2025-12-16 19:14:25 +00:00
Add instruction set extension creation in admin view.
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
|
|
||||||
@page "/admin/instruction_set_extensions/details/{Id:int}"
|
@page "/admin/instruction_set_extensions/details/{Id:int}"
|
||||||
@page "/admin/instruction_set_extensions/edit/{Id:int}"
|
@page "/admin/instruction_set_extensions/edit/{Id:int}"
|
||||||
|
@page "/admin/instruction_set_extensions/create"
|
||||||
@inherits OwningComponentBase<InstructionSetExtensionsService>
|
@inherits OwningComponentBase<InstructionSetExtensionsService>
|
||||||
@inject IStringLocalizer<InstructionSetExtensionsService> L
|
@inject IStringLocalizer<InstructionSetExtensionsService> L
|
||||||
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
@attribute [Authorize(Roles = "UberAdmin, Admin")]
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
{
|
{
|
||||||
public partial class InstructionSetExtension
|
public partial class InstructionSetExtension
|
||||||
{
|
{
|
||||||
|
bool _creating;
|
||||||
bool _editing;
|
bool _editing;
|
||||||
bool _loaded;
|
bool _loaded;
|
||||||
Database.Models.InstructionSetExtension _model;
|
Database.Models.InstructionSetExtension _model;
|
||||||
@@ -21,12 +22,17 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
|
|
||||||
_loaded = true;
|
_loaded = true;
|
||||||
|
|
||||||
if(Id <= 0)
|
_creating = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||||
|
StartsWith("admin/instruction_set_extensions/create",
|
||||||
|
StringComparison.InvariantCulture);
|
||||||
|
|
||||||
|
if(Id <= 0 &&
|
||||||
|
!_creating)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_model = await Service.GetAsync(Id);
|
_model = _creating ? new Database.Models.InstructionSetExtension() : await Service.GetAsync(Id);
|
||||||
|
|
||||||
_editing = NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
_editing = _creating || NavigationManager.ToBaseRelativePath(NavigationManager.Uri).ToLowerInvariant().
|
||||||
StartsWith("admin/instruction_set_extensions/edit/",
|
StartsWith("admin/instruction_set_extensions/edit/",
|
||||||
StringComparison.InvariantCulture);
|
StringComparison.InvariantCulture);
|
||||||
|
|
||||||
@@ -42,6 +48,14 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
async void OnCancelClicked()
|
async void OnCancelClicked()
|
||||||
{
|
{
|
||||||
_editing = false;
|
_editing = false;
|
||||||
|
|
||||||
|
if(_creating)
|
||||||
|
{
|
||||||
|
NavigationManager.ToBaseRelativePath("admin/instruction_set_extensions");
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_model = await Service.GetAsync(Id);
|
_model = await Service.GetAsync(Id);
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
@@ -53,8 +67,13 @@ namespace Marechai.Pages.Admin.Details
|
|||||||
!Service.VerifyUnique(_model.Extension))
|
!Service.VerifyUnique(_model.Extension))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_editing = false;
|
if(_creating)
|
||||||
|
Id = await Service.CreateAsync(_model);
|
||||||
|
else
|
||||||
await Service.UpdateAsync(_model);
|
await Service.UpdateAsync(_model);
|
||||||
|
|
||||||
|
_editing = false;
|
||||||
|
_creating = false;
|
||||||
_model = await Service.GetAsync(Id);
|
_model = await Service.GetAsync(Id);
|
||||||
StateHasChanged();
|
StateHasChanged();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,9 +42,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
<p>
|
<p>
|
||||||
<span class="btn btn-primary">
|
<a class="btn btn-primary" href="/admin/instruction_set_extensions/create">@L["Create new"]</a>
|
||||||
@L["Create new"]
|
|
||||||
</span>
|
|
||||||
</p>
|
</p>
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
|
|||||||
@@ -37,6 +37,19 @@ namespace Marechai.Services
|
|||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> CreateAsync(InstructionSetExtension viewModel)
|
||||||
|
{
|
||||||
|
var model = new InstructionSetExtension
|
||||||
|
{
|
||||||
|
Extension = viewModel.Extension
|
||||||
|
};
|
||||||
|
|
||||||
|
await _context.InstructionSetExtensions.AddAsync(model);
|
||||||
|
await _context.SaveChangesAsync();
|
||||||
|
|
||||||
|
return model.Id;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task DeleteAsync(int id)
|
public async Task DeleteAsync(int id)
|
||||||
{
|
{
|
||||||
InstructionSetExtension item = await _context.InstructionSetExtensions.FindAsync(id);
|
InstructionSetExtension item = await _context.InstructionSetExtensions.FindAsync(id);
|
||||||
|
|||||||
Reference in New Issue
Block a user