prvi
This commit is contained in:
125
EveryThing/Pages/AdministrationCompanies/Create.cshtml
Normal file
125
EveryThing/Pages/AdministrationCompanies/Create.cshtml
Normal file
@@ -0,0 +1,125 @@
|
||||
@page
|
||||
@model EveryThing.Pages.AdministrationCompanies.CreateModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Vnos podjetja";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Podjetja /</span> Novo
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Podatki podjetja
|
||||
</h6>
|
||||
<div class="card-body">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Title" class="form-label"></label>
|
||||
<input asp-for="Company.Title" class="form-control" />
|
||||
<span asp-validation-for="Company.Title" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.ShortTitle" class="form-label"></label>
|
||||
<input asp-for="Company.ShortTitle" class="form-control" />
|
||||
<span asp-validation-for="Company.ShortTitle" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.IdCountryFk" class="form-label"></label>
|
||||
<select asp-for="Company.IdCountryFk" class="form-control" asp-items="ViewBag.IdCountryFk"></select>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.City" class="form-label"></label>
|
||||
<input asp-for="Company.City" class="form-control" />
|
||||
<span asp-validation-for="Company.City" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Street" class="form-label"></label>
|
||||
<input asp-for="Company.Street" class="form-control" />
|
||||
<span asp-validation-for="Company.Street" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.HouseNumber" class="form-label"></label>
|
||||
<input asp-for="Company.HouseNumber" class="form-control" />
|
||||
<span asp-validation-for="Company.HouseNumber" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Post" class="form-label"></label>
|
||||
<input asp-for="Company.Post" class="form-control" />
|
||||
<span asp-validation-for="Company.Post" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.TaxNumber" class="form-label"></label>
|
||||
<input asp-for="Company.TaxNumber" class="form-control" />
|
||||
<span asp-validation-for="Company.TaxNumber" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.RegistrationNumber" class="form-label"></label>
|
||||
<input asp-for="Company.RegistrationNumber" class="form-control" />
|
||||
<span asp-validation-for="Company.RegistrationNumber" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Email" class="form-label"></label>
|
||||
<input asp-for="Company.Email" class="form-control" />
|
||||
<span asp-validation-for="Company.Email" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Bank" class="form-label"></label>
|
||||
<input asp-for="Company.Bank" class="form-control" />
|
||||
<span asp-validation-for="Company.Bank" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Iban" class="form-label"></label>
|
||||
<input asp-for="Company.Iban" class="form-control" />
|
||||
<span asp-validation-for="Company.Iban" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.SwiftBic" class="form-label"></label>
|
||||
<input asp-for="Company.SwiftBic" class="form-control" />
|
||||
<span asp-validation-for="Company.SwiftBic" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group mb-0">
|
||||
<label asp-for="Company.Ceo" class="form-label"></label>
|
||||
<input asp-for="Company.Ceo" class="form-control" />
|
||||
<span asp-validation-for="Company.Ceo" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.LogoFileName" class="form-label"></label>
|
||||
<input asp-for="Company.LogoFileName" class="form-control" />
|
||||
<span asp-validation-for="Company.LogoFileName" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<button type="submit" class="btn btn-primary">Dodaj podjetje</button>
|
||||
<a asp-page="Index" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
}
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
168
EveryThing/Pages/AdministrationCompanies/Edit.cshtml
Normal file
168
EveryThing/Pages/AdministrationCompanies/Edit.cshtml
Normal file
@@ -0,0 +1,168 @@
|
||||
@page
|
||||
@model EveryThing.Pages.AdministrationCompanies.EditModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Urejanje podjetja";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<form method="post">
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Podjetja /</span> Urejanje
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Podatki podjetja
|
||||
</h6>
|
||||
<div class="card-body">
|
||||
<input type="hidden" asp-for="Company.IdCompany" />
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Title" class="form-label"></label>
|
||||
<input asp-for="Company.Title" class="form-control" />
|
||||
<span asp-validation-for="Company.Title" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.ShortTitle" class="form-label"></label>
|
||||
<input asp-for="Company.ShortTitle" class="form-control" />
|
||||
<span asp-validation-for="Company.ShortTitle" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.IdCountryFk" class="form-label"></label>
|
||||
<select asp-for="Company.IdCountryFk" class="form-control" asp-items="ViewBag.IdCountryFk"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.City" class="form-label"></label>
|
||||
<input asp-for="Company.City" class="form-control" />
|
||||
<span asp-validation-for="Company.City" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Street" class="form-label"></label>
|
||||
<input asp-for="Company.Street" class="form-control" />
|
||||
<span asp-validation-for="Company.Street" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.HouseNumber" class="form-label"></label>
|
||||
<input asp-for="Company.HouseNumber" class="form-control" />
|
||||
<span asp-validation-for="Company.HouseNumber" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.PostNumber" class="form-label"></label>
|
||||
<input asp-for="Company.PostNumber" class="form-control" />
|
||||
<span asp-validation-for="Company.PostNumber" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Post" class="form-label"></label>
|
||||
<input asp-for="Company.Post" class="form-control" />
|
||||
<span asp-validation-for="Company.Post" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.TaxNumber" class="form-label"></label>
|
||||
<input asp-for="Company.TaxNumber" class="form-control" />
|
||||
<span asp-validation-for="Company.TaxNumber" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.RegistrationNumber" class="form-label"></label>
|
||||
<input asp-for="Company.RegistrationNumber" class="form-control" />
|
||||
<span asp-validation-for="Company.RegistrationNumber" class="text-danger"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Email" class="form-label"></label>
|
||||
<input asp-for="Company.Email" class="form-control" />
|
||||
<span asp-validation-for="Company.Email" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Ceo" class="form-label"></label>
|
||||
<input asp-for="Company.Ceo" class="form-control" />
|
||||
<span asp-validation-for="Company.Ceo" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.SwiftBic" class="form-label"></label>
|
||||
<input asp-for="Company.SwiftBic" class="form-control" />
|
||||
<span asp-validation-for="Company.SwiftBic" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Iban" class="form-label"></label>
|
||||
<input asp-for="Company.Iban" class="form-control" />
|
||||
<span asp-validation-for="Company.Iban" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Bank" class="form-label"></label>
|
||||
<input asp-for="Company.Bank" class="form-control" />
|
||||
<span asp-validation-for="Company.Bank" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.Phone" class="form-label"></label>
|
||||
<input asp-for="Company.Phone" class="form-control" />
|
||||
<span asp-validation-for="Company.Phone" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label asp-for="Company.LogoFileName" class="form-label"></label>
|
||||
<input asp-for="Company.LogoFileName" class="form-control" />
|
||||
<span asp-validation-for="Company.LogoFileName" class="text-danger"></span>
|
||||
</div>
|
||||
<div class="form-group form-check">
|
||||
<label class="form-check-label">
|
||||
<input class="form-check-input" asp-for="Company.Active" /> @Html.DisplayNameFor(model => model.Company.Active)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-footer py-3 text-right">
|
||||
<button type="submit" class="btn btn-primary">Shrani</button>
|
||||
<a asp-page="Index" class="btn btn-default">Prekliči</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Uporabniki podjetja
|
||||
</h6>
|
||||
<partial name="AdministrationUsers/IndexFrame" model="Model.User" />
|
||||
<div class="card-footer py-3 text-right">
|
||||
<a asp-page="/AdministrationUsers/Create" asp-route-idCompany="@Model.Company.IdCompany" class="btn btn-primary">Vnos uporabnika</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
|
||||
|
||||
</form>
|
||||
|
||||
@section Scripts {
|
||||
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
|
||||
|
||||
<script>
|
||||
$('[data-toggle="tooltip"]').tooltip({container: 'table'});
|
||||
</script>
|
||||
}
|
||||
87
EveryThing/Pages/AdministrationCompanies/Edit.cshtml.cs
Normal file
87
EveryThing/Pages/AdministrationCompanies/Edit.cshtml.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
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 Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using EveryThing.Models.CodeTable;
|
||||
|
||||
namespace EveryThing.Pages.AdministrationCompanies
|
||||
{
|
||||
[Authorize(Roles = "Administrator")]
|
||||
public class EditModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
|
||||
public EditModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
|
||||
{
|
||||
_context = context;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
[BindProperty]
|
||||
public CodeTableCompany Company { get; set; }
|
||||
public new IList<IdentityApplicationUser> User { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
Company = await _context.CodeTableCompanies.Include(c => c.Country).FirstOrDefaultAsync(m => m.IdCompany == id);
|
||||
User = await _userManager.Users.Include(x => x.Company).Where(x => x.IdCompanyFk == id).ToListAsync();
|
||||
ViewData["IdCompany"] = id;
|
||||
|
||||
if (Company == null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
ViewData["IdCountryFk"] = new SelectList(_context.CodeTableCountries, "IdCountry", "TranslationSlovenian");
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
if (!ModelState.IsValid)
|
||||
{
|
||||
return Page();
|
||||
}
|
||||
|
||||
_context.Attach(Company).State = EntityState.Modified;
|
||||
|
||||
try
|
||||
{
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateConcurrencyException)
|
||||
{
|
||||
if (!CompanyExists(Company.IdCompany))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
return RedirectToPage("./Index");
|
||||
}
|
||||
|
||||
private bool CompanyExists(int id)
|
||||
{
|
||||
return _context.CodeTableCompanies.Any(e => e.IdCompany == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
108
EveryThing/Pages/AdministrationCompanies/Index.cshtml
Normal file
108
EveryThing/Pages/AdministrationCompanies/Index.cshtml
Normal file
@@ -0,0 +1,108 @@
|
||||
@page
|
||||
@model EveryThing.Pages.AdministrationCompanies.IndexModel
|
||||
|
||||
@{
|
||||
ViewData["Title"] = "Podjetja";
|
||||
Layout = "~/Pages/Layouts/_Layout.cshtml";
|
||||
}
|
||||
|
||||
<h4 class="d-flex justify-content-between align-items-center w-100 font-weight-bold py-1 mb-4">
|
||||
<span>
|
||||
<span class="text-muted font-weight-light">Podjetja /</span> Pregled
|
||||
</span>
|
||||
</h4>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-12 mb-2 text-right">
|
||||
<form method="get">
|
||||
<div class="btn-group">
|
||||
<input class="form-control" type="text" name="searchString" value="@ViewData["SearchString"]" placeholder="Iskanje..." autocomplete="off">
|
||||
<button type="submit" class="btn btn-secondary" aria-label="Osveži" title="Osveži">
|
||||
<i class="opacity-75 ion ion-md-refresh"></i>
|
||||
</button>
|
||||
<div class="btn-group" title="Columns">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-label="Nastavitve" title="Nastavitve">
|
||||
<i class="opacity-75 ion ion-md-apps"></i>
|
||||
<span class="caret"></span>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-right">
|
||||
<label class="dropdown-item">
|
||||
<input type="checkbox" name="inactiveCompanies" @ViewData["InactiveCompanies"]> <span>Neaktivna podjetja</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h6 class="card-header">
|
||||
Seznam podjetij
|
||||
</h6>
|
||||
|
||||
<table class="table card-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Company[0].Title)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Company[0].City)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Company[0].Street)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Company[0].Post)
|
||||
</th>
|
||||
<th style="width: 140px;">
|
||||
@Html.DisplayNameFor(model => model.Company[0].TaxNumber)
|
||||
</th>
|
||||
<th>
|
||||
@Html.DisplayNameFor(model => model.Company[0].Email)
|
||||
</th>
|
||||
<th style="width: 80px;"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach (var item in Model.Company)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Title)
|
||||
@if (!item.Active) {<span class='badge badge-danger'>Neaktivno</span>}
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.City)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Street) @Html.DisplayFor(modelItem => item.HouseNumber)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.PostNumber) @Html.DisplayFor(modelItem => item.Post)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.RegistrationNumber)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem => item.Email)
|
||||
</td>
|
||||
<td class="text-right">
|
||||
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="Edit" asp-route-id="@item.IdCompany" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="card-footer py-3 text-right">
|
||||
<a asp-page="Create" class="btn btn-primary">Vnos podjetja</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@section Scripts {
|
||||
<script>
|
||||
$('[data-toggle="tooltip"]').tooltip({container: 'table'});
|
||||
</script>
|
||||
}
|
||||
48
EveryThing/Pages/AdministrationCompanies/Index.cshtml.cs
Normal file
48
EveryThing/Pages/AdministrationCompanies/Index.cshtml.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using EveryThing.Data;
|
||||
using EveryThing.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using EveryThing.Models.CodeTable;
|
||||
|
||||
namespace EveryThing.Pages.AdministrationCompanies
|
||||
{
|
||||
[Authorize(Roles = "Administrator")]
|
||||
public class IndexModel : PageModel
|
||||
{
|
||||
private readonly ApplicationDbContext _context;
|
||||
|
||||
public IndexModel(ApplicationDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public IList<CodeTableCompany> Company { get;set; }
|
||||
|
||||
public async Task OnGetAsync(string searchString, string inactiveCompanies)
|
||||
{
|
||||
ViewData["SearchString"] = searchString;
|
||||
ViewData["InactiveCompanies"] = inactiveCompanies == "on" ? "checked" : "";
|
||||
|
||||
Company = await _context.CodeTableCompanies
|
||||
.Include(c => c.Country).ToListAsync();
|
||||
|
||||
// Active companies
|
||||
if (string.IsNullOrEmpty(inactiveCompanies) || inactiveCompanies != "on")
|
||||
{
|
||||
Company = Company.Where(s => s.Active).ToList();
|
||||
}
|
||||
|
||||
// Search string
|
||||
if (!string.IsNullOrEmpty(searchString))
|
||||
{
|
||||
Company = Company.Where(s => s.ShortTitle.Contains(searchString) || s.Title.Contains(searchString)).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
6
EveryThing/Pages/AdministrationCompanies/Setup.cshtml
Normal file
6
EveryThing/Pages/AdministrationCompanies/Setup.cshtml
Normal file
@@ -0,0 +1,6 @@
|
||||
@page
|
||||
@model EveryThing.Pages.AdministrationCompanies.SetupModel
|
||||
@{
|
||||
ViewData["Title"] = "Odjava";
|
||||
Layout = "~/Pages/Layouts/_LayoutBlank.cshtml";
|
||||
}
|
||||
107
EveryThing/Pages/AdministrationCompanies/Setup.cshtml.cs
Normal file
107
EveryThing/Pages/AdministrationCompanies/Setup.cshtml.cs
Normal file
@@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using EveryThing.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace EveryThing.Pages.AdministrationCompanies
|
||||
{
|
||||
[Authorize(Roles = "Administrator")]
|
||||
public class SetupModel : PageModel
|
||||
{
|
||||
private readonly UserManager<IdentityApplicationUser> _userManager;
|
||||
private readonly SignInManager<IdentityApplicationUser> _signInManager;
|
||||
private readonly RoleManager<IdentityApplicationRole> _roleManager;
|
||||
private readonly ILogger<SetupModel> _logger;
|
||||
|
||||
public SetupModel(UserManager<IdentityApplicationUser> userManager, SignInManager<IdentityApplicationUser> signInManager, ILogger<SetupModel> logger, RoleManager<IdentityApplicationRole> roleManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_signInManager = signInManager;
|
||||
_logger = logger;
|
||||
_roleManager = roleManager;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
//TODO osnovno podjetje?
|
||||
var rolesDefinitions = new List<(string RoleName, string RoleDescription)>
|
||||
{
|
||||
("TransportThingUser", "TransporThing uporabniki"),
|
||||
("ProjecThingUser", "ProjecThing uporabniki"),
|
||||
("InvoicingUser", "Fakturiranje uporabniki"),
|
||||
("Administrator", "Administratorji"),
|
||||
};
|
||||
|
||||
foreach (var roleDefinition in rolesDefinitions)
|
||||
{
|
||||
if (!_roleManager.RoleExistsAsync(roleDefinition.RoleName).Result)
|
||||
{
|
||||
var role = new IdentityApplicationRole
|
||||
{
|
||||
Name = roleDefinition.RoleName,
|
||||
Description = roleDefinition.RoleDescription
|
||||
};
|
||||
|
||||
_roleManager.CreateAsync(role).Wait();
|
||||
}
|
||||
}
|
||||
|
||||
if (_userManager.FindByNameAsync("admin") == null)
|
||||
{
|
||||
IdentityApplicationUser identityApplicationUser = new IdentityApplicationUser
|
||||
{
|
||||
Name = "Master",
|
||||
Surname = "Admin",
|
||||
UserName = "admin",
|
||||
NormalizedUserName = "admin",
|
||||
Email = "admin@domain.com",
|
||||
NormalizedEmail = "admin@domain.com",
|
||||
EmailConfirmed = true,
|
||||
DateCreated = DateTime.Now,
|
||||
DateValidUntil = DateTime.MaxValue,
|
||||
PhoneNumber = "123456789",
|
||||
PhoneNumberConfirmed = true,
|
||||
Active = true,
|
||||
IdCompanyFk = 1
|
||||
};
|
||||
|
||||
var result = await _userManager.CreateAsync(identityApplicationUser, "Master#Admin22!");
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
_userManager.AddToRoleAsync(identityApplicationUser, "Administrator").Wait();
|
||||
//return RedirectToPage("/Administration/Users/Index");
|
||||
}
|
||||
else
|
||||
{
|
||||
//ModelState.AddModelError("", string.Join(",", identityResult.Errors.Select(x => x.Description)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return RedirectToPage("/User/Login");
|
||||
}
|
||||
|
||||
//public async Task<IActionResult> OnPostAsync(string returnUrl = null)
|
||||
//{
|
||||
// var user = await _userManager.GetUserAsync(User);
|
||||
|
||||
// await _signInManager.SignOutAsync();
|
||||
|
||||
// _logger.LogInformation($"Logout: {user.Name} {user.Surname} - {user.Company.Title}");
|
||||
|
||||
// if (returnUrl != null)
|
||||
// {
|
||||
// return LocalRedirect(returnUrl);
|
||||
// }
|
||||
|
||||
// return RedirectToPage();
|
||||
//}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user