Initial commit
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
namespace Services.Website;
|
||||
|
||||
public class DialogService { }
|
||||
@@ -0,0 +1,95 @@
|
||||
using Model.Website.Enums;
|
||||
|
||||
namespace Services.Website;
|
||||
|
||||
public class NavigationService : INavigationService {
|
||||
private string navigationStateType = NavigationStateType.Default;
|
||||
|
||||
private NavSelectionType navSelectionType = NavSelectionType.None;
|
||||
|
||||
private Type renderType;
|
||||
private int webPageType;
|
||||
private int webSectionType;
|
||||
|
||||
public void Subscribe(Action action) {
|
||||
_onChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action action) {
|
||||
_onChange += action;
|
||||
}
|
||||
|
||||
public void ChangeNavigationState(string newState) {
|
||||
if (newState.Equals(navigationStateType))
|
||||
return;
|
||||
|
||||
navigationStateType = newState;
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public string GetNavigationState() {
|
||||
return navigationStateType;
|
||||
}
|
||||
|
||||
public void SelectPage(int pageType, Type page) {
|
||||
if (renderType != page) {
|
||||
renderType = page;
|
||||
webPageType = pageType;
|
||||
navSelectionType = NavSelectionType.Page;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SelectSection(int section) {
|
||||
if (section == webSectionType) return;
|
||||
webSectionType = section;
|
||||
navSelectionType = NavSelectionType.Section;
|
||||
|
||||
Console.WriteLine(webSectionType);
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public void Back() {
|
||||
if (navSelectionType == NavSelectionType.Page) {
|
||||
navSelectionType = NavSelectionType.Section;
|
||||
webPageType = 0;
|
||||
NotifyDataChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
if (navSelectionType == NavSelectionType.Section) {
|
||||
navSelectionType = NavSelectionType.None;
|
||||
webSectionType = 0;
|
||||
webPageType = 0;
|
||||
NotifyDataChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public NavSelectionType GetNavSelectionType() {
|
||||
return navSelectionType;
|
||||
}
|
||||
|
||||
public int GetWebPageId() {
|
||||
return webPageType;
|
||||
}
|
||||
|
||||
public int GetWebSectionId() {
|
||||
return webSectionType;
|
||||
}
|
||||
|
||||
public Type GetRenderType() {
|
||||
return renderType;
|
||||
}
|
||||
|
||||
private event Action _onChange;
|
||||
|
||||
private void NotifyDataChanged() {
|
||||
_onChange?.Invoke();
|
||||
}
|
||||
|
||||
public Action OnChange() {
|
||||
return _onChange;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Net.Http.Json;
|
||||
using Contexts;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Model.Website;
|
||||
|
||||
namespace Services.Work;
|
||||
|
||||
public class WebsiteService : IWebsiteService {
|
||||
private readonly HttpClient httpClient;
|
||||
|
||||
private bool isLoaded;
|
||||
|
||||
public WebsiteService(HttpClient httpClient) {
|
||||
this.httpClient = httpClient;
|
||||
}
|
||||
|
||||
private DatabaseContext Database { get; set; }
|
||||
public DbSet<WebSectionModel> WebSectionModels => Database.WebSectionModels;
|
||||
public DbSet<WebPageModel> WebPageModels => Database.WebPageModels;
|
||||
|
||||
public void Subscribe(Action action) {
|
||||
_onChange += action;
|
||||
}
|
||||
|
||||
public void Unsubscribe(Action action) {
|
||||
_onChange -= action;
|
||||
}
|
||||
|
||||
public bool IsLoaded() {
|
||||
return isLoaded;
|
||||
}
|
||||
|
||||
public async Task Load(DatabaseContext database) {
|
||||
Database = database;
|
||||
|
||||
if (isLoaded) return;
|
||||
|
||||
Database.WebPageModels.AddRange(await httpClient.GetFromJsonAsync<WebPageModel[]>("generated/WebPageModels.json"));
|
||||
Database.WebSectionModels.AddRange(
|
||||
await httpClient.GetFromJsonAsync<WebSectionModel[]>("generated/WebSectionModels.json"));
|
||||
|
||||
Database.SaveChanges();
|
||||
|
||||
isLoaded = true;
|
||||
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
NotifyDataChanged();
|
||||
}
|
||||
|
||||
private event Action _onChange;
|
||||
|
||||
private void NotifyDataChanged() {
|
||||
_onChange?.Invoke();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user