using JobsJobsJobs.Shared; using Microsoft.AspNetCore.Components; using System.Collections.Generic; using System.Threading.Tasks; namespace JobsJobsJobs.Client.Pages.Profiles { public partial class View : ComponentBase { /// /// The citizen whose profile is being displayed /// private Citizen Citizen { get; set; } = default!; /// /// The profile to display /// private Profile Profile { get; set; } = default!; /// /// The work types for the top of the page /// private MarkupString WorkTypes { get { IEnumerable parts() { if (Profile.SeekingEmployment) { yield return "CURRENTLY SEEKING EMPLOYMENT"; } else { yield return "Not actively seeking employment"; } yield return $"{(Profile.FullTime ? "I" : "Not i")}nterested in full-time employment"; yield return $"{(Profile.RemoteWork ? "I" : "Not i")}nterested in remote opportunities"; } return new MarkupString(string.Join(" • ", parts())); } } /// /// The ID of the citizen whose profile should be displayed /// [Parameter] public string Id { get; set; } = default!; /// /// Retrieve the requested profile /// /// A collection to report errors that may occur public async Task RetrieveProfile(ICollection errors) { ServerApi.SetJwt(http, state); var citizenTask = ServerApi.RetrieveOne(http, $"citizen/get/{Id}"); var profileTask = ServerApi.RetrieveOne(http, $"profile/get/{Id}"); await Task.WhenAll(citizenTask, profileTask); if (citizenTask.Result.IsOk && citizenTask.Result.Ok != null) { Citizen = citizenTask.Result.Ok; } else if (citizenTask.Result.IsOk) { errors.Add("Citizen not found"); } else { errors.Add(citizenTask.Result.Error); } if (profileTask.Result.IsOk && profileTask.Result.Ok != null) { Profile = profileTask.Result.Ok; } else if (profileTask.Result.IsOk) { errors.Add("Profile not found"); } else { errors.Add(profileTask.Result.Error); } } } }