Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
290 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
BookStore-Blazor-EfCore/src/Acme.BookStore.Blazor/Pages/CreateBook.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
@page "/books/new" | ||
@attribute [Authorize(BookStorePermissions.Books.Create)] | ||
@inherits BookStoreComponentBase | ||
|
||
@using Acme.BookStore.Books; | ||
@using Acme.BookStore.Localization; | ||
@using Acme.BookStore.Permissions; | ||
@using Microsoft.Extensions.Localization; | ||
@using Volo.Abp.AspNetCore.Components.Web; | ||
|
||
@inject IStringLocalizer<BookStoreResource> L | ||
@inject AbpBlazorMessageLocalizerHelper<BookStoreResource> LH | ||
@inject IBookAppService AppService | ||
@inject NavigationManager NavigationManager | ||
|
||
<Card> | ||
<CardHeader> | ||
<HeadContent> | ||
<ModalTitle>@L["NewBook"]</ModalTitle> | ||
</HeadContent> | ||
</CardHeader> | ||
<CardBody> | ||
<Validations @ref="@CreateValidationsRef" Model="@NewEntity" ValidateOnLoad="false"> | ||
<Validation MessageLocalizer="@LH.Localize"> | ||
<Field> | ||
<FieldLabel>@L["Author"]</FieldLabel> | ||
<Select TValue="Guid" @bind-SelectedValue="@NewEntity.AuthorId"> | ||
@foreach (var author in authorList) | ||
{ | ||
<SelectItem TValue="Guid" Value="@author.Id"> | ||
@author.Name | ||
</SelectItem> | ||
} | ||
</Select> | ||
</Field> | ||
<Field> | ||
<FieldLabel>@L["Name"]</FieldLabel> | ||
<TextEdit @bind-Text="@NewEntity.Name"> | ||
<Feedback> | ||
<ValidationError /> | ||
</Feedback> | ||
</TextEdit> | ||
</Field> | ||
</Validation> | ||
<Field> | ||
<FieldLabel>@L["Type"]</FieldLabel> | ||
<Select TValue="BookType" @bind-SelectedValue="@NewEntity.Type"> | ||
@foreach (int bookTypeValue in Enum.GetValues(typeof(BookType))) | ||
{ | ||
<SelectItem TValue="BookType" Value="@((BookType) bookTypeValue)"> | ||
@L[$"Enum:BookType.{bookTypeValue}"] | ||
</SelectItem> | ||
} | ||
</Select> | ||
</Field> | ||
<Field> | ||
<FieldLabel>@L["PublishDate"]</FieldLabel> | ||
<DateEdit TValue="DateTime" @bind-Date="NewEntity.PublishDate" /> | ||
</Field> | ||
<Field> | ||
<FieldLabel>@L["Price"]</FieldLabel> | ||
<NumericEdit TValue="float" @bind-Value="NewEntity.Price" /> | ||
</Field> | ||
</Validations> | ||
</CardBody> | ||
<CardFooter> | ||
<Button Color="Color.Secondary" Type="ButtonType.Link" To="books"> | ||
@L["Cancel"] | ||
</Button> | ||
<Button Color="Color.Primary" | ||
Type="@ButtonType.Submit" | ||
PreventDefaultOnSubmit="true" | ||
Clicked="CreateEntityAsync"> | ||
@L["Save"] | ||
</Button> | ||
</CardFooter> | ||
</Card> |
55 changes: 55 additions & 0 deletions
55
BookStore-Blazor-EfCore/src/Acme.BookStore.Blazor/Pages/CreateBook.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using Acme.BookStore.Books; | ||
using Blazorise; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Volo.Abp; | ||
|
||
namespace Acme.BookStore.Blazor.Pages; | ||
|
||
public partial class CreateBook | ||
{ | ||
protected Validations CreateValidationsRef; | ||
protected CreateUpdateBookDto NewEntity = new(); | ||
IReadOnlyList<AuthorLookupDto> authorList = Array.Empty<AuthorLookupDto>(); | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await base.OnInitializedAsync(); | ||
authorList = (await AppService.GetAuthorLookupAsync()).Items; | ||
|
||
if (!authorList.Any()) | ||
{ | ||
throw new UserFriendlyException(message: L["AnAuthorIsRequiredForCreatingBook"]); | ||
} | ||
|
||
NewEntity.AuthorId = authorList.First().Id; | ||
|
||
if (CreateValidationsRef != null) | ||
{ | ||
await CreateValidationsRef.ClearAll(); | ||
} | ||
} | ||
|
||
protected virtual async Task CreateEntityAsync() | ||
{ | ||
try | ||
{ | ||
var validate = true; | ||
if (CreateValidationsRef != null) | ||
{ | ||
validate = await CreateValidationsRef.ValidateAll(); | ||
} | ||
if (validate) | ||
{ | ||
await AppService.CreateAsync(NewEntity); | ||
NavigationManager.NavigateTo("books"); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
await HandleErrorAsync(ex); | ||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
BookStore-Blazor-EfCore/src/Acme.BookStore.Blazor/Pages/EditBook.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
@page "/books/{Id}" | ||
@attribute [Authorize(BookStorePermissions.Books.Edit)] | ||
@inherits BookStoreComponentBase | ||
@using Acme.BookStore.Books; | ||
@using Acme.BookStore.Localization; | ||
@using Acme.BookStore.Permissions; | ||
@using Microsoft.Extensions.Localization; | ||
@using Volo.Abp.AspNetCore.Components.Web; | ||
|
||
@inject IStringLocalizer<BookStoreResource> L | ||
@inject AbpBlazorMessageLocalizerHelper<BookStoreResource> LH | ||
@inject IBookAppService AppService | ||
@inject NavigationManager NavigationManager | ||
|
||
<Card> | ||
<CardHeader> | ||
<HeadContent> | ||
<ModalTitle>@EditingEntity.Name</ModalTitle> | ||
</HeadContent> | ||
</CardHeader> | ||
<CardBody> | ||
<Validations @ref="@EditValidationsRef" Model="@EditingEntity" ValidateOnLoad="false"> | ||
<Validation MessageLocalizer="@LH.Localize"> | ||
<Field> | ||
<FieldLabel>@L["Author"]</FieldLabel> | ||
<Select TValue="Guid" @bind-SelectedValue="@EditingEntity.AuthorId"> | ||
@foreach (var author in authorList) | ||
{ | ||
<SelectItem TValue="Guid" Value="@author.Id"> | ||
@author.Name | ||
</SelectItem> | ||
} | ||
</Select> | ||
</Field> | ||
<Field> | ||
<FieldLabel>@L["Name"]</FieldLabel> | ||
<TextEdit @bind-Text="@EditingEntity.Name"> | ||
<Feedback> | ||
<ValidationError /> | ||
</Feedback> | ||
</TextEdit> | ||
</Field> | ||
</Validation> | ||
<Field> | ||
<FieldLabel>@L["Type"]</FieldLabel> | ||
<Select TValue="BookType" @bind-SelectedValue="@EditingEntity.Type"> | ||
@foreach (int bookTypeValue in Enum.GetValues(typeof(BookType))) | ||
{ | ||
<SelectItem TValue="BookType" Value="@((BookType) bookTypeValue)"> | ||
@L[$"Enum:BookType.{bookTypeValue}"] | ||
</SelectItem> | ||
} | ||
</Select> | ||
</Field> | ||
<Field> | ||
<FieldLabel>@L["PublishDate"]</FieldLabel> | ||
<DateEdit TValue="DateTime" @bind-Date="EditingEntity.PublishDate" /> | ||
</Field> | ||
<Field> | ||
<FieldLabel>@L["Price"]</FieldLabel> | ||
<NumericEdit TValue="float" @bind-Value="EditingEntity.Price" /> | ||
</Field> | ||
</Validations> | ||
</CardBody> | ||
<CardFooter> | ||
<Button Color="Color.Secondary" Type="ButtonType.Link" To="books"> | ||
@L["Cancel"] | ||
</Button> | ||
<Button Color="Color.Primary" | ||
Type="@ButtonType.Submit" | ||
PreventDefaultOnSubmit="true" | ||
Clicked="UpdateEntityAsync"> | ||
@L["Save"] | ||
</Button> | ||
</CardFooter> | ||
</Card> |
Oops, something went wrong.