|
|
@ -1,12 +1,11 @@ |
|
|
@inject ILogger<Edit> Logger |
|
|
@inject ILogger<Edit> Logger |
|
|
@inject AuthService Auth |
|
|
@inject AuthService Auth |
|
|
|
|
|
@inject IJSRuntime JSRuntime |
|
|
|
|
|
|
|
|
@inherits BlazorAdmin.Helpers.BlazorComponent |
|
|
@inherits BlazorAdmin.Helpers.BlazorComponent |
|
|
|
|
|
|
|
|
@namespace BlazorAdmin.Pages.CatalogItemPage |
|
|
@namespace BlazorAdmin.Pages.CatalogItemPage |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="modal @_modalClass" tabindex="-1" role="dialog" style="display:@_modalDisplay"> |
|
|
<div class="modal @_modalClass" tabindex="-1" role="dialog" style="display:@_modalDisplay"> |
|
|
<div class="modal-dialog" role="document"> |
|
|
<div class="modal-dialog" role="document"> |
|
|
<div class="modal-content"> |
|
|
<div class="modal-content"> |
|
|
@ -26,60 +25,82 @@ |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
{ |
|
|
{ |
|
|
<div class="form-group"> |
|
|
<div class="container"> |
|
|
<label class="control-label col-md-2">Name</label> |
|
|
<div class="row"> |
|
|
<div class="col-md-12"> |
|
|
@if (HasPicture) |
|
|
<InputText class="form-control" @bind-Value="_item.Name" /> |
|
|
{ |
|
|
<ValidationMessage For="(() => _item.Name)" /> |
|
|
<img class="col-md-6 esh-picture" src="@LoadPicture"> |
|
|
</div> |
|
|
} |
|
|
</div> |
|
|
<div class="col-md-@(HasPicture?"6":"12") "> |
|
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
<div class="form-group"> |
|
|
<label class="control-label col-md-2">Description</label> |
|
|
<label class="control-label col-md-6">Name</label> |
|
|
<div class="col-md-12"> |
|
|
<div class="col-md-12"> |
|
|
<InputText class="form-control" @bind-Value="_item.Description" /> |
|
|
<InputText class="form-control" @bind-Value="_item.Name" /> |
|
|
<ValidationMessage For="(() => _item.Description)" /> |
|
|
<ValidationMessage For="(() => _item.Name)" /> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
<div class="form-group"> |
|
|
<label class="control-label col-md-2">Brand</label> |
|
|
<label class="control-label col-md-6">Description</label> |
|
|
<div class="col-md-12"> |
|
|
<div class="col-md-12"> |
|
|
<InputSelect @bind-Value="_item.CatalogBrandId" class="form-control"> |
|
|
<InputText class="form-control" @bind-Value="_item.Description" /> |
|
|
@foreach (var brand in Brands) |
|
|
<ValidationMessage For="(() => _item.Description)" /> |
|
|
{ |
|
|
</div> |
|
|
<option value="@brand.Id">@brand.Name</option> |
|
|
</div> |
|
|
} |
|
|
|
|
|
</InputSelect> |
|
|
</div> |
|
|
<ValidationMessage For="(() => _item.CatalogBrandId)" /> |
|
|
<div class="col-md-12"> |
|
|
</div> |
|
|
<div class="form-group"> |
|
|
</div> |
|
|
<label class="control-label col-md-6">Brand</label> |
|
|
|
|
|
<div class="col-md-12"> |
|
|
<div class="form-group"> |
|
|
<InputSelect @bind-Value="_item.CatalogBrandId" class="form-control"> |
|
|
<label class="control-label col-md-2">Type</label> |
|
|
@foreach (var brand in Brands) |
|
|
<div class="col-md-12"> |
|
|
{ |
|
|
<InputSelect @bind-Value="_item.CatalogTypeId" class="form-control"> |
|
|
<option value="@brand.Id">@brand.Name</option> |
|
|
@foreach (var type in Types) |
|
|
} |
|
|
{ |
|
|
</InputSelect> |
|
|
<option value="@type.Id">@type.Name</option> |
|
|
<ValidationMessage For="(() => _item.CatalogBrandId)" /> |
|
|
} |
|
|
</div> |
|
|
</InputSelect> |
|
|
</div> |
|
|
<ValidationMessage For="(() => _item.CatalogTypeId)" /> |
|
|
|
|
|
</div> |
|
|
<div class="form-group"> |
|
|
</div> |
|
|
<label class="control-label col-md-6">Type</label> |
|
|
|
|
|
<div class="col-md-12"> |
|
|
<div class="form-group"> |
|
|
<InputSelect @bind-Value="_item.CatalogTypeId" class="form-control"> |
|
|
<label class="control-label col-md-2">Price</label> |
|
|
@foreach (var type in Types) |
|
|
<div class="col-md-12"> |
|
|
{ |
|
|
<InputNumber @bind-Value="_item.Price" class="form-control" /> |
|
|
<option value="@type.Id">@type.Name</option> |
|
|
<ValidationMessage For="(() => _item.Price)" /> |
|
|
} |
|
|
</div> |
|
|
</InputSelect> |
|
|
</div> |
|
|
<ValidationMessage For="(() => _item.CatalogTypeId)" /> |
|
|
|
|
|
</div> |
|
|
<div class="form-group"> |
|
|
</div> |
|
|
<label class="control-label col-md-2">Picture name</label> |
|
|
|
|
|
<div class="col-md-12 esh-form-information"> |
|
|
<div class="form-group"> |
|
|
Uploading images not allowed for this version. |
|
|
<label class="control-label col-md-6">Price</label> |
|
|
|
|
|
<div class="col-md-12"> |
|
|
|
|
|
<InputNumber @bind-Value="_item.Price" class="form-control" /> |
|
|
|
|
|
<ValidationMessage For="(() => _item.Price)" /> |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
|
|
|
|
|
|
|
|
|
<div class="form-group"> |
|
|
|
|
|
<label class="control-label col-md-6">@_item.PictureName</label> |
|
|
|
|
|
<div class="row"> |
|
|
|
|
|
<div class="col-md-6 esh-form-information"> |
|
|
|
|
|
<InputFile OnChange="ChangeFile" /> |
|
|
|
|
|
</div> |
|
|
|
|
|
<div class="col-md-6 esh-form-information"> |
|
|
|
|
|
@if (HasPicture) |
|
|
|
|
|
{ |
|
|
|
|
|
<button type="button" class="btn btn-danger" @onclick="RemoveImage">Remove Picture</button> |
|
|
|
|
|
} |
|
|
|
|
|
</div> |
|
|
|
|
|
<span class="col-md-12" style="color: red;"> @_badFileMessage </span> |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
|
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
} |
|
|
} |
|
|
@ -111,6 +132,9 @@ |
|
|
[Parameter] |
|
|
[Parameter] |
|
|
public EventCallback<string> OnCloseClick { get; set; } |
|
|
public EventCallback<string> OnCloseClick { get; set; } |
|
|
|
|
|
|
|
|
|
|
|
private string LoadPicture => string.IsNullOrEmpty(_item.PictureBase64) ? string.IsNullOrEmpty(_item.PictureUri) ? string.Empty : $"{Auth.WebUrl}{_item.PictureUri}" : $"data:image/png;base64, {_item.PictureBase64}"; |
|
|
|
|
|
private bool HasPicture => !(string.IsNullOrEmpty(_item.PictureBase64) && string.IsNullOrEmpty(_item.PictureUri)); |
|
|
|
|
|
private string _badFileMessage = string.Empty; |
|
|
private string _modalDisplay = "none;"; |
|
|
private string _modalDisplay = "none;"; |
|
|
private string _modalClass = ""; |
|
|
private string _modalClass = ""; |
|
|
private bool _showEditModal = false; |
|
|
private bool _showEditModal = false; |
|
|
@ -119,25 +143,54 @@ |
|
|
private async Task SaveClick() |
|
|
private async Task SaveClick() |
|
|
{ |
|
|
{ |
|
|
await new BlazorAdmin.Services.CatalogItemServices.Edit(Auth).HandleAsync(_item); |
|
|
await new BlazorAdmin.Services.CatalogItemServices.Edit(Auth).HandleAsync(_item); |
|
|
Close(); |
|
|
await Close(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public async Task Open(int id) |
|
|
public async Task Open(int id) |
|
|
{ |
|
|
{ |
|
|
Logger.LogInformation("Now loading... /Catalog/Edit/{Id}", id); |
|
|
Logger.LogInformation("Now loading... /Catalog/Edit/{Id}", id); |
|
|
|
|
|
|
|
|
|
|
|
await new Css(JSRuntime).HideBodyOverflow(); |
|
|
|
|
|
|
|
|
_item = await new GetById(Auth).HandleAsync(id); |
|
|
_item = await new GetById(Auth).HandleAsync(id); |
|
|
|
|
|
|
|
|
_modalDisplay = "block;"; |
|
|
_modalDisplay = "block;"; |
|
|
_modalClass = "Show"; |
|
|
_modalClass = "Show"; |
|
|
_showEditModal = true; |
|
|
_showEditModal = true; |
|
|
|
|
|
|
|
|
|
|
|
StateHasChanged(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void Close() |
|
|
private async Task Close() |
|
|
{ |
|
|
{ |
|
|
|
|
|
await new Css(JSRuntime).ShowBodyOverflow(); |
|
|
|
|
|
|
|
|
_modalDisplay = "none"; |
|
|
_modalDisplay = "none"; |
|
|
_modalClass = ""; |
|
|
_modalClass = ""; |
|
|
_showEditModal = false; |
|
|
_showEditModal = false; |
|
|
OnCloseClick.InvokeAsync(null); |
|
|
await OnCloseClick.InvokeAsync(null); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private async Task ChangeFile(IFileListEntry[] files) |
|
|
|
|
|
{ |
|
|
|
|
|
_badFileMessage = string.Empty; |
|
|
|
|
|
|
|
|
|
|
|
var file = files.FirstOrDefault(); |
|
|
|
|
|
_item.PictureName = file?.Name; |
|
|
|
|
|
_item.PictureBase64 = await CatalogItem.DataToBase64(file); |
|
|
|
|
|
|
|
|
|
|
|
_badFileMessage = CatalogItem.IsValidImage(_item.PictureName, _item.PictureBase64); |
|
|
|
|
|
if (!string.IsNullOrEmpty(_badFileMessage)) |
|
|
|
|
|
{ |
|
|
|
|
|
_item.PictureName = null; |
|
|
|
|
|
_item.PictureBase64 = null; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void RemoveImage() |
|
|
|
|
|
{ |
|
|
|
|
|
_item.PictureName = null; |
|
|
|
|
|
_item.PictureBase64 = null; |
|
|
|
|
|
_item.PictureUri = null; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|