63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
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 DeleteModel : PageModel
|
|
{
|
|
private readonly Catalog26.Data.Catalog26Context _context;
|
|
|
|
public DeleteModel(Catalog26.Data.Catalog26Context context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
[BindProperty]
|
|
public TDSPriceAvailability TDSPriceAvailability { get; set; } = default!;
|
|
// public string ErrorMessage { get; set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var tdspriceavailability = await _context.TDSCatalogItems.FirstOrDefaultAsync(m => m.Id == id);
|
|
|
|
if (tdspriceavailability is not null)
|
|
{
|
|
TDSPriceAvailability = tdspriceavailability;
|
|
|
|
return Page();
|
|
}
|
|
|
|
return NotFound();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
var tdspriceavailability = await _context.TDSCatalogItems.FindAsync(id);
|
|
if (tdspriceavailability != null)
|
|
{
|
|
TDSPriceAvailability = tdspriceavailability;
|
|
_context.TDSCatalogItems.Remove(TDSPriceAvailability);
|
|
await _context.SaveChangesAsync();
|
|
}
|
|
|
|
return RedirectToPage("./Index");
|
|
}
|
|
}
|