using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using EFCore_Kontext;
using EFC_GO;

namespace ASPNETCore_NETCore.Pages.RazorPages
{
 public class FlugsucheModel : PageModel
 {
  public string Meldung { get; set; }

  WWWingsContext ctx;
  public FlugsucheModel(WWWingsContext ctx) // ctx per DI!
  {
   this.ctx = ctx;
  }

  public void OnGet()
  {
   this.Meldung += "OnGet<br>";
  }

  [BindProperty]
  public string SucheingabeOrt { get; set; } = "Berlin";
  [BindProperty]
  public List<Flug> FlugSet { get; set; }
  [BindProperty]
  public string Ort { get; set; }
  [BindProperty]
  public int GesamtAnzahl { get; set; }

  public IActionResult OnPostOrt()
  {
   this.Meldung += "OnPostOrt<br>";
   this.FlugSet = ctx.Flug.Where(x => x.Abflugort == this.Ort).ToList();
   this.Ort = this.SucheingabeOrt;
   this.GesamtAnzahl = ctx.Flug.Count();
   return Page();
  }


  //public async Task OnGetAsync()
  //{
  // this.Meldung += "OnGetAsync<br>";
  //}
  //public async Task<IActionResult> OnPostAsync()
  //{
  // this.Meldung += "OnPostAsync: " + this.Name + "<br>";
  // await Task.Delay(1);
  // return Page();
  //}
 }
}