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.

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