Skip to content

Commit

Permalink
Current users name appears first in the Assign DO list
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominic NEED authored and Dominic NEED committed Mar 15, 2024
1 parent f9258bb commit 2a95280
Showing 1 changed file with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
using Dfe.PrepareConversions.Utils;
using Dfe.PrepareConversions.ViewModels;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace Dfe.PrepareConversions.Pages.ProjectList;
Expand All @@ -26,6 +28,7 @@ public IndexModel(IAcademyConversionProjectRepository repository)
protected override ApiV2PagingInfo Paging { get; set; }
public IEnumerable<ProjectListViewModel> Projects { get; set; }
public int ProjectCount => Projects.Count();
protected string NameOfUser => User?.FindFirstValue("name") ?? string.Empty;

public int TotalProjects { get; set; }

Expand All @@ -48,7 +51,9 @@ public async Task OnGetAsync()
if (filterParametersResponse.Success)
{
Filters.AvailableStatuses = filterParametersResponse.Body.Statuses.ConvertAll(r => r.ToSentenceCase());
Filters.AvailableDeliveryOfficers = filterParametersResponse.Body.AssignedUsers;
Filters.AvailableDeliveryOfficers = filterParametersResponse.Body.AssignedUsers.OrderByDescending(o => o.Equals(ConvertToFirstLast(NameOfUser), StringComparison.OrdinalIgnoreCase))
.ThenBy(o => o)
.ToList();
Filters.AvailableRegions = filterParametersResponse.Body.Regions;
Filters.AvailableLocalAuthorities = filterParametersResponse.Body.LocalAuthorities;
Filters.AvailableAdvisoryBoardDates = filterParametersResponse.Body.AdvisoryBoardDates;
Expand Down Expand Up @@ -79,4 +84,17 @@ public async Task<FileStreamResult> OnGetDownload()
return fileStreamResult;
}
}
// Convert from "LASTNAME, Firstname" to "Firstname Lastname"
public static string ConvertToFirstLast(string name)
{
if (string.IsNullOrEmpty(name)) return string.Empty;

var parts = name.Split(',');
if (parts.Length == 2)
{
return $"{parts[1].Trim()} {parts[0].Trim()}";
}

return name;
}
}

0 comments on commit 2a95280

Please sign in to comment.