using JobsJobsJobs.Shared.Api;
using Microsoft.AspNetCore.Components;
using System.Collections.Generic;
using System.Threading.Tasks;
using Domain = JobsJobsJobs.Shared;
namespace JobsJobsJobs.Client.Pages.Citizen
{
///
/// The first page a user sees after signing in
///
public partial class Dashboard : ComponentBase
{
///
/// The user's profile
///
private Domain.Profile? Profile { get; set; } = null;
///
/// The number of profiles
///
private int ProfileCount { get; set; }
///
/// Load the user's profile information
///
/// A collection to report errors that may be encountered
public async Task LoadProfile(ICollection errors)
{
if (state.User != null)
{
ServerApi.SetJwt(http, state);
var profileTask = ServerApi.RetrieveProfile(http, state);
var profileCountTask = ServerApi.RetrieveOne(http, "profile/count");
await Task.WhenAll(profileTask, profileCountTask);
if (profileTask.Result.IsOk)
{
Profile = profileTask.Result.Ok;
}
else
{
errors.Add(profileTask.Result.Error);
}
if (profileCountTask.Result.IsOk)
{
ProfileCount = profileCountTask.Result.Ok?.Value ?? 0;
}
else
{
errors.Add(profileCountTask.Result.Error);
}
}
}
}
}