Skip to content

Commit

Permalink
Merge pull request #996 from bcgov/bugfix/ab#27138-submissionId-not-d…
Browse files Browse the repository at this point in the history
…isplaying-properly

ab#27138 Fix application links
  • Loading branch information
jimmyPasta authored Jan 14, 2025
2 parents 82681c9 + 8d322c2 commit 18d1df5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ public interface IApplicationLinksService : ICrudAppService<
Guid>
{
Task<List<ApplicationLinksInfoDto>> GetListByApplicationAsync(Guid applicationId);

Task<ApplicationLinksInfoDto> GetLinkedApplicationAsync(Guid currentApplicationId, Guid linkedApplicationId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,29 @@ join appForm in applicationFormsQuery on application.ApplicationFormId equals ap

return await combinedQuery.ToListAsync();
}

public async Task<ApplicationLinksInfoDto> GetLinkedApplicationAsync(Guid currentApplicationId, Guid linkedApplicationId)
{
var applicationLinksQuery = await ApplicationLinksRepository.GetQueryableAsync();
var applicationsQuery = await ApplicationRepository.GetQueryableAsync();
var applicationFormsQuery = await ApplicationFormRepository.GetQueryableAsync();

var combinedQuery = from applicationLinks in applicationLinksQuery
join application in applicationsQuery on applicationLinks.LinkedApplicationId equals application.Id into appLinks
from application in appLinks.DefaultIfEmpty() // Left join for safety
join appForm in applicationFormsQuery on application.ApplicationFormId equals appForm.Id into appForms
from appForm in appForms.DefaultIfEmpty() // Left join for safety
where applicationLinks.ApplicationId == linkedApplicationId && applicationLinks.LinkedApplicationId == currentApplicationId
select new ApplicationLinksInfoDto
{
Id = applicationLinks.Id,
ApplicationId = application.Id,
ApplicationStatus = application.ApplicationStatus.InternalStatus,
ReferenceNumber = application.ReferenceNo,
Category = appForm.Category ?? "Unknown", // Handle potential nulls
ProjectName = application.ProjectName
};

return await combinedQuery.SingleAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class ApplicationLinksModalModel : AbpPageModel
[BindProperty]
public Guid? CurrentApplicationId { get; set; }


public ApplicationLinksModalModel(IApplicationLinksService applicationLinksService, IGrantApplicationAppService grantApplicationAppService)
{
_applicationLinksService = applicationLinksService ?? throw new ArgumentNullException(nameof(applicationLinksService));
Expand All @@ -62,18 +61,23 @@ public async Task OnGetAsync(Guid applicationId)
{
CurrentApplicationId = applicationId;
var grantApplications = await _grantApplicationAppService.GetAllApplicationsAsync();
var tempGrantApplications = new List<GrantApplicationLiteDto>(grantApplications);
var currentApplication = tempGrantApplications.Single(item => item.Id == applicationId);

var linkedApplications = await _applicationLinksService.GetListByApplicationAsync(applicationId);
var filteredLinkedApplications = linkedApplications.Where(item => item.ApplicationId != CurrentApplicationId);

// remove current application id from ths suggestion list
grantApplications.Remove(grantApplications.Single(item => item.Id == applicationId));
tempGrantApplications.Remove(currentApplication);

var formattedAllApplications = grantApplications.Select(item => item.ReferenceNo + " - " + item.ProjectName).ToList();
var formattedLinkedApplications = linkedApplications.Select(item => item.ReferenceNumber + " - " + item.ProjectName).ToList();
var formattedAllApplications = tempGrantApplications.Select(item => item.ReferenceNo + " - " + item.ProjectName).ToList();
var formattedLinkedApplications = filteredLinkedApplications.Select(item => item.ReferenceNumber + " - " + item.ProjectName).ToList();

AllApplications = string.Join(",", formattedAllApplications);
SelectedApplications = string.Join(",", formattedLinkedApplications);
GrantApplicationsList = JsonConvert.SerializeObject(grantApplications);
LinkedApplicationsList = JsonConvert.SerializeObject(linkedApplications);
LinkedApplicationsList = JsonConvert.SerializeObject(filteredLinkedApplications);

}
catch (Exception ex)
{
Expand All @@ -89,6 +93,7 @@ public async Task<IActionResult> OnPostAsync()
string[]? selectedApplicationsArray = JsonConvert.DeserializeObject<string[]>(SelectedApplications);
List<GrantApplicationLiteDto>? grantApplications = JsonConvert.DeserializeObject<List<GrantApplicationLiteDto>>(GrantApplicationsList!);
List<ApplicationLinksInfoDto>? linkedApplications = JsonConvert.DeserializeObject<List<ApplicationLinksInfoDto>>(LinkedApplicationsList!);
List<ApplicationLinksInfoDto>? applicationList = JsonConvert.DeserializeObject<List<ApplicationLinksInfoDto>>(GrantApplicationsList!);

foreach (var item in selectedApplicationsArray!)
{
Expand All @@ -100,10 +105,18 @@ public async Task<IActionResult> OnPostAsync()
if (applicationLinksInfoDto == null) {
Guid linkedApplicationId = grantApplications!.Find(application => application.ReferenceNo == referenceNo)!.Id;

//For CurrentApplication
await _applicationLinksService.CreateAsync(new ApplicationLinksDto{
ApplicationId = CurrentApplicationId ?? Guid.Empty,
LinkedApplicationId = linkedApplicationId
});

//For LinkedApplication
await _applicationLinksService.CreateAsync(new ApplicationLinksDto
{
ApplicationId = linkedApplicationId,
LinkedApplicationId = CurrentApplicationId ?? Guid.Empty
});
}
}

Expand All @@ -113,6 +126,9 @@ await _applicationLinksService.CreateAsync(new ApplicationLinksDto{
var selectedIndex = selectedApplicationsArray!.FindIndex(selected => selected.Split('-')[0].Trim() == linked.ReferenceNumber);
if(selectedIndex < 0) {
await _applicationLinksService.DeleteAsync(linked.Id);

var linkApp = await _applicationLinksService.GetLinkedApplicationAsync(CurrentApplicationId ?? Guid.Empty, linked.ApplicationId);
await _applicationLinksService.DeleteAsync(linkApp.Id);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections.Generic;
using Volo.Abp.AspNetCore.Mvc.UI.Bundling;
using Unity.GrantManager.GrantApplications;
using System.Linq;

namespace Unity.GrantManager.Web.Views.Shared.Components.ApplicationLinksWidget
{
Expand All @@ -25,7 +26,8 @@ public ApplicationLinksWidgetViewComponent(IApplicationLinksService applicationL

public async Task<IViewComponentResult> InvokeAsync(Guid applicationId)
{
List<ApplicationLinksInfoDto> applicationLinks = await _applicationLinksService.GetListByApplicationAsync(applicationId);
var applicationList = await _applicationLinksService.GetListByApplicationAsync(applicationId);
List<ApplicationLinksInfoDto> applicationLinks = applicationList.Where(item => item.ApplicationId != applicationId).ToList();
ApplicationLinksWidgetViewModel model = new() {
ApplicationLinks = applicationLinks,
ApplicationId = applicationId
Expand Down

0 comments on commit 18d1df5

Please sign in to comment.