prvi
This commit is contained in:
51
EveryThing/Pages/AdministrationCompanies/Create.cshtml.cs
Normal file
51
EveryThing/Pages/AdministrationCompanies/Create.cshtml.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
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 Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using EveryThing.Models.CodeTable;
|
||||
|
||||
namespace EveryThing.Pages.AdministrationCompanies
|
||||
{
|
||||
[Authorize(Roles = "Administrator")]
|
||||
public class CreateModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public CreateModel(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public CodeTableCompany Company { get; set; }
|
||||
|
||||
public IActionResult OnGet()
|
||||
{
|
||||
ViewData["IdCountryFk"] = new SelectList(_context.CodeTableCountries, "IdCountry", "Title");
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
ViewData["IdCountryFk"] = new SelectList(_context.CodeTableCountries, "IdCountry", "Title");
|
||||
|
||||
return Page();
|
||||
}
|
||||
Company.Active = true;
|
||||
_context.CodeTableCompanies.Add(Company);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user