Prvi commit
This commit is contained in:
72
EveryThing/Pages/Notes/Create.cshtml.cs
Normal file
72
EveryThing/Pages/Notes/Create.cshtml.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
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;
|
||||
|
||||
namespace EveryThing.Pages.Notes
|
||||
{
|
||||
public class CreateModel : PageModel
|
||||
{
|
||||
private readonly EveryThing.Data.ApplicationDbContext _context;
|
||||
|
||||
public CreateModel(EveryThing.Data.ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IActionResult OnGet()
|
||||
{
|
||||
ViewData["IdCompanyFk"] = new SelectList(_context.CodeTableCompanies, "IdCompany", "Ceo");
|
||||
ViewData["IdEmployeeFk"] = new SelectList(_context.CodeTableEmployees, "IdEmployee", "BankAccount");
|
||||
ViewData["IdVehicleFk"] = new SelectList(_context.Set<Models.Vehicle.Vehicle>(), "IdVehicle", "RegistrationNumber");
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public IActionResult OnGetModal()
|
||||
{
|
||||
ViewData["IdCompanyFk"] = new SelectList(_context.CodeTableCompanies, "IdCompany", "Ceo");
|
||||
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");
|
||||
}
|
||||
|
||||
_context.GeneralNotes.Add(Note);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Partial("CreateModal");
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public GeneralNote Note { 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.GeneralNotes.Add(Note);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user