using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.EntityFrameworkCore;
using Catalog26.Data;
using PricingCatalog.Models;

namespace Catalog26.Pages.TDSynnex;

public class DetailsModel : PageModel
{
    private readonly Catalog26.Data.Catalog26Context _context;

    public DetailsModel(Catalog26.Data.Catalog26Context context)
    {
        _context = context;
    }

    public TDSPriceAvailability TDSPriceAvailability { get; set; } = default!;

    public async Task<IActionResult> OnGetAsync(int? id)
    {
        if (id == null)
        {
            return NotFound();
        }

        var tdspriceavailability = await _context.TDSCatalogItems
            .AsNoTracking()
            .FirstOrDefaultAsync(m => m.Id == id);

        if (tdspriceavailability is not null)
        {
            TDSPriceAvailability = tdspriceavailability;

            return Page();
        }

        return NotFound();
    }
}
