-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow HE quals with no link to dfeta_hequalification table
Amended to only return HE quals with at least one subject + added tests Removed commented out code Removed unnecessary code Removed commented out code
- Loading branch information
Showing
20 changed files
with
677 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...hingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetAllHeQualificationsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
public record GetAllHeQualificationsQuery : ICrmQuery<dfeta_hequalification[]>; |
3 changes: 3 additions & 0 deletions
3
TeachingRecordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetAllHeSubjectsQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
public record GetAllHeSubjectsQuery : ICrmQuery<dfeta_hesubject[]>; |
5 changes: 5 additions & 0 deletions
5
...cordSystem/src/TeachingRecordSystem.Core/Dqt/Queries/GetQualificationsByContactIdQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
using Microsoft.Xrm.Sdk.Query; | ||
|
||
namespace TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
public record GetQualificationsByContactIdQuery(Guid ContactId, ColumnSet ColumnSet, bool IncludeHigherEducationDetails = false) : ICrmQuery<dfeta_qualification[]>; |
31 changes: 31 additions & 0 deletions
31
...rdSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetAllHeQualificationsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 GetAllHeQualificationsHandler : ICrmQueryHandler<GetAllHeQualificationsQuery, dfeta_hequalification[]> | ||
{ | ||
public async Task<dfeta_hequalification[]> Execute(GetAllHeQualificationsQuery query, IOrganizationServiceAsync organizationService) | ||
{ | ||
var queryExpression = new QueryExpression() | ||
{ | ||
EntityName = dfeta_hequalification.EntityLogicalName, | ||
ColumnSet = new ColumnSet( | ||
dfeta_hequalification.Fields.dfeta_name, | ||
dfeta_hequalification.Fields.dfeta_Value) | ||
}; | ||
|
||
queryExpression.Criteria.AddCondition(dfeta_hequalification.Fields.StateCode, ConditionOperator.Equal, (int)dfeta_hequalificationState.Active); | ||
|
||
var request = new RetrieveMultipleRequest() | ||
{ | ||
Query = queryExpression | ||
}; | ||
|
||
var response = await organizationService.RetrieveMultipleAsync(queryExpression); | ||
|
||
return response.Entities.Select(e => e.ToEntity<dfeta_hequalification>()).ToArray(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...ngRecordSystem/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetAllHeSubjectsHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
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 GetAllHeSubjectsHandler : ICrmQueryHandler<GetAllHeSubjectsQuery, dfeta_hesubject[]> | ||
{ | ||
public async Task<dfeta_hesubject[]> Execute(GetAllHeSubjectsQuery query, IOrganizationServiceAsync organizationService) | ||
{ | ||
var queryExpression = new QueryExpression() | ||
{ | ||
EntityName = dfeta_hesubject.EntityLogicalName, | ||
ColumnSet = new ColumnSet( | ||
dfeta_hesubject.Fields.dfeta_name, | ||
dfeta_hesubject.Fields.dfeta_Value) | ||
}; | ||
|
||
queryExpression.Criteria.AddCondition(dfeta_hesubject.Fields.StateCode, ConditionOperator.Equal, (int)dfeta_hesubjectState.Active); | ||
|
||
var request = new RetrieveMultipleRequest() | ||
{ | ||
Query = queryExpression | ||
}; | ||
|
||
var response = await organizationService.RetrieveMultipleAsync(queryExpression); | ||
|
||
return response.Entities.Select(e => e.ToEntity<dfeta_hesubject>()).ToArray(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...em/src/TeachingRecordSystem.Core/Dqt/QueryHandlers/GetQualificationsByContactIdHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Microsoft.PowerPlatform.Dataverse.Client; | ||
using Microsoft.Xrm.Sdk.Query; | ||
using TeachingRecordSystem.Core.Dqt.Queries; | ||
|
||
namespace TeachingRecordSystem.Core.Dqt.QueryHandlers; | ||
|
||
public class GetQualificationsByContactIdHandler : ICrmQueryHandler<GetQualificationsByContactIdQuery, dfeta_qualification[]> | ||
{ | ||
public async Task<dfeta_qualification[]> Execute(GetQualificationsByContactIdQuery query, IOrganizationServiceAsync organizationService) | ||
{ | ||
var filter = new FilterExpression(); | ||
filter.AddCondition(dfeta_qualification.Fields.dfeta_PersonId, ConditionOperator.Equal, query.ContactId); | ||
filter.AddCondition(dfeta_qualification.Fields.StateCode, ConditionOperator.Equal, (int)dfeta_qualificationState.Active); | ||
|
||
var qualificationTypeFilter = new FilterExpression(LogicalOperator.Or); | ||
qualificationTypeFilter.AddCondition(dfeta_qualification.Fields.dfeta_Type, ConditionOperator.NotEqual, (int)dfeta_qualification_dfeta_Type.HigherEducation); | ||
|
||
var heFilter = new FilterExpression(LogicalOperator.And); | ||
heFilter.AddCondition(dfeta_qualification.Fields.dfeta_Type, ConditionOperator.Equal, (int)dfeta_qualification_dfeta_Type.HigherEducation); | ||
|
||
var heSubjectFilter = new FilterExpression(LogicalOperator.Or); | ||
heSubjectFilter.AddCondition(dfeta_qualification.Fields.dfeta_HE_HESubject1Id, ConditionOperator.NotNull); | ||
heSubjectFilter.AddCondition(dfeta_qualification.Fields.dfeta_HE_HESubject2Id, ConditionOperator.NotNull); | ||
heSubjectFilter.AddCondition(dfeta_qualification.Fields.dfeta_HE_HESubject3Id, ConditionOperator.NotNull); | ||
heFilter.AddFilter(heSubjectFilter); | ||
|
||
qualificationTypeFilter.AddFilter(heFilter); | ||
filter.AddFilter(qualificationTypeFilter); | ||
|
||
var queryExpression = new QueryExpression(dfeta_qualification.EntityLogicalName) | ||
{ | ||
ColumnSet = query.ColumnSet, | ||
Criteria = filter, | ||
Orders = | ||
{ | ||
new OrderExpression(dfeta_qualification.Fields.CreatedOn, OrderType.Ascending) | ||
} | ||
}; | ||
|
||
if (query.IncludeHigherEducationDetails) | ||
{ | ||
var heLink = queryExpression.AddLink( | ||
dfeta_hequalification.EntityLogicalName, | ||
dfeta_qualification.Fields.dfeta_HE_HEQualificationId, | ||
dfeta_hequalification.Fields.Id, | ||
JoinOperator.LeftOuter); | ||
|
||
heLink.Columns = new ColumnSet( | ||
dfeta_hequalification.PrimaryIdAttribute, | ||
dfeta_hequalification.Fields.dfeta_name); | ||
heLink.EntityAlias = dfeta_hequalification.EntityLogicalName; | ||
|
||
AddHeSubjectLink(queryExpression, dfeta_qualification.Fields.dfeta_HE_HESubject1Id, $"{dfeta_hesubject.EntityLogicalName}1"); | ||
AddHeSubjectLink(queryExpression, dfeta_qualification.Fields.dfeta_HE_HESubject2Id, $"{dfeta_hesubject.EntityLogicalName}2"); | ||
AddHeSubjectLink(queryExpression, dfeta_qualification.Fields.dfeta_HE_HESubject3Id, $"{dfeta_hesubject.EntityLogicalName}3"); | ||
} | ||
|
||
var result = await organizationService.RetrieveMultipleAsync(queryExpression); | ||
|
||
return result.Entities.Select(entity => entity.ToEntity<dfeta_qualification>()).ToArray(); | ||
|
||
void AddHeSubjectLink(QueryExpression query, string subjectIdField, string alias) | ||
{ | ||
var heSubjectLink = query.AddLink( | ||
dfeta_hesubject.EntityLogicalName, | ||
subjectIdField, | ||
dfeta_hesubject.PrimaryIdAttribute, | ||
JoinOperator.LeftOuter); | ||
|
||
heSubjectLink.Columns = new ColumnSet( | ||
dfeta_hesubject.PrimaryIdAttribute, | ||
dfeta_hesubject.Fields.dfeta_name, | ||
dfeta_hesubject.Fields.dfeta_Value); | ||
heSubjectLink.EntityAlias = alias; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.