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

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

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

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

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

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

            _context.Apartments.Add(Apartment);
            await _context.SaveChangesAsync();

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