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 GetAllData() { dbhelper dbh = new dbhelper(); dbh.Get_Tabledata("Select * from Beruf", false, true); //dbh.dsdaten.Tables[0].WriteXml("n:\\berufe.xml"); return dbh.ConvertDataTable(dbh.dsdaten.Tables[0]); } public static List GetAllAktiveData() { dbhelper dbh = new dbhelper(); dbh.Get_Tabledata("Select * from Beruf where aktiv=1 order by bezeichnung", false, true); return dbh.ConvertDataTable(dbh.dsdaten.Tables[0]); } public static List GetByID(int ID) { dbhelper dbh = new dbhelper(); dbh.Get_Tabledata("Select * from Beruf where id=" + ID.ToString(), false, true); return dbh.ConvertDataTable(dbh.dsdaten.Tables[0]); } public static List GetLast() { dbhelper dbh = new dbhelper(); dbh.Get_Tabledata("Select top 1 * from Beruf order by mutiert_am desc", false, true); return dbh.ConvertDataTable(dbh.dsdaten.Tables[0]); } public static List 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(dbh.dsdaten.Tables[0]); } public static List GetbyUserSQL(string SQL) { dbhelper dbh = new dbhelper(); dbh.Get_Tabledata(SQL, false, true); return dbh.ConvertDataTable(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 tmplst = GetLastByMutierer(Berufdata.mutierer); return tmplst.First().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 GetBerufsangebot() { dbhelper dbh = new dbhelper(); string sql = ""; sql = "SELECT distinct dbo.Beruf.ID, dbo.Beruf.bezeichnung "; //, dbo.Beruf.lehrjahre, dbo.Beruf.anmerkung, dbo.Beruf.beschreibung, dbo.Beruf.klasseNr, dbo.Beruf.aktiv, dbo.Beruf.erstellt_am, dbo.Beruf.mutiert_am, dbo.Beruf.mutierer,"; //sql += "dbo.Beruf.mandantnr "; sql += "FROM dbo.FirmaBeruf INNER JOIN "; sql += "dbo.Firma ON dbo.FirmaBeruf.firmaID = dbo.Firma.ID INNER JOIN "; sql += "dbo.Beruf ON dbo.FirmaBeruf.berufID = dbo.Beruf.ID "; sql += "WHERE(dbo.Beruf.aktiv = 1) AND(dbo.FirmaBeruf.aktiv = 1) AND(dbo.Firma.aktiv = 1) AND(dbo.Firma.aktuell = 1) order by dbo.beruf.bezeichnung"; dbh.Get_Tabledata(sql, false, true); return dbh.ConvertDataTable(dbh.dsdaten.Tables[0]); } } }