Adding print
This commit is contained in:
42
pointMaster/Controllers/PrintController.cs
Normal file
42
pointMaster/Controllers/PrintController.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using pointMaster.Data;
|
||||
using pointMaster.Models;
|
||||
using QRCoder;
|
||||
using System.Drawing;
|
||||
|
||||
namespace pointMaster.Controllers
|
||||
{
|
||||
public class PrintController : Controller
|
||||
{
|
||||
private readonly DataContext context;
|
||||
|
||||
public PrintController(DataContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Patruljer()
|
||||
{
|
||||
var vm = new PrintPatruljerModel();
|
||||
|
||||
vm.patruljer = await context.Patruljer.Include(x => x.PatruljeMedlems).ToListAsync();
|
||||
|
||||
foreach (var item in vm.patruljer)
|
||||
{
|
||||
QRCodeGenerator QrGenerator = new QRCodeGenerator();
|
||||
QRCodeData QrCodeInfo = QrGenerator.CreateQrCode("https://smallbenji.tech", QRCodeGenerator.ECCLevel.Q);
|
||||
|
||||
vm.QRcode.Add(item.Id, "data:image/png;base64," + Convert.ToBase64String(new PngByteQRCode(QrCodeInfo).GetGraphic(20)));
|
||||
}
|
||||
|
||||
return View(vm);
|
||||
}
|
||||
|
||||
}
|
||||
public class PrintPatruljerModel
|
||||
{
|
||||
public List<Patrulje> patruljer { get; set; } = null!;
|
||||
public Dictionary<int, string> QRcode { get; set; } = new Dictionary<int, string>();
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@
|
||||
}
|
||||
<h1>Patruljer</h1>
|
||||
<a asp-action="Create" asp-controller="Patrulje" class="btn btn-primary">Opret patrulje</a>
|
||||
<a asp-action="Patruljer" asp-controller="Print" class="ms-4 btn btn-secondary">Print patruljer</a>
|
||||
@foreach (var patrulje in Model.patruljeModels)
|
||||
{
|
||||
<div class="border m-4 p-4 rounded">
|
||||
|
||||
25
pointMaster/Views/Print/Patruljer.cshtml
Normal file
25
pointMaster/Views/Print/Patruljer.cshtml
Normal file
@@ -0,0 +1,25 @@
|
||||
@model pointMaster.Controllers.PrintPatruljerModel;
|
||||
@{
|
||||
Layout = "_Point";
|
||||
ViewData["Title"] = "Patruljer";
|
||||
}
|
||||
|
||||
@foreach (var patrulje in Model.patruljer)
|
||||
{
|
||||
<div class="print-card">
|
||||
<div class="patrulje-info">
|
||||
<h1>@patrulje.Name</h1>
|
||||
<p>Medlemmer:</p>
|
||||
@foreach (var medlem in patrulje.PatruljeMedlems)
|
||||
{
|
||||
<p>@medlem.Name</p>
|
||||
}
|
||||
</div>
|
||||
<div class="flex-grow"></div>
|
||||
<img src="@Model.QRcode[patrulje.Id]" width="300" height="300" />
|
||||
</div>
|
||||
}
|
||||
|
||||
<script>
|
||||
print()
|
||||
</script>
|
||||
@@ -7,6 +7,7 @@
|
||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="~/css/point.css" asp-append-version="true" />
|
||||
<link rel="stylesheet" href="~/pointMaster.styles.css" asp-append-version="true" />
|
||||
<link rel="icon" href="~/favicon.svg" />
|
||||
</head>
|
||||
<body>
|
||||
@RenderBody()
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.7" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
|
||||
<PackageReference Include="QRCoder" Version="1.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -37,3 +37,31 @@
|
||||
.sendButton .btn {
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
.print-card {
|
||||
display: flex;
|
||||
border: 1px solid black;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.print-card .patrulje-info {
|
||||
padding: 5px;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
.print-card .patrulje-info h1 {
|
||||
font-size: 4rem;
|
||||
}
|
||||
|
||||
.print-card .patrulje-info p {
|
||||
font-size: 1.75rem;
|
||||
line-height: 1rem;
|
||||
}
|
||||
|
||||
.print-card img {
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.print-card .flex-grow {
|
||||
flex-grow: 1;
|
||||
}
|
||||
Reference in New Issue
Block a user