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.

110 lines
3.8 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 OptionenController : ControllerBase
{
public static List<Optionen> GetAllData()
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select * from Optionen", false, true);
return dbh.ConvertDataTable<Optionen>(dbh.dsdaten.Tables[0]);
}
public static List<Optionen> GetByID(int ID)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select * from Optionen where id=" + ID.ToString(), false, true);
return dbh.ConvertDataTable<Optionen>(dbh.dsdaten.Tables[0]);
}
public static List<Optionen> GetLast()
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select top 1 * from Optionen order by mutiert_am desc", false, true);
return dbh.ConvertDataTable<Optionen>(dbh.dsdaten.Tables[0]);
}
public static List<Optionen> GetLastByMutierer(string Mutierer)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata("Select top 1 * from Optionen where mutierer='" + Mutierer + "' order by mutiert_am desc", false, true);
return dbh.ConvertDataTable<Optionen>(dbh.dsdaten.Tables[0]);
}
public static List<Optionen> GetbyUserSQL(string SQL)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabledata(SQL, false, true);
return dbh.ConvertDataTable<Optionen>(dbh.dsdaten.Tables[0]);
}
public static int POST(Optionen Optionendata)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Optionen] where id=-1", false, true);
DataRow dr = dbh.dsdaten.Tables[0].NewRow();
Optionendata.GetType().GetProperties().ToList().ForEach(f =>
{
try
{
if (f.PropertyType == typeof(DateTime))
{
dr[f.Name] = (DateTime)f.GetValue(Optionendata, null);
}
else
{
dr[f.Name] = f.GetValue(Optionendata, null);
}
}
catch (Exception ex) { string s = ex.Message; }
});
dbh.dsdaten.Tables[0].Rows.Add(dr);
dbh.Update_Tabeldata();
List<Optionen> tmplst = GetLastByMutierer(Optionendata.mutierer);
return tmplst.First<Optionen>().ID;
}
public static void PUT(Optionen Optionendata)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Optionen] where id=" + Optionendata.ID.ToString(), false, true);
DataRow dr = dbh.dsdaten.Tables[0].Rows[0];
Optionendata.GetType().GetProperties().ToList().ForEach(f =>
{
try
{
if (f.PropertyType == typeof(DateTime))
{
dr[f.Name] = (DateTime)f.GetValue(Optionendata, null);
}
else
{
dr[f.Name] = f.GetValue(Optionendata, null);
}
}
catch (Exception ex) { string s = ex.Message; }
});
dbh.Update_Tabeldata();
}
public static void DELETE(Optionen Optionendata)
{
dbhelper dbh = new dbhelper();
dbh.Get_Tabeldata_for_Update("delete from [Optionen] where id=" + Optionendata.ID.ToString(), false, true);
}
}
}