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 EveryThing.Data; using EveryThing.Models; using EveryThing.Models.Vehicle; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Authorization; namespace EveryThing.Pages.FleetIssues { [Authorize] public class CreateModel : PageModel { private readonly ApplicationDbContext _context; private readonly UserManager _userManager; public CreateModel(ApplicationDbContext context, UserManager userManager) { _context = context; _userManager = userManager; } [BindProperty] public VehicleIssue Issue { get; set; } public IActionResult OnGetModal() { ViewData["IdEmployeeFk"] = new SelectList(_context.CodeTableEmployees, "IdEmployee", "BankAccount"); ViewData["IdVehicleFk"] = new SelectList(_context.Set(), "IdVehicle", "RegistrationNumber"); return Partial("CreateModal"); } public async Task OnPostModalAsync() { //if (!ModelState.IsValid) //{ // return Partial("CreateModal"); //} var aa = _userManager.GetUserAsync(User); _context.VehicleIssues.Add(Issue); await _context.SaveChangesAsync(); return Partial("CreateModal"); } public IActionResult OnGet() { ViewData["IdEmployeeFk"] = new SelectList(_context.CodeTableEmployees, "IdEmployee", "BankAccount"); ViewData["IdVehicleFk"] = new SelectList(_context.Set(), "IdVehicle", "RegistrationNumber"); return Page(); } public async Task OnPostAsync() { if (!ModelState.IsValid) { return Page(); } _context.VehicleIssues.Add(Issue); await _context.SaveChangesAsync(); return RedirectToPage("./Index"); } } }