logik im controller
This commit is contained in:
parent
6233525e3c
commit
1d335663ba
46
AquaCare.Controller/PflegeController.cs
Normal file
46
AquaCare.Controller/PflegeController.cs
Normal file
@ -0,0 +1,46 @@
|
||||
using AquaCare.Model;
|
||||
using AquaCare.Persistence;
|
||||
|
||||
namespace AquaCare.Controller
|
||||
{
|
||||
public class PflegeController
|
||||
{
|
||||
private readonly Datenbank _db;
|
||||
|
||||
public PflegeController(Datenbank db)
|
||||
{
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public bool SavePflegeTask(DateTime datum, bool gefuettert, bool filterReinigen,
|
||||
bool wasserWechseln, double temperatur, double phWert, double nitrat, double ammoniak)
|
||||
{
|
||||
try
|
||||
{
|
||||
var wert = new Werte
|
||||
{
|
||||
Datum = datum,
|
||||
Gefuettert = gefuettert,
|
||||
FilterReinigen = filterReinigen,
|
||||
WasserWechseln = wasserWechseln,
|
||||
Temperatur = temperatur,
|
||||
PhWert = phWert,
|
||||
Nitrat = nitrat,
|
||||
Ammoniak = ammoniak
|
||||
};
|
||||
|
||||
_db.AddValue(wert);
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Werte> GetAllWerte()
|
||||
{
|
||||
return _db.GetValuesAsObjects();
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -1,3 +1,4 @@
|
||||
using AquaCare.Controller;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
@ -9,12 +10,12 @@ namespace AquaCare.View
|
||||
{
|
||||
public partial class PflegeWindow : Window
|
||||
{
|
||||
private readonly Datenbank _datenbank;
|
||||
private readonly PflegeController _controller;
|
||||
|
||||
public PflegeWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
_datenbank = new Datenbank();
|
||||
_controller = new PflegeController(new Datenbank());
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
@ -38,30 +39,35 @@ namespace AquaCare.View
|
||||
return;
|
||||
}
|
||||
|
||||
var neuerWert = new Werte
|
||||
var success = _controller.SavePflegeTask(
|
||||
DatumPicker.SelectedDate.Value.DateTime,
|
||||
GefuettertCheckBox.IsChecked ?? false,
|
||||
FilterReinigenCheckBox.IsChecked ?? false,
|
||||
WasserWechselnCheckBox.IsChecked ?? false,
|
||||
temperatur,
|
||||
phWert,
|
||||
nitrat,
|
||||
ammoniak
|
||||
);
|
||||
|
||||
if (success)
|
||||
{
|
||||
Datum = DatumPicker.SelectedDate.Value.DateTime,
|
||||
Gefuettert = GefuettertCheckBox.IsChecked ?? false,
|
||||
FilterReinigen = FilterReinigenCheckBox.IsChecked ?? false,
|
||||
WasserWechseln = WasserWechselnCheckBox.IsChecked ?? false,
|
||||
Temperatur = temperatur,
|
||||
PhWert = phWert,
|
||||
Nitrat = nitrat,
|
||||
Ammoniak = ammoniak
|
||||
};
|
||||
Console.WriteLine("Erfolg: Werte erfolgreich gespeichert.");
|
||||
|
||||
_datenbank.AddValue(neuerWert);
|
||||
Console.WriteLine("Erfolg: Werte erfolgreich gespeichert.");
|
||||
|
||||
// Eingabefelder zurücksetzen
|
||||
DatumPicker.SelectedDate = null;
|
||||
GefuettertCheckBox.IsChecked = false;
|
||||
FilterReinigenCheckBox.IsChecked = false;
|
||||
WasserWechselnCheckBox.IsChecked = false;
|
||||
TemperaturBox.Text = string.Empty;
|
||||
PhBox.Text = string.Empty;
|
||||
NitratBox.Text = string.Empty;
|
||||
AmmoniakBox.Text = string.Empty;
|
||||
// Eingabefelder zurücksetzen
|
||||
DatumPicker.SelectedDate = null;
|
||||
GefuettertCheckBox.IsChecked = false;
|
||||
FilterReinigenCheckBox.IsChecked = false;
|
||||
WasserWechselnCheckBox.IsChecked = false;
|
||||
TemperaturBox.Text = string.Empty;
|
||||
PhBox.Text = string.Empty;
|
||||
NitratBox.Text = string.Empty;
|
||||
AmmoniakBox.Text = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Fehler: Werte konnten nicht gespeichert werden.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user