Hi,
My app : blazor wasm aps.net core5.
First of all I tried, I will try to explain the configuration of my application is : DataGridView with several column of which ECR & ECO
The column ECR is fill when the user click on AddEcr. Thanks to @AgaveJoe the number is incremented with the current year. it's ok.
We can acces to ECO column when we click on Edit button. I want that the user can take or not the number ECO xxx/YY (with the same format that ECR).
The button Update correspond to the Edit.razor
this means populate all data in table from database.
Edit.razor
<FormEdit ButtonText="Update" dev="dev"
OnValidSubmit="@EditDeveloper" />
@code {
[Parameter] public int developerId { get; set; }
Developer dev = new Developer();
protected async override Task OnParametersSetAsync()
{
dev = await http.GetFromJsonAsync<Developer>($"api/developer/{developerId}");
}
async Task EditDeveloper()
{
await http.PutAsJsonAsync("api/developer", dev);
await js.InvokeVoidAsync("alert", $"Updated Successfully!");
uriHelper.NavigateTo("developer");
}
Now the button Number ECO
allows to user take the number .
The definition of the button Number ECO
is in FormEdit.razor
<EditForm Model="@dev" OnValidSubmit="@OnValidSubmit">
<DataAnnotationsValidator />
<button type="submit" @onclick="@OnSubmitEcoNumber" >Submit</button>
</EditForm>
@code {
[Parameter] public Developer dev { get; set; }
[Parameter] public EventCallback OnValidSubmit { get; set; }
Developer[] developers { get; set; }
protected void OnSubmitEcoNumber()
{
//It's here that I've to call the method
}
}
My question is : how to do the link between the button Number ECO
(I think I have to put check box) with the Edit.razor
to fill the column ECO?
the api is define below to fill the ECO number with a good format
[HttpPost]
public async Task<IActionResult> Post(Developer developer)
{
YearCountECO deveco = await IncrementECODeveloperIdAsync();
developer.YearECO = deveco.YearECO;
developer.CountECO = deveco.CountECO;
YearCount dev = await IncrementDeveloperIdAsync();
developer.Year = dev.Year;
developer.Count = dev.Count;
_context.Add(developer);
await _context.SaveChangesAsync();
return Ok(developer.Id);
}
private async Task<YearCountECO> IncrementECODeveloperIdAsync()
{
if (!await _context.Developers.AnyAsync(d => d.Year == DateTime.Now.Year))
{
return new YearCountECO() { CountECO = 1, YearECO= DateTime.Now.Year };
}
int max = await _context.Developers.Where(d => d.Year == DateTime.Now.Year).MaxAsync(d => d.Count) + 1;
return new YearCountECO() { CountECO = max, YearECO = DateTime.Now.Year };
}