You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
3.5 KiB

2 years ago
@page "/fetchdata"
<PageTitle>Weather forecast</PageTitle>
@using BlazorServerApp.Data
@inject WeatherForecastService ForecastService
<h1>Weather forecast</h1>
<p>This component demonstrates fetching data from a service.</p>
2 years ago
@if (_forecasts == null)
2 years ago
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
2 years ago
@foreach (var forecast in _forecasts)
2 years ago
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
2 years ago
<button class="btn btn-primary" @onclick="AddNewForecast">
Add New Forecast
</button>
if (_showPopup)
{
<div class="modal" style="display:block" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title">Add Forecast</h3>
<button type="button" class="btn-close" @onclick="ClosePopup"/>
</div>
<div class="modal-body">
<EditForm Model="_addForecast" OnValidSubmit="SaveForecast">
@* Validation 기능 on *@
<DataAnnotationsValidator/>
@* 에러 메세지 출력 기능 on *@
<ValidationSummary/>
<label for="TemperatureC">Temperacure(℃)</label>
<InputNumber class="form-control" placeholder="Temperacure(℃)" @bind-Value="_addForecast.TemperatureC" />
<label for="Summary">Summary</label>
<InputText class="form-control" placeholder="Summary" @bind-Value="_addForecast.Summary" />
<br />
<button class="btn btn-primary" type="submit">Save</button>
</EditForm>
@* <label for="TemperatureC">Temperacure(℃)</label>
<input class="form-control" type="text" placeholder="Temperacure(℃)" @bind="_addForecast.TemperatureC"/>
<label for="Summary">Summary</label>
<input class="form-control" type="text" placeholder="Summary" @bind="_addForecast.Summary" />
<br/>
<button class="btn btn-primary" @onclick="SaveForecast">Save</button> *@
</div>
</div>
</div>
</div>
}
2 years ago
}
@code {
2 years ago
private List<WeatherForecast>? _forecasts;
private bool _showPopup = false;
private WeatherForecast _addForecast;
2 years ago
protected override async Task OnInitializedAsync()
{
2 years ago
_forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}
private void AddNewForecast()
{
_showPopup = true;
_addForecast = new WeatherForecast();
}
private void ClosePopup()
{
_showPopup = false;
}
private void SaveForecast()
{
_addForecast.Date = DateTime.Now;
_forecasts.Add(_addForecast);
_showPopup = false;
2 years ago
}
}