public async Task OnGetAsync() { ForecastPeriods = await _context.ForecastPeriods.ToListAsync(); ForecastPeriods.Reverse(); AllVerified = await _context.VerifiedForecasts.ToListAsync(); }
public async Task <IActionResult> OnGetAsync(int?FPid) { ForecastPeriods = await _context.ForecastPeriods.ToListAsync(); ForecastPeriods.Reverse(); if (FPid != null) { CurrentPeriod = await _context.ForecastPeriods.FindAsync(FPid); PersonalForecasts = await _context.Forecasts.Where(x => x.ForecastPeriodID == FPid).ToListAsync(); SelectedForePeriodID = (int)FPid; if (PersonalForecasts.Count == 0 || PersonalForecasts == null) { Forecast tempForecast = new Forecast() { ForecastPeriod = CurrentPeriod, ForecastTime = 12, ForecastPeriodID = (int)FPid }; _context.Forecasts.Add(tempForecast); tempForecast = new Forecast() { ForecastPeriod = CurrentPeriod, ForecastTime = 24, ForecastPeriodID = (int)FPid }; _context.Forecasts.Add(tempForecast); tempForecast = new Forecast() { ForecastPeriod = CurrentPeriod, ForecastTime = 36, ForecastPeriodID = (int)FPid }; _context.Forecasts.Add(tempForecast); tempForecast = new Forecast() { ForecastPeriod = CurrentPeriod, ForecastTime = 48, ForecastPeriodID = (int)FPid }; _context.Forecasts.Add(tempForecast); tempForecast = new Forecast() { ForecastPeriod = CurrentPeriod, ForecastTime = 60, ForecastPeriodID = (int)FPid }; _context.Forecasts.Add(tempForecast); await _context.SaveChangesAsync(); PersonalForecasts = await _context.Forecasts.Where(x => x.ForecastPeriodID == FPid).ToListAsync(); } } return(Page()); }