76 lines
2.3 KiB
C#
76 lines
2.3 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.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<IdentityApplicationUser> _userManager;
|
|
|
|
public CreateModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> 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<Models.Vehicle.Vehicle>(), "IdVehicle", "RegistrationNumber");
|
|
|
|
return Partial("CreateModal");
|
|
}
|
|
|
|
public async Task<IActionResult> 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<Models.Vehicle.Vehicle>(), "IdVehicle", "RegistrationNumber");
|
|
|
|
return Page();
|
|
}
|
|
|
|
public async Task<IActionResult> OnPostAsync()
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return Page();
|
|
}
|
|
|
|
_context.VehicleIssues.Add(Issue);
|
|
await _context.SaveChangesAsync();
|
|
|
|
return RedirectToPage("./Index");
|
|
}
|
|
}
|
|
} |