doc(Project Data) Document on using data in project

This commit is contained in:
2022-04-11 11:59:02 -04:00
parent 7cd289f98a
commit 4285c0e1ed
6 changed files with 51 additions and 69 deletions
+38 -32
View File
@@ -1,20 +1,18 @@
using System.Net.Http.Json;
using Contexts;
using Microsoft.EntityFrameworkCore;
using System.Net.Http.Json;
using Model.Work.Tasks;
namespace Services.Development;
public class AgileService : IAgileService {
public class AgileService : IAgileService
{
private readonly HttpClient httpClient;
private bool isLoaded;
private event Action OnChange = default!;
public AgileService(HttpClient httpClient) {
public AgileService(HttpClient httpClient)
{
this.httpClient = httpClient;
}
@@ -23,47 +21,53 @@ public class AgileService : IAgileService {
public List<AgileSprintModel>? AgileSprintModels { get; set; }
public List<AgileTaskModel>? AgileTaskModels { get; set; }
#else
private DatabaseContext Database { get; set; }
public DbSet<SprintModel> SprintModels => Database.SprintModels;
public DbSet<TaskModel> TaskModels => Database.TaskModels;
#endif
public void Subscribe(Action? action) {
public void Subscribe(Action? action)
{
OnChange += action;
}
public void Unsubscribe(Action? action) {
public void Unsubscribe(Action? action)
{
OnChange -= action;
}
public bool IsLoaded() {
public bool IsLoaded()
{
return isLoaded;
}
#if NO_SQL
public async Task Load() {
if (isLoaded) {
return;
}
public async Task Load()
{
if (isLoaded) return;
AgileSprintModels =
(await httpClient.GetFromJsonAsync<AgileSprintModel[]>("generated/AgileSprintModels.json")
?? Array.Empty<AgileSprintModel>()).ToList();
AgileTaskModels =
(await httpClient.GetFromJsonAsync<AgileTaskModel[]>("generated/AgileTaskModels.json")
?? Array.Empty<AgileTaskModel>()).ToList();
SortSql();
AgileSprintModels = (await httpClient.GetFromJsonAsync<AgileSprintModel[]>("generated/AgileSprintModels.json")?? Array.Empty<AgileSprintModel>() ).ToList();
AgileTaskModels = (await httpClient.GetFromJsonAsync<AgileTaskModel[]>("generated/AgileTaskModels.json") ?? Array.Empty<AgileTaskModel>()).ToList();
foreach (var agileTask in AgileTaskModels)
{
if (agileTask.AgileSprintModelId != null)
{
SprintById(agileTask.AgileSprintModelId.Value)?.AgileTaskModels.Add(agileTask);
}
}
isLoaded = true;
NotifyDataChanged();
}
private void SortSql()
{
foreach (var agileTask in AgileTaskModels!)
if (agileTask.AgileSprintModelId != null)
SprintById(agileTask.AgileSprintModelId.Value)?.AgileTaskModels.Add(agileTask);
}
private AgileSprintModel? SprintById(int id)
{
foreach (var data in AgileSprintModels!)
@@ -72,7 +76,7 @@ public class AgileService : IAgileService {
return null;
}
private AgileTaskModel? TaskById(int id)
{
foreach (var data in AgileTaskModels!)
@@ -81,7 +85,7 @@ public class AgileService : IAgileService {
return null;
}
#else
public async Task Load(DatabaseContext database) {
Database = database;
@@ -101,11 +105,13 @@ public class AgileService : IAgileService {
}
#endif
public void Update() {
public void Update()
{
NotifyDataChanged();
}
private void NotifyDataChanged() {
private void NotifyDataChanged()
{
OnChange?.Invoke();
}
}
+2 -2
View File
@@ -68,7 +68,7 @@ public class DocumentationService : IDocumentationService
#endif
//TODO Until SQL work in production. Or, why even add SQL?
SortSQL();
SortSql();
isLoaded = true;
@@ -92,7 +92,7 @@ public class DocumentationService : IDocumentationService
return null;
}
private void SortSQL()
private void SortSql()
{
foreach (var connection in DocConnectionModels)
{