Skip to content

Commit

Permalink
add originalLicenceId to viewModel (#693)
Browse files Browse the repository at this point in the history
# Description

This PR includes the following proposed change(s):

- spdbt-1848 - update view model
  • Loading branch information
peggy-quartech authored Jan 19, 2024
1 parent 90113db commit 72220cb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/Spd.Manager.Licence/PersonalLicenceAppContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public abstract record WorkerLicenceAppBase
public GenderCode? GenderCode { get; set; }
public bool? OneLegalName { get; set; }
public string? ExpiredLicenceNumber { get; set; }
public Guid? ExpiredLicenceId { get; set; } = null;//for new, it should be from user answering the question. for renew, replace, update, it should be original licence id.
public bool? HasExpiredLicence { get; set; } = null; //for new, it should be from user answering the question. for renew, replace, update, it should always be true.
public Guid? ExpiredLicenceId { get; set; } = null;//for new application type, for renew, replace, update, it should be null.
public bool? HasExpiredLicence { get; set; } = null; //for new application type
public LicenceTermCode? LicenceTermCode { get; set; }
public bool? HasCriminalHistory { get; set; }
public bool? HasPreviousName { get; set; }
Expand Down Expand Up @@ -175,7 +175,8 @@ public record WorkerLicenceAppAnonymousSubmitRequestJson : WorkerLicenceAppBase
public WorkerCategoryTypeCode[] CategoryCodes { get; set; } = Array.Empty<WorkerCategoryTypeCode>();
public DocumentBase[]? DocumentInfos { get; set; }
public Guid[]? FileKeyCodes { get; set; }
public Guid? OriginalApplicationId { get; set; } = null;//for new, it should be null. for renew, replace, update, it should be original application id.
public Guid? OriginalApplicationId { get; set; } //for new, it should be null. for renew, replace, update, it should be original application id.
public Guid? OriginalLicenceId { get; set; } //for new, it should be null. for renew, replace, update, it should be original licence id.
}

public record WorkerLicenceCreateResponse
Expand Down
3 changes: 1 addition & 2 deletions src/Spd.Manager.Licence/PersonalLicenceAppValidation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,7 @@ public WorkerLicenceAppAnonymousSubmitRequestJsonValidator(IConfiguration config
.WithMessage("Some category cannot be in the same licence request.");

RuleFor(r => r.OriginalApplicationId).NotEmpty().When(r => r.ApplicationTypeCode != ApplicationTypeCode.New);
RuleFor(r => r.HasExpiredLicence).Must(r => r == true).When(r => r.ApplicationTypeCode != ApplicationTypeCode.New);
RuleFor(r => r.ExpiredLicenceId).NotEmpty().When(r => r.ApplicationTypeCode != ApplicationTypeCode.New);
RuleFor(r => r.OriginalLicenceId).NotEmpty().When(r => r.ApplicationTypeCode != ApplicationTypeCode.New);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Spd.Resource.Applicants/LicenceApplication/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public record LicenceApplication
public bool? IsDogsPurposeDetectionExplosives { get; set; }
public WorkerLicenceAppCategory[] CategoryData { get; set; } = Array.Empty<WorkerLicenceAppCategory>();
public bool? IsCanadianCitizen { get; set; }
public Guid? OriginalApplicationId { get; set; } = null;
}

public record WorkerLicenceAppCategory
Expand All @@ -79,7 +78,8 @@ public record SaveLicenceApplicationCmd() : LicenceApplication
public record CreateLicenceApplicationCmd() : LicenceApplication
{
public ApplicationStatusEnum ApplicationStatusEnum { get; set; } = ApplicationStatusEnum.Incomplete;
public Guid? OriginalApplicationId { get; set;} = null;
public Guid? OriginalApplicationId { get; set; }
public Guid? OriginalLicenceId { get; set; }
};

public record LicenceApplicationResp() : LicenceApplication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,34 @@ public async Task<LicenceApplicationCmdResp> CreateLicenceApplicationAsync(Creat
app.statuscode = (int)ApplicationStatusOptionSet.Incomplete;
_context.AddTospd_applications(app);
LinkServiceType(cmd.WorkerLicenceTypeCode, app);
if (cmd.HasExpiredLicence == true && cmd.ExpiredLicenceId != null) LinkExpiredLicence(cmd.ExpiredLicenceId, app);
contact contact = _mapper.Map<contact>(cmd);
if (cmd.ApplicationTypeCode == ApplicationTypeEnum.New)
{
if (cmd.HasExpiredLicence == true && cmd.ExpiredLicenceId != null) LinkExpiredLicence(cmd.ExpiredLicenceId, app);
//for new, always create a new contact
contact = await _context.CreateContact(contact, null, _mapper.Map<IEnumerable<spd_alias>>(cmd.Aliases), ct);
}
else
{
if (cmd.OriginalApplicationId != null)
{
spd_application originApp = _context.spd_applications.Where(a => a.spd_applicationid == cmd.OriginalApplicationId).FirstOrDefault();
spd_application originApp = await _context.spd_applications.Where(a => a.spd_applicationid == cmd.OriginalApplicationId).FirstOrDefaultAsync(ct);
//for replace, renew, update, "contact" is already exists, so, do update.
contact = await _context.UpdateContact((Guid)originApp._spd_applicantid_value, contact, null, _mapper.Map<IEnumerable<spd_alias>>(cmd.Aliases), ct);
}
else
{
throw new ArgumentException("for replace, renew or update, original application id cannot be null");
}

if (cmd.OriginalLicenceId != null)
{
LinkExpiredLicence(cmd.OriginalLicenceId, app);
}
else
{
throw new ArgumentException("for replace, renew or update, original licence id cannot be null");
}
}
_context.SetLink(app, nameof(app.spd_ApplicantId_contact), contact);
await _context.SaveChangesAsync();
Expand Down

0 comments on commit 72220cb

Please sign in to comment.