Fan website of IMMORTAL: Gates of Pyre.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

68 lines
1.1 KiB

using System.Net.Http.Json;
using Model.Immortal.Notes;
using Model.Work.Git;
#if NO_SQL
#else
using Contexts;
using Microsoft.EntityFrameworkCore;
#endif
namespace Services.Work;
public class NoteService : INoteService {
private readonly HttpClient httpClient;
private bool isLoaded;
private event Action _onChange;
private void NotifyDataChanged() {
_onChange?.Invoke();
}
public NoteService(HttpClient httpClient) {
this.httpClient = httpClient;
}
public List<NoteModel> NoteModels { get; set; }
public void Subscribe(Action action) {
_onChange += action;
}
public void Unsubscribe(Action action) {
_onChange -= action;
}
public bool IsLoaded() {
return isLoaded;
}
public async Task Load() {
if (isLoaded) {
return;
}
NoteModels = (await httpClient.GetFromJsonAsync<NoteModel[]>("generated/NoteModels.json")).ToList();
isLoaded = true;
NotifyDataChanged();
}
public void Update() {
NotifyDataChanged();
}
}