PlanTempusApp/PlanTempus.DeprecatedApplication/Components/OrganizationViewComponent.cs
Janus C. H. Knudsen 7fc1ae0650 WIP
2026-01-10 20:39:17 +01:00

43 lines
No EOL
1.4 KiB
C#

using Microsoft.AspNetCore.Mvc;
using Microsoft.ApplicationInsights;
namespace PlanTempus.Application.Components
{
public class OrganizationViewComponent : ApiViewComponentBase
{
private readonly TelemetryClient _telemetry;
public OrganizationViewComponent(
IHttpClientFactory httpClientFactory,
TelemetryClient telemetry)
: base(httpClientFactory, telemetry)
{
_telemetry = telemetry;
}
public async Task<IViewComponentResult> InvokeAsync(int organizationId, bool showDetailedView = true)
{
_telemetry.TrackEvent($"{GetType().Name}Invoked", new Dictionary<string, string>
{
["OrganizationId"] = organizationId.ToString(),
["ShowDetailedView"] = showDetailedView.ToString()
});
var organization = await GetJObjectFromApiAsync($"/api/organization/get/{organizationId}");
if (organization == null)
return HandleError("Organization not found");
ViewBag.ShowDetailedView = showDetailedView;
_telemetry.TrackEvent("Viewed", new Dictionary<string, string>
{
["OrganizationId"] = organizationId.ToString(),
["Name"] = organization["name"]?.ToString()
});
return View(organization);
}
}
}