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.

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