| Name | Message | Date |
|---|---|---|
| π Date.razor | 1 month ago | |
| π Date.razor.css | 1 month ago | |
| π Export.razor | 1 month ago | |
| π Export.razor.css | 1 month ago | |
| π Index.razor | 1 month ago | |
| π Index.razor.css | 1 month ago | |
| π Kokbok.razor | 2 days ago | |
| π Kokbok.razor.cs | 2 days ago | |
| π Kokbok.razor.css | 2 days ago | |
| π Login.razor | 1 month ago | |
| π Logout.razor | 1 month ago | |
| π Participants.razor | 1 month ago | |
| π Participants.razor.css | 1 month ago | |
| π Questions.razor | 1 month ago | |
| π Questions.razor.css | 1 month ago |
📄
MatDenDagen/Components/Pages/Admin/Kokbok.razor.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; using System.Threading; using System.Threading.Tasks; using MatDenDagen.Infrastructure.Storage.BlobStorage; using MatDenDagen.Infrastructure.Storage.Database; using MatDenDagen.Models; using Microsoft.AspNetCore.Components; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; namespace MatDenDagen.Components.Pages.Admin; public partial class Kokbok(BlobStorageService blobService, QuestionnaireContext questionnaireContext) { [CascadingParameter] private HttpContext? HttpContext { get; set; } private bool success; private string? errorMessage; private List<Cookbook> cookbooks = []; protected override async Task OnInitializedAsync() { var cancellationToken = HttpContext?.RequestAborted ?? CancellationToken.None; cookbooks = await questionnaireContext.Cookbooks.OrderBy(c => c.Id).ToListAsync(cancellationToken); if (HttpContext?.Request.Method is not "POST") return; var form = HttpContext.Request.Form; var id = form["id"].FirstOrDefault()?.Trim(); if (id is null || !validId.IsMatch(id)) { errorMessage = "Ogiltigt ID. AnvΓ€nd bokstΓ€ver, siffror, bindestreck och understreck."; return; } var file = form.Files.GetFile("file"); if (file is null || file.Length == 0) { errorMessage = "Ingen PDF-fil vald."; return; } if (!file.FileName.EndsWith(".pdf", StringComparison.OrdinalIgnoreCase)) { errorMessage = "Endast PDF-filer Γ€r tillΓ₯tna."; return; } await using var stream = file.OpenReadStream(); var result = await blobService.SaveBlob(stream, cancellationToken); var existing = await questionnaireContext.Cookbooks.FindAsync([id], cancellationToken); if (existing is not null) { blobService.DeleteBlob(existing.BlobId); existing.BlobId = result.Id; existing.FileName = file.FileName; } else { questionnaireContext.Cookbooks.Add( new Cookbook { Id = id, BlobId = result.Id, FileName = file.FileName, } ); } await questionnaireContext.SaveChangesAsync(cancellationToken); cookbooks = await questionnaireContext.Cookbooks.OrderBy(c => c.Id).ToListAsync(cancellationToken); success = true; } [GeneratedRegex(@"^[a-zA-Z0-9][a-zA-Z0-9_-]*$")] private static partial Regex validId { get; } }