using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Mvc.Rendering;
using RazorPages.Data;
using RazorPages.Models;

namespace RazorPages.Pages.Climbs
{
    public class CreateModel : PageModel
    {
        private readonly RazorPages.Data.RazorPagesClimbContext _context;

        public CreateModel(RazorPages.Data.RazorPagesClimbContext context)
        {
            _context = context;
        }

        public IActionResult OnGet()
        {
            return Page();
        }

        [BindProperty]
        public Climb Climb { get; set; } = default!;

        // For more information, see https://aka.ms/RazorPagesCRUD.
        public async Task<IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return Page();
            }

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

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