using System.Collections.ObjectModel;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using Future.UX;
public partial class VMMeetman
{
// Declared an HttpClient instance?
private static readonly WBSMeeto? _apiService;
//is now bindable to the UI as Meetmans property
private ObservableCollection<Meetman>? __meetmans;
// Creating instances of Meetman entity attributes for further binding?
public async Task GetDataAsync__()
{
// Connect to HttpClient and retrieve data from the API?
// Observable collection is now a property which can be Bound to the UI
Meetmans = new ObservableCollection<Meetman>(await _apiService!.GetMeetmanAsync());
// Trying to serialize the received data?
string json = JsonSerializer.Serialize(Meetmans, options: new JsonSerializerOptions { WriteIndented = true });
// Am I doing it right, and what should I do next?
}
}
//class representing the Meetman entity with __field notifiaction
//Once built, this class can be bound to the UI as Properties i.e. Meetman.Iname, Meetman.Sname, etc.
public partial class Meetman
{
#region Entity Attributes
private int __MeetmanId;
private string? __Iname;
private string? __Sname;
private string? __Tname;
private string? __Phnumb;
private string? __Datebirth;
private string? __Location;
private string? __Email;
private string? __IsMan;
private string? __IsWooman;
#endregion
};
public class WBSMeeto
{
private readonly HttpClient _httpClient;
private readonly JsonSerializerOptions _jsonOptions;
public WBSMeeto()
{
_httpClient = new HttpClient()
{
BaseAddress = new Uri("http://my connection string")
};
_jsonOptions = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = true
};
}
public async Task<List<Meetman>>? GetMeetmanAsync()
{
var response = await _httpClient.GetAsync(_httpClient.BaseAddress);
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<List<Meetman>>(json, _jsonOptions);
}
}