Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

View person alerts #837

Merged
merged 12 commits into from
Sep 25, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ public static class Fields
public const string dfeta_account_dfeta_initialteachertraining = "dfeta_account_dfeta_initialteachertraining";
public const string dfeta_account_dfeta_qualification_he = "dfeta_account_dfeta_qualification_he";
public const string incident_customer_accounts = "incident_customer_accounts";
public const string Referencedmsa_account_managingpartner = "Referencedmsa_account_managingpartner";
public const string msa_contact_managingpartner = "msa_contact_managingpartner";
public const string Referencingaccount_master_account = "account_master_account";
public const string Referencingaccount_parent_account = "account_parent_account";
public const string account_primary_contact = "account_primary_contact";
public const string lk_accountbase_createdby = "lk_accountbase_createdby";
public const string lk_accountbase_createdonbehalfby = "lk_accountbase_createdonbehalfby";
public const string lk_accountbase_modifiedby = "lk_accountbase_modifiedby";
public const string lk_accountbase_modifiedonbehalfby = "lk_accountbase_modifiedonbehalfby";
public const string Referencingmsa_account_managingpartner = "msa_account_managingpartner";
public const string system_user_accounts = "system_user_accounts";
public const string user_accounts = "user_accounts";
}
Expand Down Expand Up @@ -425,6 +428,46 @@ public System.Collections.Generic.IEnumerable<TeachingRecordSystem.Core.Dqt.Mode
}
}

/// <summary>
/// 1:N msa_account_managingpartner
/// </summary>
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("msa_account_managingpartner", Microsoft.Xrm.Sdk.EntityRole.Referenced)]
public System.Collections.Generic.IEnumerable<TeachingRecordSystem.Core.Dqt.Models.Account> Referencedmsa_account_managingpartner
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetRelatedEntities<TeachingRecordSystem.Core.Dqt.Models.Account>("msa_account_managingpartner", Microsoft.Xrm.Sdk.EntityRole.Referenced);
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.OnPropertyChanging("Referencedmsa_account_managingpartner");
this.SetRelatedEntities<TeachingRecordSystem.Core.Dqt.Models.Account>("msa_account_managingpartner", Microsoft.Xrm.Sdk.EntityRole.Referenced, value);
this.OnPropertyChanged("Referencedmsa_account_managingpartner");
}
}

/// <summary>
/// 1:N msa_contact_managingpartner
/// </summary>
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("msa_contact_managingpartner")]
public System.Collections.Generic.IEnumerable<TeachingRecordSystem.Core.Dqt.Models.Contact> msa_contact_managingpartner
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetRelatedEntities<TeachingRecordSystem.Core.Dqt.Models.Contact>("msa_contact_managingpartner", null);
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.OnPropertyChanging("msa_contact_managingpartner");
this.SetRelatedEntities<TeachingRecordSystem.Core.Dqt.Models.Contact>("msa_contact_managingpartner", null, value);
this.OnPropertyChanged("msa_contact_managingpartner");
}
}

/// <summary>
/// N:1 account_master_account
/// </summary>
Expand Down Expand Up @@ -572,6 +615,27 @@ public TeachingRecordSystem.Core.Dqt.Models.SystemUser lk_accountbase_modifiedon
}
}

/// <summary>
/// N:1 msa_account_managingpartner
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("msa_managingpartnerid")]
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("msa_account_managingpartner", Microsoft.Xrm.Sdk.EntityRole.Referencing)]
public TeachingRecordSystem.Core.Dqt.Models.Account Referencingmsa_account_managingpartner
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetRelatedEntity<TeachingRecordSystem.Core.Dqt.Models.Account>("msa_account_managingpartner", Microsoft.Xrm.Sdk.EntityRole.Referencing);
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.OnPropertyChanging("Referencingmsa_account_managingpartner");
this.SetRelatedEntity<TeachingRecordSystem.Core.Dqt.Models.Account>("msa_account_managingpartner", Microsoft.Xrm.Sdk.EntityRole.Referencing, value);
this.OnPropertyChanged("Referencingmsa_account_managingpartner");
}
}

/// <summary>
/// N:1 system_user_accounts
/// </summary>
Expand Down Expand Up @@ -1180,6 +1244,7 @@ public static class Fields
public const string lk_contact_modifiedonbehalfby = "lk_contact_modifiedonbehalfby";
public const string lk_contactbase_createdby = "lk_contactbase_createdby";
public const string lk_contactbase_modifiedby = "lk_contactbase_modifiedby";
public const string msa_contact_managingpartner = "msa_contact_managingpartner";
public const string system_user_contacts = "system_user_contacts";
}

Expand Down Expand Up @@ -2675,6 +2740,27 @@ public TeachingRecordSystem.Core.Dqt.Models.SystemUser lk_contactbase_modifiedby
}
}

/// <summary>
/// N:1 msa_contact_managingpartner
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("msa_managingpartnerid")]
[Microsoft.Xrm.Sdk.RelationshipSchemaNameAttribute("msa_contact_managingpartner")]
public TeachingRecordSystem.Core.Dqt.Models.Account msa_contact_managingpartner
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetRelatedEntity<TeachingRecordSystem.Core.Dqt.Models.Account>("msa_contact_managingpartner", null);
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.OnPropertyChanging("msa_contact_managingpartner");
this.SetRelatedEntity<TeachingRecordSystem.Core.Dqt.Models.Account>("msa_contact_managingpartner", null, value);
this.OnPropertyChanged("msa_contact_managingpartner");
}
}

/// <summary>
/// N:1 system_user_contacts
/// </summary>
Expand Down Expand Up @@ -8398,6 +8484,7 @@ public static class Fields
public const string dfeta_NoReAppuntildate = "dfeta_noreappuntildate";
public const string dfeta_PersonId = "dfeta_personid";
public const string dfeta_SanctionCodeId = "dfeta_sanctioncodeid";
public const string dfeta_SanctionDetails = "dfeta_sanctiondetails";
public const string dfeta_sanctionId = "dfeta_sanctionid";
public const string Id = "dfeta_sanctionid";
public const string dfeta_Spent = "dfeta_spent";
Expand Down Expand Up @@ -8536,6 +8623,26 @@ public Microsoft.Xrm.Sdk.EntityReference dfeta_SanctionCodeId
}
}

/// <summary>
///
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("dfeta_sanctiondetails")]
public string dfeta_SanctionDetails
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetAttributeValue<string>("dfeta_sanctiondetails");
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.OnPropertyChanging("dfeta_SanctionDetails");
this.SetAttributeValue("dfeta_sanctiondetails", value);
this.OnPropertyChanged("dfeta_SanctionDetails");
}
}

/// <summary>
/// Unique identifier for entity instances
/// </summary>
Expand Down Expand Up @@ -8846,6 +8953,7 @@ public partial class dfeta_sanctioncode : Microsoft.Xrm.Sdk.Entity, System.Compo
/// </summary>
public static class Fields
{
public const string dfeta_name = "dfeta_name";
public const string dfeta_sanctioncodeId = "dfeta_sanctioncodeid";
public const string Id = "dfeta_sanctioncodeid";
public const string dfeta_Value = "dfeta_value";
Expand Down Expand Up @@ -8900,6 +9008,26 @@ private void OnPropertyChanging(string propertyName)
}
}

/// <summary>
/// The name of the custom entity.
/// </summary>
[Microsoft.Xrm.Sdk.AttributeLogicalNameAttribute("dfeta_name")]
public string dfeta_name
{
[System.Diagnostics.DebuggerNonUserCode()]
get
{
return this.GetAttributeValue<string>("dfeta_name");
}
[System.Diagnostics.DebuggerNonUserCode()]
set
{
this.OnPropertyChanging("dfeta_name");
this.SetAttributeValue("dfeta_name", value);
this.OnPropertyChanged("dfeta_name");
}
}

/// <summary>
/// Unique identifier for entity instances
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace TeachingRecordSystem.Core.Dqt.Queries;

public record GetSanctionDetailsByContactIdQuery(Guid ContactId) : ICrmQuery<SanctionDetailResult[]>;

public record SanctionDetailResult(dfeta_sanction Sanction, string Description);
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public async Task<dfeta_sanctioncode[]> Execute(GetAllSanctionCodesQuery query,
EntityName = dfeta_sanctioncode.EntityLogicalName,
ColumnSet = new ColumnSet(
dfeta_sanctioncode.Fields.dfeta_sanctioncodeId,
dfeta_sanctioncode.Fields.dfeta_Value)
dfeta_sanctioncode.Fields.dfeta_Value,
dfeta_sanctioncode.Fields.dfeta_name)
};

queryExpression.Criteria.AddCondition(dfeta_sanctioncode.Fields.StateCode, ConditionOperator.Equal, (int)dfeta_sanctioncodeState.Active);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using Microsoft.PowerPlatform.Dataverse.Client;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Query;
using TeachingRecordSystem.Core.Dqt.Queries;

namespace TeachingRecordSystem.Core.Dqt.QueryHandlers;

public class GetSanctionDetailsByContactIdHandler : ICrmQueryHandler<GetSanctionDetailsByContactIdQuery, SanctionDetailResult[]>
{
public async Task<SanctionDetailResult[]> Execute(GetSanctionDetailsByContactIdQuery query, IOrganizationServiceAsync organizationService)
{
var filter = new FilterExpression();
filter.AddCondition(dfeta_sanction.Fields.dfeta_PersonId, ConditionOperator.Equal, query.ContactId);

var queryExpression = new QueryExpression(dfeta_sanction.EntityLogicalName)
{
ColumnSet = new ColumnSet(
dfeta_sanction.PrimaryIdAttribute,
dfeta_sanction.Fields.dfeta_SanctionDetails,
dfeta_sanction.Fields.dfeta_PersonId,
dfeta_sanction.Fields.dfeta_StartDate,
dfeta_sanction.Fields.dfeta_EndDate,
dfeta_sanction.Fields.dfeta_Spent,
dfeta_sanction.Fields.StateCode),
Criteria = filter
};

var sanctionCodeLink = queryExpression.AddLink(
dfeta_sanctioncode.EntityLogicalName,
dfeta_sanction.Fields.dfeta_SanctionCodeId,
dfeta_sanctioncode.PrimaryIdAttribute,
JoinOperator.Inner);

sanctionCodeLink.Columns = new ColumnSet(dfeta_sanctioncode.PrimaryIdAttribute, dfeta_sanctioncode.Fields.dfeta_name);
sanctionCodeLink.EntityAlias = typeof(dfeta_sanctioncode).Name;

var request = new RetrieveMultipleRequest()
{
Query = queryExpression
};

var result = (RetrieveMultipleResponse)await organizationService.ExecuteAsync(request);
return result.EntityCollection.Entities.Select(entity => new SanctionDetailResult(entity.ToEntity<dfeta_sanction>(), entity.Extract<dfeta_sanctioncode>().dfeta_name)).ToArray();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.Xrm.Sdk.Query;
using TeachingRecordSystem.Core.Dqt.Models;
using TeachingRecordSystem.Core.Dqt.Queries;

namespace TeachingRecordSystem.SupportUi.Infrastructure.Filters;

public class CheckPersonExistsFilter : IAsyncPageFilter
{
public async Task OnPageHandlerExecutionAsync(PageHandlerExecutingContext context, PageHandlerExecutionDelegate next)
{
var personId = context.RouteData.Values["personId"] as string;
if (personId is not null)
{
var crmQueryDispatcher = context.HttpContext.RequestServices.GetRequiredService<ICrmQueryDispatcher>();
var person = await crmQueryDispatcher.ExecuteQuery(new GetContactDetailByIdQuery(Guid.Parse(personId), new ColumnSet(Contact.Fields.Id)));
if (person is null)
{
context.Result = new NotFoundResult();
return;
}
}

await next();
}

public Task OnPageHandlerSelectionAsync(PageHandlerSelectedContext context) => Task.CompletedTask;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@page "/alerts/{alertId}/close"
@model TeachingRecordSystem.SupportUi.Pages.Alerts.Alert.CloseModel
@{
ViewBag.Title = "Close alert";
}

<h1 class="govuk-heading-l">@ViewBag.Title</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace TeachingRecordSystem.SupportUi.Pages.Alerts.Alert;

public class CloseModel : PageModel
{
public void OnGet()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@page "/alerts/{alertId}"
@model IndexModel
@{
ViewBag.Title = "Alert";
}

<h1 class="govuk-heading-l">@ViewBag.Title</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace TeachingRecordSystem.SupportUi.Pages.Alerts.Alert;

public class IndexModel : PageModel
{
public void OnGet()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TeachingRecordSystem.SupportUi.Pages.Common;

public enum PersonSubNavigationTab
{
General,
Alerts,
ChangeLog
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@using TeachingRecordSystem.Core.Dqt.Models;
@using TeachingRecordSystem.SupportUi.Pages.Common;
@{
Layout = "_Layout";
var selectedTab = (PersonSubNavigationTab)ViewBag.SelectedTab;
var personId = (Guid)ViewBag.PersonId;
var search = (string)ViewBag.Search;
var sortBy = (ContactSearchSortByOption?)ViewBag.SortBy;
var pageNumber = (int?)ViewBag.PageNumber;
}

@section BeforeContent {
<govuk-back-link href="@LinkGenerator.Persons(search, sortBy, pageNumber)">Back to find a record</govuk-back-link>
}

<h1 class="govuk-heading-l" data-testid="page-title">@ViewBag.Title</h1>

<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<nav class="moj-sub-navigation" aria-label="Sub navigation">
<ul class="moj-sub-navigation__list">
<li class="moj-sub-navigation__item">
<a class="moj-sub-navigation__link" aria-current="@(selectedTab == PersonSubNavigationTab.General ? "page" : null)" href="@LinkGenerator.PersonDetail(personId, search, sortBy, pageNumber)">General</a>
</li>

<li class="moj-sub-navigation__item">
<a class="moj-sub-navigation__link" aria-current="@(selectedTab == PersonSubNavigationTab.Alerts ? "page" : null)" href="@LinkGenerator.PersonAlerts(personId, search, sortBy, pageNumber)">Alerts</a>
</li>

<li class="moj-sub-navigation__item">
<a class="moj-sub-navigation__link" aria-current="@(selectedTab == PersonSubNavigationTab.ChangeLog ? "page" : null)" href="@LinkGenerator.PersonChangeLog(personId, search, sortBy, pageNumber)">Change log</a>
</li>
</ul>
</nav>
@RenderBody()
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@page "/persons/{personId}/alerts/new"
@model TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail.AddAlertModel
@{
ViewBag.Title = "Add alert";
}

<h1 class="govuk-heading-l">@ViewBag.Title</h1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace TeachingRecordSystem.SupportUi.Pages.Persons.PersonDetail;

public class AddAlertModel : PageModel
{
public void OnGet()
{
}
}
Loading
Loading