You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
4.1 KiB
117 lines
4.1 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BWPMModels;
|
|
using BlazorApp.Helper;
|
|
using Newtonsoft.Json;
|
|
using System.Data;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BlazorApp.Controller
|
|
|
|
{
|
|
|
|
public class SchuelerController : ControllerBase
|
|
{
|
|
public static List<Schueler> GetAllData()
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabledata("Select * from Schueler", false, true);
|
|
return dbh.ConvertDataTable<Schueler>(dbh.dsdaten.Tables[0]);
|
|
}
|
|
|
|
public static List<Schueler> GetByID(int ID)
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabledata("Select * from Schueler where id=" + ID.ToString(), false, true);
|
|
return dbh.ConvertDataTable<Schueler>(dbh.dsdaten.Tables[0]);
|
|
}
|
|
|
|
public static List<Schueler> GetByKlasseID(int ID)
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabledata("Select * from Schueler where aktiv=1 and klasseid=" + ID.ToString()+" order by name, vorname", false, true);
|
|
return dbh.ConvertDataTable<Schueler>(dbh.dsdaten.Tables[0]);
|
|
}
|
|
public static List<Schueler> GetLast()
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabledata("Select top 1 * from Schueler order by mutiert_am desc", false, true);
|
|
return dbh.ConvertDataTable<Schueler>(dbh.dsdaten.Tables[0]);
|
|
}
|
|
public static List<Schueler> GetLastByMutierer(string Mutierer)
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabledata("Select top 1 * from Schueler where mutierer='" + Mutierer + "' order by mutiert_am desc", false, true);
|
|
return dbh.ConvertDataTable<Schueler>(dbh.dsdaten.Tables[0]);
|
|
}
|
|
|
|
public static List<Schueler> GetbyUserSQL(string SQL)
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabledata(SQL, false, true);
|
|
return dbh.ConvertDataTable<Schueler>(dbh.dsdaten.Tables[0]);
|
|
}
|
|
|
|
public static int POST(Schueler Schuelerdata)
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Schueler] where id=-1", false, true);
|
|
DataRow dr = dbh.dsdaten.Tables[0].NewRow();
|
|
Schuelerdata.GetType().GetProperties().ToList().ForEach(f =>
|
|
{
|
|
try
|
|
{
|
|
if (f.PropertyType == typeof(DateTime))
|
|
{
|
|
dr[f.Name] = (DateTime)f.GetValue(Schuelerdata, null);
|
|
|
|
}
|
|
else
|
|
{
|
|
dr[f.Name] = f.GetValue(Schuelerdata, null);
|
|
}
|
|
}
|
|
catch (Exception ex) { string s = ex.Message; }
|
|
});
|
|
dbh.dsdaten.Tables[0].Rows.Add(dr);
|
|
dbh.Update_Tabeldata();
|
|
List<Schueler> tmplst = GetLastByMutierer(Schuelerdata.mutierer);
|
|
return tmplst.First<Schueler>().ID;
|
|
}
|
|
|
|
public static void PUT(Schueler Schuelerdata)
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Schueler] where id=" + Schuelerdata.ID.ToString(), false, true);
|
|
DataRow dr = dbh.dsdaten.Tables[0].Rows[0];
|
|
Schuelerdata.GetType().GetProperties().ToList().ForEach(f =>
|
|
{
|
|
try
|
|
{
|
|
if (f.PropertyType == typeof(DateTime))
|
|
{
|
|
dr[f.Name] = (DateTime)f.GetValue(Schuelerdata, null);
|
|
}
|
|
else
|
|
{
|
|
dr[f.Name] = f.GetValue(Schuelerdata, null);
|
|
}
|
|
}
|
|
catch (Exception ex) { string s = ex.Message; }
|
|
});
|
|
dbh.Update_Tabeldata();
|
|
|
|
}
|
|
|
|
public static void DELETE(Schueler Schuelerdata)
|
|
{
|
|
dbhelper dbh = new dbhelper();
|
|
dbh.Get_Tabeldata_for_Update("delete from [Schueler] where id=" + Schuelerdata.ID.ToString(), false, true);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|