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.
325 lines
15 KiB
325 lines
15 KiB
using Database;
|
|
using DOCGEN;
|
|
using Model;
|
|
using API_NetFramework.Models;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Net.Http;
|
|
using System.Runtime.Serialization.Formatters;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using SecuringWebApiUsingApiKey.Middleware;
|
|
using Newtonsoft.Json;
|
|
using System.Web.Http.Results;
|
|
using Microsoft.Ajax.Utilities;
|
|
using System.Data.SqlClient;
|
|
using System.Data;
|
|
using System.Text.RegularExpressions;
|
|
using System.Text;
|
|
using Newtonsoft.Json.Linq;
|
|
using System.Web.Helpers;
|
|
|
|
namespace API_NetFramework.Controllers
|
|
{
|
|
public class AntwortAdresseController : ApiController
|
|
{
|
|
string tokenfunction = "Adresse";
|
|
string connectionstring = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
|
|
|
/// <summary>
|
|
/// GetGetAll liefert alle GAS-Adressen
|
|
/// </summary>
|
|
/// <param name="OutFormat">Optional. The default value is "JSON".Optionaler Parameter: "XML"</param>
|
|
/// <returns></returns>
|
|
/// <remarks></remarks>
|
|
[HttpGet]
|
|
[Route("API/Antwortadresse/GetAll")]
|
|
|
|
public IHttpActionResult GetGetAll(string OutFormat = "JSON")
|
|
{
|
|
//string a = SecuringWebApiUsingApiKey.Middleware.StringCipher.Encrypt("Adresse", "OnDoc");
|
|
//a = SecuringWebApiUsingApiKey.Middleware.StringCipher.Decrypt(a, "OnDoc");
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request,tokenfunction) ==false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start Adresse GetAll", LogLevelType.Debug);
|
|
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
string SQL = "Select * from Antwortadresse order by bezeichnung";
|
|
if (OutFormat == "JSON") { SQL = SQL + " for json path"; }
|
|
if (OutFormat == "XML") { SQL = SQL + " for xml path"; }
|
|
db.Get_Tabledata(SQL, false, true);
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Adresse GetAll", LogLevelType.Debug);
|
|
|
|
return Ok(JToken.Parse(db.dsdaten.Tables[0].Rows[0][0].ToString()));
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request,e.Message,LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
}
|
|
|
|
[HttpGet]
|
|
[Route("API/Antwortadresse/GetByID")]
|
|
/// <summary>
|
|
/// GetByID liefert die GAS-Adresse mit der gewünschten ID
|
|
/// </summary>
|
|
/// <param name="ID">ID der GAS-Adresse</param>
|
|
/// <param name="OutFormat">Optional. The default value is "JSON".Optionaler Parameter: "XML"</param>
|
|
/// <returns></returns>
|
|
/// <remarks></remarks>
|
|
|
|
public IHttpActionResult GetByID(string ID,string OutFormat = "JSON")
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start Adresse GetByID ID:"+ID, LogLevelType.Debug);
|
|
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
string SQL = "Select * from Antwortadresse where id=" + ID;
|
|
if (OutFormat == "JSON") { SQL = SQL + " for json path"; }
|
|
if (OutFormat == "XML") { SQL = SQL + " for xml path"; }
|
|
db.Get_Tabledata(SQL, false, true);
|
|
if (db.dsdaten.Tables[0].Rows.Count == 0) {
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Adresse GetByID ID:" + ID, LogLevelType.Debug);
|
|
|
|
return Ok();
|
|
} else {
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Adresse GetByID ID:" + ID, LogLevelType.Debug);
|
|
|
|
return Ok(JToken.Parse(db.dsdaten.Tables[0].Rows[0][0].ToString()));
|
|
};
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// GetAllMitarbeiterByTGNummer liefert die persönlichen Adressen eines Mitarbeiters
|
|
/// </summary>
|
|
/// <param name="tgnummer">Required. </param>
|
|
/// <param name="OutFormat">Optional. The default value is "JSON".Optionalier Parameter: "XML"</param>
|
|
/// <returns></returns>
|
|
/// <remarks></remarks>
|
|
[HttpGet]
|
|
[Route("API/ntwortAdresse/GetAllMitarbeiterByTGNummer")]
|
|
|
|
public IHttpActionResult GetAllMitarbeiterByTGNummer(string tgnummer, string OutFormat = "JSON")
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start Adresse GetAllMitarbeiterByTGNummer", LogLevelType.Debug);
|
|
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
string SQL = "Select * from AntwortAdresse_Mitarbeiter where aktiv=1 and tgnummer='" + tgnummer + "' order by bezeichnung ";
|
|
if (OutFormat == "JSON") { SQL = SQL + " for json path"; }
|
|
if (OutFormat == "XML") { SQL = SQL + " for xml path"; }
|
|
db.Get_Tabledata(SQL, false, true);
|
|
if (db.dsdaten.Tables[0].Rows.Count == 0) {
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Adresse GetAllMitarbeiterByTGNummer", LogLevelType.Debug);
|
|
|
|
return Ok();
|
|
} else {
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Adresse GetAllMitarbeiterByTGNummer", LogLevelType.Debug);
|
|
|
|
return Ok(JToken.Parse(db.dsdaten.Tables[0].Rows[0][0].ToString()));
|
|
};
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
}
|
|
[HttpGet]
|
|
[Route("API/AntwortAdresse/GetAllMitarbeiterByMitarbeiterNr")]
|
|
/// <summary>
|
|
/// GetAllMitarbeiterByMitarbeiternr liefert die persönlichen Adressen eines Mitarbeiters
|
|
/// </summary>
|
|
/// <param name="Mitarbeiternr">Required. </param>
|
|
/// <param name="OutFormat">Optional. The default value is "JSON".Optionalier Parameter: "XML"</param>
|
|
/// <returns></returns>
|
|
/// <remarks></remarks>
|
|
|
|
public IHttpActionResult GetAllMitarbeiterByMitarbeiterNr(string Mitarbeiternr, string OutFormat = "JSON")
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start Adresse GetAllMitarbeiterByMitarbeiterNr Ma-Nr:"+Mitarbeiternr, LogLevelType.Debug);
|
|
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
string SQL = "Select * from AntwortAdresse_Mitarbeiter where aktiv=1 and Mitarbeiternr='" + Mitarbeiternr + "' ";
|
|
if (OutFormat == "JSON") { SQL = SQL + " for json path"; }
|
|
if (OutFormat == "XML") { SQL = SQL + " for xml path"; }
|
|
db.Get_Tabledata(SQL, false, true);
|
|
if (db.dsdaten.Tables[0].Rows.Count == 0) {
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Adresse GetAllMitarbeiterByMitarbeiterNr Ma-Nr:" + Mitarbeiternr, LogLevelType.Debug);
|
|
return Ok();
|
|
} else {
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende Adresse GetAllMitarbeiterByMitarbeiterNr Ma-Nr:" + Mitarbeiternr, LogLevelType.Debug);
|
|
return Ok(JToken.Parse(db.dsdaten.Tables[0].Rows[0][0].ToString()));
|
|
};
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
[Route("API/AntwortAdresse/GetMitarbeiterByID")]
|
|
/// <summary>
|
|
/// GetMitarbeiterByID liefert eine Mitarbeiter-Adrsse mit der ID
|
|
/// </summary>
|
|
/// <param name="ID">Required. </param>
|
|
/// <param name="OutFormat">Optional. The default value is "JSON".Optionalier Parameter: "XML"</param>
|
|
/// <returns></returns>
|
|
/// <remarks></remarks>
|
|
|
|
public IHttpActionResult GetMitarbeiterByID(string ID, string OutFormat = "JSON")
|
|
{
|
|
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start GetMitarbeiterByID ID: "+ID, LogLevelType.Debug);
|
|
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
string SQL = "Select * from AntwortAdresse_Mitarbeiter where id=" + ID;
|
|
if (OutFormat == "JSON") { SQL = SQL + " for json path"; }
|
|
if (OutFormat == "XML") { SQL = SQL + " for xml path"; }
|
|
db.Get_Tabledata(SQL, false, true);
|
|
if (db.dsdaten.Tables[0].Rows.Count == 0) {
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende GetMitarbeiterByID ID: " + ID, LogLevelType.Debug);
|
|
return Ok();
|
|
} else {
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende GetMitarbeiterByID ID: " + ID, LogLevelType.Debug);
|
|
return Ok(JToken.Parse(db.dsdaten.Tables[0].Rows[0][0].ToString())); };
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
}
|
|
[HttpGet]
|
|
[Route("API/AntwortAdresse/GetMitarbeiterUndStandard")]
|
|
/// <summary>
|
|
/// GetMitarbeiterByID liefert eine Mitarbeiter-Adrsse mit der ID
|
|
/// </summary>
|
|
/// <param name="ID">Required. </param>
|
|
/// <param name="OutFormat">Optional. The default value is "JSON".Optionalier Parameter: "XML"</param>
|
|
/// <returns></returns>
|
|
/// <remarks></remarks>
|
|
/// public IHttpActionResult GetMitarbeiterByID(string ID, string OutFormat = "JSON")
|
|
public IHttpActionResult GetGASAdressen_Einzeilig(string TGNummer, string OutFormat = "JSON")
|
|
{
|
|
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
|
{
|
|
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
|
}
|
|
try
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Start GetGASAdressen_Einzeilig TGNummer: " + TGNummer, LogLevelType.Debug);
|
|
|
|
Database.DB db = new Database.DB(connectionstring);
|
|
db.clear_parameter();
|
|
db.add_parameter("@tgnummer", TGNummer);
|
|
db.add_parameter("@format", OutFormat);
|
|
db.Get_Tabledata("sp_get_gas_einzeilig", true, false);
|
|
if (db.dsdaten.Tables[0].Rows.Count == 0)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende GetGASAdressen_Einzeilig TGNummer: " + TGNummer, LogLevelType.Debug);
|
|
return Content(HttpStatusCode.NotFound, "");
|
|
}
|
|
else
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, "Ende GetGASAdressen_Einzeilig TGNummer: " + TGNummer, LogLevelType.Debug);
|
|
//List<adressresponse> adressen = new List<adressresponse>();
|
|
//foreach (System.Data.DataRow dr in db.dsdaten.Tables[0].Rows)
|
|
//{
|
|
// adressen.Add(new adressresponse() {adresse = dr[0].ToString()});
|
|
//}
|
|
//var token = JToken.Parse(Newtonsoft.Json.JsonConvert.SerializeObject(adressen));
|
|
|
|
return Content(HttpStatusCode.OK, JToken.Parse(db.dsdaten.Tables[0].Rows[0][0].ToString()));
|
|
};
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
APILogging.Log((HttpRequestMessage)Request, e.Message, LogLevelType.Error);
|
|
return Content(HttpStatusCode.InternalServerError, e.Message);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public string DataTableToJsonObj(DataTable dt)
|
|
{
|
|
DataSet ds = new DataSet();
|
|
ds.Merge(dt);
|
|
StringBuilder JsonString = new StringBuilder();
|
|
if (ds != null && ds.Tables[0].Rows.Count > 0)
|
|
{
|
|
JsonString.Append("[");
|
|
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
|
|
{
|
|
JsonString.Append("{");
|
|
for (int j = 0; j < ds.Tables[0].Columns.Count; j++)
|
|
{
|
|
if (j < ds.Tables[0].Columns.Count - 1)
|
|
{
|
|
JsonString.Append("\"" + ds.Tables[0].Columns[j].ColumnName.ToString() + "\":" + "\"" + ds.Tables[0].Rows[i][j].ToString() + "\",");
|
|
}
|
|
else if (j == ds.Tables[0].Columns.Count - 1)
|
|
{
|
|
JsonString.Append("\"" + ds.Tables[0].Columns[j].ColumnName.ToString() + "\":" + "\"" + ds.Tables[0].Rows[i][j].ToString() + "\"");
|
|
}
|
|
}
|
|
if (i == ds.Tables[0].Rows.Count - 1)
|
|
{
|
|
JsonString.Append("}");
|
|
}
|
|
else
|
|
{
|
|
JsonString.Append("},");
|
|
}
|
|
}
|
|
JsonString.Append("]");
|
|
return JsonString.ToString();
|
|
}
|
|
else
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
|
|
}
|
|
} |