Architecture
Add DI, Interfaces, Repositories
This commit is contained in:
@@ -8,6 +8,9 @@ using System.Windows.Input;
|
||||
using CommunityToolkit.Maui.Alerts;
|
||||
using CommunityToolkit.Maui.Core;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using Jugenddienst_Stunden.Interfaces;
|
||||
using Jugenddienst_Stunden.Repositories;
|
||||
using Jugenddienst_Stunden.Services;
|
||||
|
||||
|
||||
namespace Jugenddienst_Stunden.ViewModels;
|
||||
@@ -15,6 +18,7 @@ namespace Jugenddienst_Stunden.ViewModels;
|
||||
/// ViewModel für die Stundenliste
|
||||
/// </summary>
|
||||
internal partial class StundenViewModel : ObservableObject, IQueryAttributable, INotifyPropertyChanged {
|
||||
private readonly IHoursService _hoursService;
|
||||
|
||||
public ICommand NewEntryCommand { get; }
|
||||
public ICommand SelectEntryCommand { get; }
|
||||
@@ -156,7 +160,13 @@ internal partial class StundenViewModel : ObservableObject, IQueryAttributable,
|
||||
/// <summary>
|
||||
/// CTOR
|
||||
/// </summary>
|
||||
public StundenViewModel() {
|
||||
public StundenViewModel() : this(GetServiceOrCreate()) {
|
||||
}
|
||||
|
||||
private static IHoursService GetServiceOrCreate() => new HoursService(new HoursRepository());
|
||||
|
||||
internal StundenViewModel(IHoursService hoursService) {
|
||||
_hoursService = hoursService;
|
||||
Hours = new Hours();
|
||||
|
||||
LoadOverview = "Lade Summen für " + DateToday.ToString("MMMM");
|
||||
@@ -200,9 +210,9 @@ internal partial class StundenViewModel : ObservableObject, IQueryAttributable,
|
||||
/// </summary>
|
||||
private async Task LoadData() {
|
||||
try {
|
||||
BaseResponse dat = await HoursBase.LoadBase("hours&year=" + DateToday.ToString("yyyy") + "&month=" + DateToday.ToString("MM"));
|
||||
Hours = dat.hour;
|
||||
Settings = dat.settings;
|
||||
var (hours, settings) = await _hoursService.GetMonthSummaryAsync(DateToday);
|
||||
Hours = hours;
|
||||
Settings = settings;
|
||||
|
||||
if (Settings.Version != AppInfo.Current.VersionString.Substring(0, 5)) {
|
||||
InfoEvent?.Invoke(this, "Version: " + Settings.Version + " verfügbar (" + AppInfo.Current.VersionString.Substring(0, 5) + " installiert)");
|
||||
@@ -222,11 +232,10 @@ internal partial class StundenViewModel : ObservableObject, IQueryAttributable,
|
||||
DayTotal = new TimeOnly(0);
|
||||
Sollstunden = new TimeOnly(0);
|
||||
try {
|
||||
//_dayTimes = await HoursBase.LoadDay(date);
|
||||
BaseResponse dat = await HoursBase.LoadBase("date=" + date.ToString("yyyy-MM-dd"));
|
||||
var (dayTimes, settings) = await _hoursService.GetDayWithSettingsAsync(date);
|
||||
|
||||
DayTimes = dat.daytimes;
|
||||
Settings = dat.settings;
|
||||
DayTimes = dayTimes;
|
||||
Settings = settings;
|
||||
GemeindeAktivSet = Settings.GemeindeAktivSet;
|
||||
ProjektAktivSet = Settings.ProjektAktivSet;
|
||||
|
||||
@@ -251,9 +260,9 @@ internal partial class StundenViewModel : ObservableObject, IQueryAttributable,
|
||||
|
||||
//Nach der Tagessumme die anderen Tage anhängen
|
||||
if (DayTimes != null) {
|
||||
BaseResponse dat1 = await HoursBase.LoadBase("date=" + date.ToString("yyyy-MM-dd") + "&tilldate=" + date.AddDays(3).ToString("yyyy-MM-dd"));
|
||||
if (dat1.daytimes != null)
|
||||
DayTimes = dat.daytimes.Concat(dat1.daytimes).ToList();
|
||||
var more = await _hoursService.GetDayRangeAsync(date, date.AddDays(3));
|
||||
if (more != null && more.Count > 0)
|
||||
DayTimes = DayTimes.Concat(more).ToList();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
|
||||
Reference in New Issue
Block a user