51 lines
1.4 KiB
C#
51 lines
1.4 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 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");
|
|
}
|
|
}
|
|
} |