Prvi commit

This commit is contained in:
David Štaleker
2023-05-12 09:00:07 +02:00
parent d3ffe93e42
commit 03b92525d7
14757 changed files with 9251133 additions and 53 deletions

View File

@@ -0,0 +1,111 @@
@page
@model EveryThing.Pages.CodeTableVehicles.CreateEditModel
@{
ViewData["Title"] = "Create";
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">
Vozni park /
</span> @if ((bool)ViewData["Edit"])
{
<span>Urejanje</span>
}
else
{
<span>Nov</span>
}
</span>
</h4>
<div class="card">
<h6 class="card-header">
Podatki vozila
</h6>
<div class="card-body">
<div class="row">
<div class="col-4">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<input type="hidden" asp-for="@ViewData["Edit"]" name="type"/>
<div class="form-group">
<label asp-for="Vehicle.Title" class="control-label"></label>
<input asp-for="Vehicle.Title" class="form-control"/>
<span asp-validation-for="Vehicle.Title" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Vehicle.IdMakeFk" class="control-label"></label>
<select asp-for="Vehicle.IdMakeFk" class="form-control" asp-items="ViewBag.VehicleMake"></select>
</div>
<div class="form-group">
<label asp-for="Vehicle.Model" class="control-label"></label>
<input asp-for="Vehicle.Model" class="form-control"/>
</div>
<div class="form-group">
<label asp-for="Vehicle.RegistrationNumber" class="control-label"></label>
<input asp-for="Vehicle.RegistrationNumber" class="form-control"/>
<span asp-validation-for="Vehicle.RegistrationNumber" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Vehicle.IdVehicleTypeFk" class="control-label"></label>
<select asp-for="Vehicle.IdVehicleTypeFk" class="form-control" asp-items="ViewBag.VehicleType"></select>
<span asp-validation-for="Vehicle.IdVehicleTypeFk" class="text-danger"></span>
</div>
<div class="form-group form-check">
<label class="form-check-label">
<input class="form-check-input" asp-for="Vehicle.Active"/> @Html.DisplayNameFor(model => model.Vehicle.Active)
</label>
</div>
</div>
<div class="col-4">
<div class="form-group">
<label asp-for="Vehicle.Year" class="control-label"></label>
<input asp-for="Vehicle.Year" class="form-control" />
<span asp-validation-for="Vehicle.Year" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Vehicle.VinNumber" class="control-label"></label>
<input asp-for="Vehicle.VinNumber" class="form-control" />
<span asp-validation-for="Vehicle.VinNumber" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Vehicle.EngineNumber" class="control-label"></label>
<input asp-for="Vehicle.EngineNumber" class="form-control" />
</div>
<div class="form-group">
<label asp-for="Vehicle.IdFuelTypeFk" class="control-label"></label>
<select asp-for="Vehicle.IdFuelTypeFk" class="form-control" asp-items="ViewBag.FuelType"></select>
</div>
<div class="form-group">
<label asp-for="Vehicle.VehicleMeterType" class="control-label"></label>
<select asp-for="Vehicle.VehicleMeterType" class="form-control" asp-items="Html.GetEnumSelectList<Models.Vehicle.VehicleMeterType>()"></select>
<span asp-validation-for="Vehicle.VehicleMeterType" class="text-danger"></span>
</div>
<div class="form-group">
<label asp-for="Vehicle.IdDepartementFk" class="control-label"></label>
<select asp-for="Vehicle.IdDepartementFk" class="form-control" asp-items="ViewBag.Department"></select>
</div>
</div>
<div class="col-4">
<label asp-for="Vehicle.Note" class="control-label"></label>
@Html.TextAreaFor(model => model.Vehicle.Note, new { @class = "form-control", style = "resize:none; height: 455px;"})
</div>
</div>
<div class="row" style="margin-top:10px;">
<div class="col-6">
<div class="form-group">
<input type="submit" value="Shrani" class="btn btn-primary" />
<a class="btn btn-default" asp-page="./Index">Nazaj na seznam</a>
</div>
</div>
</div>
</div>
</div>
</form>
@section Scripts {
@{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
}

View File

@@ -0,0 +1,109 @@
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;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using NuGet.Protocol.Plugins;
using DocumentFormat.OpenXml.Bibliography;
using Microsoft.EntityFrameworkCore;
namespace EveryThing.Pages.CodeTableVehicles
{
[Authorize(Roles = "Administrator,TransportThingUser")]
public class CreateEditModel : PageModel
{
private readonly ApplicationDbContext _context;
private readonly UserManager<IdentityApplicationUser> _userManager;
public CreateEditModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
{
_context = context;
_userManager = userManager;
}
[BindProperty]
public Vehicle Vehicle { get; set; }
public async Task<IActionResult> OnGetAsync(bool edit, int? id)
{
var user = _userManager.GetUserAsync(User).Result;
ViewData["Edit"] = edit;
if (edit)
{
if (id == null)
{
return NotFound();
}
Vehicle = await _context.Vehicles.FirstOrDefaultAsync(x => x.IdCompanyFk == user.IdCompanyFk
&& x.IdVehicle == id);
if (Vehicle == null)
{
return NotFound();
}
}
ViewData["VehicleType"] = new SelectList(_context.VehicleTypes
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active), "IdVehicleType", "Title");
ViewData["VehicleMake"] = new SelectList(_context.VehicleMakes
.Where(x => x.IdCompanyFk == user.IdCompanyFk && x.Active), "IdVehicleMake", "Title");
ViewData["FuelType"] = new SelectList(_context.VehicleFuelTypes
.Where(x => x.IdCompanyFk == user.IdCompanyFk), "IdVehicleFuelType", "Title");
ViewData["Department"] = new SelectList(_context.CodeTableDepartements
.Where(x => x.IdCompanyFk == user.IdCompanyFk), "IdDepartement", "Title");
return Page();
}
// To protect from over-posting attacks, see https://aka.ms/RazorPagesCRUD
public async Task<IActionResult> OnPostAsync(bool edit)
{
if (!ModelState.IsValid)
{
return Page();
}
if (edit)
{
_context.Attach(Vehicle).State = EntityState.Modified;
try
{
await _context.SaveChangesAsync();
}
catch (DbUpdateConcurrencyException)
{
if (!VehicleExists(Vehicle.IdVehicle))
{
return NotFound();
}
throw;
}
}
else
{
//Add new
_context.Vehicles.Add(Vehicle);
await _context.SaveChangesAsync();
}
return RedirectToPage("./Index");
}
private bool VehicleExists(int id)
{
return _context.Vehicles.Any(e => e.IdVehicle == id);
}
}
}

View File

@@ -0,0 +1,139 @@
@page
@model EveryThing.Pages.CodeTableVehicles.IndexModel
@{
ViewData["Title"] = "Index";
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">Vozni park / </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" asp-route-type="@ViewData["Type"]">
<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="inactiveVehicles" @ViewData["InactiveVehicles"]> <span>Neaktivna vozila</span>
</label>
</div>
</div>
</div>
</form>
</div>
</div>
<div class="card">
<table class="table card-table">
<thead>
<tr>
@*<th style="width: 200px;">#</th>*@
<th style="width: auto;">
@Html.DisplayNameFor(modelItem => modelItem.Vehicles[0].Title)
</th>
<th style="width: auto;">
@Html.DisplayNameFor(modelItem => modelItem.Vehicles[0].RegistrationNumber)
</th>
<th style="width: 100px">
@Html.DisplayNameFor(modelItem => modelItem.Vehicles[0].Active)
</th>
<th style="width: 120px;"></th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Vehicles)
{
<tr data-idvehicle="@item.IdVehicle">
<td>
@Html.DisplayFor(modelItem => item.Title)
</td>
<td>
@Html.DisplayFor(modelItem => item.RegistrationNumber)
</td>
<td>
@Html.DisplayFor(modelItem => item.Active)
</td>
<td>
<a class="btn btn-xs icon-btn btn-outline-secondary borderless" asp-page="Edit" asp-route-id="true" asp-route-id="@item.IdVehicle" data-toggle="tooltip" data-placement="top" title="Urejanje" data-state="secondary"><i class="fas fa-pencil-alt"></i></a>
<a class="btn btn-xs icon-btn btn-outline-danger borderless" data-state="danger" href='javascript:;' onclick="deleteVehicle(this)"><i class="fas fa-times"></i></a>
</td>
</tr>
}
</tbody>
</table>
<div class="card-footer py-3 text-right">
<a asp-page="CreateEdit" asp-route-edit="false" class="btn btn-primary">Vnos novega</a>
</div>
</div>
@Html.AntiForgeryToken()
@section Scripts {
<script>
$('[data-toggle="tooltip"]').tooltip({ container: 'table' });
function deleteVehicle(element) {
let row = $(element).parent().parent();
let idInvoice = $(row).attr('data-idinvoice');
let invoiceNumber = $(row).attr('data-number');
Swal.fire({
title: `Izbrišem dokument ${invoiceNumber}?`,
text: "Tega dejanja ni možno razveljaviti!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Da, izbriši!',
cancelButtonText: 'Prekliči!'
}).then((result) => {
if (result.isConfirmed) {
$.blockUI();
$.ajax({
type: "DELETE",
beforeSend: function (xhr) {
xhr.setRequestHeader("XSRF-TOKEN",
$('input:hidden[name="__RequestVerificationToken"]').val());
},
url: "/Invoices/Index/?handler=Invoice",
data: {
idInvoice
},
success: function (data) {
$.unblockUI();
if (data.successful) {
$(row).remove();
} else {
console.log(data);
Swal.fire('Napaka pri brisanju dokumenta',
data.error,
'error');
}
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr);
alert(xhr.responseText);
$.unblockUI();
}
});
}
});
}
</script>
}

View 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.EntityFrameworkCore;
using EveryThing.Data;
using EveryThing.Models;
using EveryThing.Models.Vehicle;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using EveryThing.Models.Invoice;
namespace EveryThing.Pages.CodeTableVehicles
{
[Authorize(Roles = "Administrator,TransportThingUser")]
public class IndexModel : PageModel
{
private readonly ApplicationDbContext _context;
private readonly UserManager<IdentityApplicationUser> _userManager;
public IndexModel(ApplicationDbContext context, UserManager<IdentityApplicationUser> userManager)
{
_context = context;
_userManager = userManager;
}
public IList<Vehicle> Vehicles { get;set; }
public async Task OnGetAsync(string searchString, string inactiveVehicles)
{
var user = _userManager.GetUserAsync(User).Result;
ViewData["SearchString"] = searchString;
ViewData["InactiveVehicles"] = inactiveVehicles == "on" ? "checked" : "";
Vehicles = await _context.Vehicles
.Where(x => x.IdCompanyFk == user.IdCompanyFk)
.OrderBy(x => x.Active)
.ThenBy(x => x.Title)
.ToListAsync();
// Search string
if (!string.IsNullOrEmpty(searchString))
{
Vehicles = Vehicles.Where(s => s.Title.Contains(searchString)).ToList();
}
}
}
}