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 AspNetUserRolesController : ControllerBase { public static List GetAllData() { dbhelper dbh = new dbhelper(); dbh.Get_Tabledata("Select * from AspNetUserRoles", false, true); return dbh.ConvertDataTable(dbh.dsdaten.Tables[0]); } public static List GetByID(int ID) { dbhelper dbh = new dbhelper(); dbh.Get_Tabledata("Select * from AspNetUserRoles 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 AspNetUserRoles 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 AspNetUserRoles 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 void POST(AspNetUserRoles AspNetUserRolesdata) { dbhelper dbh = new dbhelper(); dbh.Get_Tabeldata_for_Update("Select top 1 * from [AspNetUserRoles] where userid='-1'", false, true); DataRow dr = dbh.dsdaten.Tables[0].NewRow(); AspNetUserRolesdata.GetType().GetProperties().ToList().ForEach(f => { try { if (f.PropertyType == typeof(DateTime)) { dr[f.Name] = (DateTime)f.GetValue(AspNetUserRolesdata, null); } else { dr[f.Name] = f.GetValue(AspNetUserRolesdata, null); } } catch (Exception ex) { string s = ex.Message; } }); dbh.dsdaten.Tables[0].Rows.Add(dr); dbh.Update_Tabeldata(); } public static void PUT(AspNetUserRoles AspNetUserRolesdata) { dbhelper dbh = new dbhelper(); dbh.Get_Tabeldata_for_Update("Select top 1 * from [AspNetUserRoles] where userid='" + AspNetUserRolesdata.UserId.ToString()+"'", false, true); DataRow dr = dbh.dsdaten.Tables[0].Rows[0]; AspNetUserRolesdata.GetType().GetProperties().ToList().ForEach(f => { try { if (f.PropertyType == typeof(DateTime)) { dr[f.Name] = (DateTime)f.GetValue(AspNetUserRolesdata, null); } else { dr[f.Name] = f.GetValue(AspNetUserRolesdata, null); } } catch (Exception ex) { string s = ex.Message; } }); dbh.Update_Tabeldata(); } public static void DELETE(AspNetUserRoles AspNetUserRolesdata) { dbhelper dbh = new dbhelper(); dbh.Get_Tabeldata_for_Update("delete from [AspNetUserRoles] where id=" + AspNetUserRolesdata.UserId.ToString(), false, true); } } }