Files
everything2/EveryThing/Pages/FleetFueling/Create.cshtml.cs
David Štaleker 03b92525d7 Prvi commit
2023-05-12 09:00:07 +02:00

51 lines
1.7 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.Vehicle;
namespace EveryThing.Pages.FleetFueling
{
public class CreateModel : PageModel
{
private readonly ApplicationDbContext _context;
public CreateModel(ApplicationDbContext context)
{
_context = context;
}
public IActionResult OnGet()
{
ViewData["IdCountryFk"] = new SelectList(_context.CodeTableCountries, "IdCountry", "Title");
ViewData["IdEmployeeFk"] = new SelectList(_context.CodeTableEmployees, "IdEmployee", "BankAccount");
ViewData["IdVehicleFk"] = new SelectList(_context.Vehicles, "IdVehicle", "RegistrationNumber");
ViewData["IdVehicleFuelTypeFk"] = new SelectList(_context.VehicleFuelTypes, "IdVehicleFuelType", "Title");
ViewData["IdVehicleFuelingCardFk"] = new SelectList(_context.VehicleFuelingCards, "IdFuelingCard", "CardNumber");
return Page();
}
[BindProperty]
public Models.Vehicle.VehicleFueling VehicleFueling { get; set; }
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
// more details see https://aka.ms/RazorPagesCRUD.
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
_context.VehicleFuelings.Add(VehicleFueling);
await _context.SaveChangesAsync();
return RedirectToPage("./Index");
}
}
}