Skip to content

Commit 6688ee5

Browse files
authored
add GetSingleField (#2410)
1 parent 402dc5f commit 6688ee5

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/JoinRpg.Domain/CharacterFields/CustomFieldsExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using JoinRpg.Data.Interfaces;
22
using JoinRpg.DataModel;
33
using JoinRpg.Helpers;
4+
using JoinRpg.PrimitiveTypes;
45
using JoinRpg.PrimitiveTypes.ProjectMetadata;
56
using Newtonsoft.Json;
67

@@ -72,6 +73,11 @@ public static IReadOnlyCollection<FieldWithValue> GetFields(this Claim claim, Pr
7273
claim.DeserializeFieldValues());
7374
}
7475

76+
public static FieldWithValue? GetSingleField(this Claim claim, ProjectInfo projectInfo, ProjectFieldIdentification id)
77+
{
78+
return claim.GetFields(projectInfo).SingleOrDefault(f => f.Field.ProjectFieldId == id.ProjectFieldId);
79+
}
80+
7581
public static IReadOnlyCollection<FieldWithValue> GetFieldsForClaimSource(this IClaimSource claimSource, ProjectInfo projectInfo)
7682
{
7783
if (claimSource is Character character)

src/JoinRpg.Portal/Controllers/ClaimListController.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,12 @@ public async Task<ActionResult> PaidDeclined(int projectid, string export)
353353
[HttpGet, MasterAuthorize()]
354354
public async Task<ActionResult> ByAssignedField(int projectfieldid, int projectid, string export)
355355
{
356-
var field = await ProjectRepository.GetProjectField(projectid, projectfieldid);
357356
var claims = await ClaimsRepository.GetClaims(projectid, ClaimStatusSpec.Active);
358357
var projectInfo = await projectMetadataRepository.GetProjectMetadata(new(projectid));
358+
var fieldId = new ProjectFieldIdentification(new(projectid), projectfieldid);
359+
var field = projectInfo.GetFieldById(fieldId);
359360

360-
return await ShowMasterClaimList(projectid, export, "Поле (проставлено): " + field.FieldName, claims.Where(c => c.GetFields(projectInfo).Single(f => f.Field.ProjectFieldId == projectfieldid).HasEditableValue)
361+
return await ShowMasterClaimList(projectid, export, "Поле (проставлено): " + field.Name, claims.Where(c => c.GetSingleField(projectInfo, fieldId)!.HasEditableValue)
361362
.ToList(),
362363
ClaimStatusSpec.Active
363364
);
@@ -366,10 +367,12 @@ public async Task<ActionResult> ByAssignedField(int projectfieldid, int projecti
366367
[HttpGet, MasterAuthorize()]
367368
public async Task<ActionResult> ByUnAssignedField(int projectfieldid, int projectid, string export)
368369
{
369-
var field = await ProjectRepository.GetProjectField(projectid, projectfieldid);
370370
var claims = await ClaimsRepository.GetClaims(projectid, ClaimStatusSpec.Active);
371371
var projectInfo = await projectMetadataRepository.GetProjectMetadata(new(projectid));
372-
return await ShowMasterClaimList(projectid, export, "Поле (непроставлено): " + field.FieldName, claims.Where(c => !c.GetFields(projectInfo).Single(f => f.Field.ProjectFieldId == projectfieldid).HasEditableValue)
372+
var fieldId = new ProjectFieldIdentification(new(projectid), projectfieldid);
373+
var field = projectInfo.GetFieldById(fieldId);
374+
375+
return await ShowMasterClaimList(projectid, export, "Поле (непроставлено): " + field.Name, claims.Where(c => !c.GetSingleField(projectInfo, fieldId)!.HasEditableValue)
373376
.ToList(),
374377
ClaimStatusSpec.Active
375378
);

0 commit comments

Comments
 (0)