Skip to content

Commit

Permalink
[SPDBT-3077] cancel and inactive spd_app when delete non-swl bizConta…
Browse files Browse the repository at this point in the history
…ct (#1423)

getting `FirstOrDefault()` from the
`spd_businesscontact_spd_application` collection, then cancel it.
  • Loading branch information
esdd1995 authored Sep 20, 2024
1 parent 08ef978 commit d6d49fe
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Spd.Resource.Repository/BizContact/BizContactRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,27 @@ public async Task<IEnumerable<BizContactResp>> QueryBizContactsAsync(BizContactQ
private async Task<Guid?> DeleteBizContactAsync(BizContactDeleteCmd cmd, CancellationToken ct)
{
spd_businesscontact? bizContact = await _context.GetBizContactById(cmd.BizContactId, ct);

if (bizContact == null)
throw new ApiException(HttpStatusCode.BadRequest, $"business contact with id {cmd.BizContactId} not found.");

spd_application? app = _context.spd_applications
.Expand(a => a.spd_businesscontact_spd_application)
.Where(x => x.spd_businesscontact_spd_application.Any(y=>y.spd_businesscontactid == cmd.BizContactId)).FirstOrDefault();

if (app != null &&
(app.statuscode == (int)ApplicationStatusOptionSet.Incomplete ||
app.statuscode == (int)ApplicationStatusOptionSet.Draft ||
app.statuscode == (int)ApplicationStatusOptionSet.PaymentPending ||
app.statuscode == (int)ApplicationStatusOptionSet.ApplicantVerification))
{
app.statecode = DynamicsConstants.StateCode_Inactive;
app.statuscode = (int) ApplicationStatusOptionSet.Cancelled;
_context.UpdateObject(app);
}
bizContact.statecode = DynamicsConstants.StateCode_Inactive;
_context.UpdateObject(bizContact);

await _context.SaveChangesAsync(ct);
return null;
}
Expand Down

0 comments on commit d6d49fe

Please sign in to comment.