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 MenuItemController : ControllerBase { // GET: api/ [HttpGet] public List Get() { dbhelper dbh = new dbhelper(); dbh.Get_Tabledata("Select * from [MenuItem] order by parentid, sort", false, true); return dbh.ConvertDataTable(dbh.Get_Tabledata("Select * from [MenuItem] order by parentid, sort", false, true)); } // GET api//5 [HttpGet("{id}")] public List Get(int id) { dbhelper dbh = new dbhelper(); List Details = new List(); return dbh.ConvertDataTable(dbh.Get_Tabledata("Select * from menuitem where aktiv=1 and ( menutype=100 or menutype=1 or menutype = " + id.ToString() + ") order by menutype,parentid, sort",false,true)); } // POST api/ [HttpPost] public void Post([FromBody] MenuItem MenuItem) { dbhelper dbh = new dbhelper(); dbh.Get_Tabeldata_for_Update("Select top 1 * from [MenuItem] where id=-1", false, true); DataRow dr = dbh.dsdaten.Tables[0].NewRow(); MenuItem.GetType().GetProperties().ToList().ForEach(f => { try { if (f.PropertyType == typeof(DateTime)) { dr[f.Name] = (DateTime)f.GetValue(MenuItem, null); } else { dr[f.Name] = f.GetValue(MenuItem, null); } } catch (Exception ex) { string s = ex.Message; } }); dbh.dsdaten.Tables[0].Rows.Add(dr); dbh.Update_Tabeldata(); } // PUT api//5 [HttpPut("{id}")] public void Put(int id, [FromBody] MenuItem MenuItem) { dbhelper dbh = new dbhelper(); dbh.Get_Tabeldata_for_Update("Select top 1 * from [MenuItem] where id=" + id.ToString(), false, true); DataRow dr = dbh.dsdaten.Tables[0].Rows[0]; MenuItem.GetType().GetProperties().ToList().ForEach(f => { try { if (f.PropertyType == typeof(DateTime)) { dr[f.Name] = (DateTime)f.GetValue(MenuItem, null); } else { dr[f.Name] = f.GetValue(MenuItem, null); } } catch (Exception ex) { string s = ex.Message; } }); dbh.Update_Tabeldata(); } // DELETE api//5 [HttpDelete("{id}")] public void Delete(int id) { dbhelper dbh = new dbhelper(); dbh.Get_Tabeldata_for_Update("Select top 1 * from [MenuItem] where id=" + id, false, true); DataRow dr = dbh.dsdaten.Tables[0].Rows[0]; dr["Aktiv"] = false; dr["mutiert_am"] = DateTime.Now; dbh.Update_Tabeldata(); } } }