
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RestAPI2.Models;
using System;
using System.Threading.Tasks;

namespace RestAPI2.Pages
{
    public class CreateModel : PageModel
    {
        private readonly RestAPI2.Data.HouseContext _context;

        public CreateModel(RestAPI2.Data.HouseContext context)
        {
            _context = context;
        }

        public IActionResult OnGet()
        {
            Console.WriteLine("got it");
            return Page();
        }

        [BindProperty]
        public RestAPI2.Models.House House { get; set; }

        public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }
            House.ID=House.Number;

            _context.House.Add(House);
            await _context.SaveChangesAsync();

            return RedirectToPage("./House");
        }
    }
}