logik im controller
This commit is contained in:
parent
2e2ad49d0c
commit
a4542b5f4b
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.Controls;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
@ -9,12 +10,12 @@ namespace AquaCare.View
|
|||||||
{
|
{
|
||||||
public partial class PflegeWindow : Window
|
public partial class PflegeWindow : Window
|
||||||
{
|
{
|
||||||
private readonly Datenbank _datenbank;
|
private readonly PflegeController _controller;
|
||||||
|
|
||||||
public PflegeWindow()
|
public PflegeWindow()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_datenbank = new Datenbank();
|
_controller = new PflegeController(new Datenbank());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
@ -38,30 +39,35 @@ namespace AquaCare.View
|
|||||||
return;
|
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,
|
Console.WriteLine("Erfolg: Werte erfolgreich gespeichert.");
|
||||||
Gefuettert = GefuettertCheckBox.IsChecked ?? false,
|
|
||||||
FilterReinigen = FilterReinigenCheckBox.IsChecked ?? false,
|
|
||||||
WasserWechseln = WasserWechselnCheckBox.IsChecked ?? false,
|
|
||||||
Temperatur = temperatur,
|
|
||||||
PhWert = phWert,
|
|
||||||
Nitrat = nitrat,
|
|
||||||
Ammoniak = ammoniak
|
|
||||||
};
|
|
||||||
|
|
||||||
_datenbank.AddValue(neuerWert);
|
// Eingabefelder zurücksetzen
|
||||||
Console.WriteLine("Erfolg: Werte erfolgreich gespeichert.");
|
DatumPicker.SelectedDate = null;
|
||||||
|
GefuettertCheckBox.IsChecked = false;
|
||||||
// Eingabefelder zurücksetzen
|
FilterReinigenCheckBox.IsChecked = false;
|
||||||
DatumPicker.SelectedDate = null;
|
WasserWechselnCheckBox.IsChecked = false;
|
||||||
GefuettertCheckBox.IsChecked = false;
|
TemperaturBox.Text = string.Empty;
|
||||||
FilterReinigenCheckBox.IsChecked = false;
|
PhBox.Text = string.Empty;
|
||||||
WasserWechselnCheckBox.IsChecked = false;
|
NitratBox.Text = string.Empty;
|
||||||
TemperaturBox.Text = string.Empty;
|
AmmoniakBox.Text = string.Empty;
|
||||||
PhBox.Text = string.Empty;
|
}
|
||||||
NitratBox.Text = string.Empty;
|
else
|
||||||
AmmoniakBox.Text = string.Empty;
|
{
|
||||||
|
Console.WriteLine("Fehler: Werte konnten nicht gespeichert werden.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
Binary file not shown.
Loading…
Reference in New Issue
Block a user