Update 07082021
This commit is contained in:
114
CoreWebAPI1/Controllers/AnredeController.cs
Normal file
114
CoreWebAPI1/Controllers/AnredeController.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreWebAPI1.Models;
|
||||
using BWPMModels;
|
||||
using System.Data;
|
||||
using SecuringWebApiUsingApiKey.Attributes;
|
||||
|
||||
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace CoreWebAPI1.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
|
||||
public class AnredeController : ControllerBase
|
||||
{
|
||||
// GET: api/<AnredeController>
|
||||
[HttpGet]
|
||||
|
||||
public List<Anrede> Get()
|
||||
{
|
||||
dbhelper dbh = new dbhelper();
|
||||
//dbh.Get_Tabledata("Select * from [Anrede]", false, true);
|
||||
|
||||
List<BWPMModels.Anrede> Details = new List<BWPMModels.Anrede>();
|
||||
return dbh.ConvertDataTable<BWPMModels.Anrede>(dbh.Get_Tabledata("Select * from [Anrede]", false, true));
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("usersql/{sql}")]
|
||||
public List<Anrede> GetLast(string sql)
|
||||
{
|
||||
dbhelper dbh = new dbhelper();
|
||||
List<BWPMModels.Anrede> Details = new List<BWPMModels.Anrede>();
|
||||
return dbh.ConvertDataTable<BWPMModels.Anrede>(dbh.Get_Tabledata(sql, false, true));
|
||||
}
|
||||
|
||||
// GET api/<AnredeController>/5
|
||||
[HttpGet("{id}")]
|
||||
public List<Anrede> Get(int id)
|
||||
{
|
||||
dbhelper dbh = new dbhelper();
|
||||
List<Anrede> Details = new List<Anrede>();
|
||||
return dbh.ConvertDataTable<Anrede>(dbh.Get_Tabledata("Select * from [Anrede] where id=" + id.ToString(), false, true));
|
||||
}
|
||||
|
||||
// POST api/<AnredeController>
|
||||
[HttpPost]
|
||||
public void Post([FromBody] Anrede Anrede)
|
||||
{
|
||||
dbhelper dbh = new dbhelper();
|
||||
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Anrede] where id=-1", false, true);
|
||||
DataRow dr = dbh.dsdaten.Tables[0].NewRow();
|
||||
Anrede.GetType().GetProperties().ToList().ForEach(f =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (f.PropertyType == typeof(DateTime))
|
||||
{
|
||||
dr[f.Name] = (DateTime)f.GetValue(Anrede, null);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dr[f.Name] = f.GetValue(Anrede, null);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { string s = ex.Message; }
|
||||
});
|
||||
dbh.dsdaten.Tables[0].Rows.Add(dr);
|
||||
dbh.Update_Tabeldata();
|
||||
}
|
||||
|
||||
// PUT api/<AnredeController>/5
|
||||
[HttpPut("{id}")]
|
||||
public void Put(int id, [FromBody] Anrede Anrede)
|
||||
{
|
||||
dbhelper dbh = new dbhelper();
|
||||
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Anrede] where id=" + id.ToString(), false, true);
|
||||
DataRow dr = dbh.dsdaten.Tables[0].Rows[0];
|
||||
Anrede.GetType().GetProperties().ToList().ForEach(f =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (f.PropertyType == typeof(DateTime))
|
||||
{
|
||||
dr[f.Name] = (DateTime)f.GetValue(Anrede, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
dr[f.Name] = f.GetValue(Anrede, null);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) { string s = ex.Message; }
|
||||
});
|
||||
dbh.Update_Tabeldata();
|
||||
|
||||
}
|
||||
|
||||
// DELETE api/<AnredeController>/5
|
||||
[HttpDelete("{id}")]
|
||||
public void Delete(int id)
|
||||
{
|
||||
dbhelper dbh = new dbhelper();
|
||||
dbh.Get_Tabeldata_for_Update("Select top 1 * from [Anrede] where id=" + id, false, true);
|
||||
DataRow dr = dbh.dsdaten.Tables[0].Rows[0];
|
||||
dr["Aktiv"] = false;
|
||||
dr["mutiert_am"] = DateTime.Now;
|
||||
dbh.Update_Tabeldata();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user