public bool SubmitManualMatchingUsingDropdown(ProjectMapModelMinified projectMapModel)
{
if (projectMapModel != null)
{
UpdateActivities(projectMapModel.IatiActivitiesNotInAims, Sessions.ProjectMapModel.IatiActivitiesNotInAims);
//Sessions.ProjectMapModel.AimsProjectsNotInIati = projectMapModel.AimsProjectsNotInIati;
Sessions.ProjectMapModel.MatchedProjects.RemoveAll(r => r.IsManuallyMapped);
}
//actual method starts here :)
//add manually matched projects
var aimsProjects = Sessions.activitiesContainer?.AimsProjects;
var iatiActivities = Sessions.ProjectMapModel?.IatiActivitiesNotInAims;
foreach (var project in aimsProjects)
{
var mappedActivityCount = iatiActivities.Count(c => c.ProjectId == project.ProjectId);
if (mappedActivityCount == 1)
{
var m = new ProjectFieldMapModel(iatiActivities.Find(c => c.ProjectId == project.ProjectId), project, false) { IsManuallyMapped = true };
Sessions.ProjectMapModel.MatchedProjects.Add(m);
}
else if (mappedActivityCount > 1)
{
iatiactivity groupedActivity = MergeToSingleActivity(iatiActivities.FindAll(c => c.ProjectId == project.ProjectId));
Sessions.ProjectMapModel.MatchedProjects.Add(new ProjectFieldMapModel(groupedActivity, project, false) { IsManuallyMapped = true, IsGrouped = true });
}
}
//foreach (var activity in Sessions.ProjectMapModel?.IatiActivitiesNotInAims.Where(w => w.ProjectId > 0))
//{
// var project = aimsProjects.Find(f => f.ProjectId == activity.ProjectId);
// if (project != null)
// {
// Sessions.ProjectMapModel.MatchedProjects.Add(new ProjectFieldMapModel(activity, project) { IsManuallyMapped = true });
// }
//}
foreach (var activity in Sessions.ProjectMapModel?.IatiActivitiesNotInAims.Where(w => w.ProjectId == -2))
{
activity.IsCommitmentIncluded = true;
activity.IsDisbursmentIncluded = true;
activity.IsPlannedDisbursmentIncluded = true;
Sessions.ProjectMapModel.NewProjectsToAddInAims.Add(activity);
}
return true;
}