-
Notifications
You must be signed in to change notification settings - Fork 0
/
Report1ComponentBase.cs
77 lines (63 loc) · 2.79 KB
/
Report1ComponentBase.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
using Dapper;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.Data.SqlClient;
using Microsoft.JSInterop;
namespace OptimizelyCmsBlazorComponentAddonsDemo.Features.BlazorTest.BlazorReport
{
public class Report1ComponentBase : ComponentBase
{
[Inject]
protected ILogger<Report1ComponentBase> Logger { get; set; }
[Inject]
protected IConfiguration Configuration { get; set; }
[Inject]
protected IJSRuntime JsRuntime { get; set; }
protected override async void OnInitialized()
{
await JsRuntime.InvokeVoidAsync("Spinner");
await JsRuntime.InvokeVoidAsync("Spinner.hide");
}
protected List<Report1ResultDto> Items { get; set; }
protected string? SearchString;
protected bool IsLoading;
protected async Task SearchForContent(MouseEventArgs e)
{
Items = new List<Report1ResultDto>();
IsLoading = true;
await JsRuntime.InvokeVoidAsync("Spinner.show");
try
{
Items.AddRange(await ListFoundContent(SearchString));
}
catch (Exception ex)
{
Logger.LogError(ex, "Something is rotten...");
}
IsLoading = false;
await JsRuntime.InvokeVoidAsync("Spinner.hide");
}
private async Task<IEnumerable<Report1ResultDto>> ListFoundContent(string searchString)
{
var list = default(IEnumerable<Report1ResultDto>);
var connectionString = Configuration.GetConnectionString("EPiServerDB");
using (var connection = new SqlConnection(connectionString))
{
list = await connection.QueryAsync<Report1ResultDto>($"SELECT fkContentID AS ContentID, (SELECT TOP 1 Name FROM tblWorkCOntent WHERE fkContentID = tCP.fkContentID ORDER BY Saved DESC) AS ContentName, (SELECT Name FROM tblPropertyDefinition WHERE pkID = tCP.fkPropertyDefinitionID) AS PropertyName, (SELECT LanguageID FROM tblLanguageBranch WHERE pkID = tCP.fkLanguageBranchID) AS LanguageCode, '' AS Link, (SELECT ContentPath FROM tblContent WHERE pkID = tCP.fkContentID) AS ContentPath FROM tblContentProperty AS tCP WHERE LongString LIKE '%{searchString}%'");
}
foreach (var item in list) {
item.Link = $"/EPiServer/CMS/#context=epi.cms.contentdata:///{item.ContentId}&viewsetting=viewlanguage:///{item.LanguageCode}";
}
return list;
}
}
public class Report1ResultDto
{
public int ContentId;
public string ContentName;
public string PropertyName;
public string LanguageCode;
public string Link;
public string ContentPath;
}
}