-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProcessedFiles.cshtml.cs
More file actions
79 lines (66 loc) · 2.62 KB
/
ProcessedFiles.cshtml.cs
File metadata and controls
79 lines (66 loc) · 2.62 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Identity.Abstractions;
using Microsoft.Identity.Client;
namespace Visualiser.Pages
{
public class ProcessedFilesModel(IDownstreamApi api) : PageModel
{
// Bindable property for the view
public ProcessedFileDto[] ProcessedFiles { get; private set; } = Array.Empty<ProcessedFileDto>();
public ProcessedFileDto[] OffLocFiles => ProcessedFiles
.Where(c => c.FileName.StartsWith("cfoextract", StringComparison.CurrentCultureIgnoreCase) == false)
.OrderByDescending(c => c.ValidFrom)
.ToArray();
public ProcessedFileDto[] DeliusFiles => ProcessedFiles
.Where(c => c.FileName.StartsWith("cfoextract", StringComparison.CurrentCultureIgnoreCase))
.OrderByDescending(c => c.ValidFrom)
.ToArray();
public async Task<IActionResult> OnGetAsync()
{
HttpResponseMessage? response = null;
try
{
response = await api.CallApiForUserAsync("DMS", opts => opts.RelativePath = "Visualisation/processedfiles");
}
catch (Exception ex) when (ex.InnerException is MsalUiRequiredException { ErrorCode: MsalError.UserNullError })
{
return Challenge();
}
if (response is null)
{
ModelState.AddModelError(string.Empty, "No response");
return Page();
}
if (response.IsSuccessStatusCode)
{
try
{
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true
};
var json = await response.Content.ReadAsStringAsync();
ProcessedFiles = JsonSerializer.Deserialize<ProcessedFileDto[]>(json, options)
?? Array.Empty<ProcessedFileDto>();
}
catch(JsonException)
{
ModelState.AddModelError(string.Empty, $"Failed to parse API response");
}
}
return Page();
}
}
public class ProcessedFileDto
{
public required string FileName { get; set; }
public DateTime ValidFrom { get; set; }
public required string Status { get; set; }
}
}