@page "/plants/add"
@using Models.BaseData
@inject IPlantsUtils PlantsUtils
@using Microsoft.AspNetCore.Components.Forms
@code {
protected SavePlantViewModel PlantModel { get; set; } = new();
protected async Task AddPlant()
{
var response = await PlantsUtils.Add(PlantModel);
if (response.IsSuccessStatusCode)
{
NavigationManager.NavigateTo("/plants/list");
}
}
private async Task OnInputFileChange(InputFileChangeEventArgs e)
{
var buf = new byte[e.File.Size];
try
{
await e.File.OpenReadStream(maxAllowedSize: 1000000).ReadAsync(buf);
PlantModel.Base64Icon = Convert.ToBase64String(buf);
StateHasChanged();
}
catch
{
await SwalUtils.ShowSwal("","Image size should be less than 1 MB.", icon: SweetAlertIcon.Error);
}
}
}