update 20260522
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,384 @@
|
||||
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;
|
||||
using System.Text.Json;
|
||||
|
||||
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);
|
||||
|
||||
var data = db.dsdaten.Tables[0].Rows.OfType<DataRow>()
|
||||
.Select(row => db.dsdaten.Tables[0].Columns.OfType<DataColumn>()
|
||||
.ToDictionary(col => col.ColumnName, c => row[c]));
|
||||
return Ok(JToken.Parse(System.Text.Json.JsonSerializer.Serialize(data)));
|
||||
|
||||
|
||||
//string JSONresult = JsonConvert.SerializeObject(db.dsdaten.Tables[0]);
|
||||
|
||||
//return Ok(JSONresult);
|
||||
|
||||
//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);
|
||||
|
||||
SQL = "Select * from Antwortadresse where id=@ID";
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@ID", ID);
|
||||
//db.add_parameter("@format", OutFormat.ToLower());
|
||||
db.Get_Tabledata_Addvar(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);
|
||||
|
||||
var data = db.dsdaten.Tables[0].Rows.OfType<DataRow>()
|
||||
.Select(row => db.dsdaten.Tables[0].Columns.OfType<DataColumn>()
|
||||
.ToDictionary(col => col.ColumnName, c => row[c]));
|
||||
return Ok(JToken.Parse(System.Text.Json.JsonSerializer.Serialize(data)));
|
||||
};
|
||||
}
|
||||
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);
|
||||
|
||||
SQL = "Select * from AntwortAdresse_Mitarbeiter where aktiv=1 and tgnummer=@TGNR order by bezeichnung ";
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@TGNR", tgnummer);
|
||||
//db.add_parameter("@format", OutFormat.ToLower());
|
||||
db.Get_Tabledata_Addvar(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);
|
||||
|
||||
var data = db.dsdaten.Tables[0].Rows.OfType<DataRow>()
|
||||
.Select(row => db.dsdaten.Tables[0].Columns.OfType<DataColumn>()
|
||||
.ToDictionary(col => col.ColumnName, c => row[c]));
|
||||
return Ok(JToken.Parse(System.Text.Json.JsonSerializer.Serialize(data)));
|
||||
};
|
||||
}
|
||||
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);
|
||||
|
||||
SQL = "Select * from Antwortadresse_Mitarbeiter where aktiv=1 and Mitarbeiternr=@MANR order by bezeichnung ";
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@MANR", Mitarbeiternr);
|
||||
//db.add_parameter("@format", OutFormat.ToLower());
|
||||
db.Get_Tabledata_Addvar(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);
|
||||
var data = db.dsdaten.Tables[0].Rows.OfType<DataRow>()
|
||||
.Select(row => db.dsdaten.Tables[0].Columns.OfType<DataColumn>()
|
||||
.ToDictionary(col => col.ColumnName, c => row[c]));
|
||||
return Ok(JToken.Parse(System.Text.Json.JsonSerializer.Serialize(data)));
|
||||
};
|
||||
}
|
||||
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);
|
||||
|
||||
SQL = "Select * from AntwortAdresse_Mitarbeiter where id=@id";
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@id", ID);
|
||||
db.add_parameter("@format", OutFormat.ToLower());
|
||||
db.Get_Tabledata_Addvar(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);
|
||||
var data = db.dsdaten.Tables[0].Rows.OfType<DataRow>()
|
||||
.Select(row => db.dsdaten.Tables[0].Columns.OfType<DataColumn>()
|
||||
.ToDictionary(col => col.ColumnName, c => row[c]));
|
||||
return Ok(JToken.Parse(System.Text.Json.JsonSerializer.Serialize(data)));
|
||||
}
|
||||
}
|
||||
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));
|
||||
var data = db.dsdaten.Tables[0].Rows.OfType<DataRow>()
|
||||
.Select(row => db.dsdaten.Tables[0].Columns.OfType<DataColumn>()
|
||||
.ToDictionary(col => col.ColumnName, c => row[c]));
|
||||
return Ok(JToken.Parse(System.Text.Json.JsonSerializer.Serialize(data)));
|
||||
//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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private 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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace API_NetFramework.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.Title = "OnDocAPI";
|
||||
return Redirect("/OnDocAPIHome.aspx");
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using API_NetFramework.Models;
|
||||
using System.Web.WebPages;
|
||||
using System.IO;
|
||||
|
||||
namespace API_NetFramework.Controllers
|
||||
{
|
||||
public class ImageController : ApiController
|
||||
{
|
||||
string tokenfunction = "Image";
|
||||
|
||||
private System.Drawing.Image ResizeImage(System.Drawing.Image imgToResize, Size size)
|
||||
{
|
||||
// Get the image current width
|
||||
int sourceWidth = imgToResize.Width;
|
||||
// Get the image current height
|
||||
int sourceHeight = imgToResize.Height;
|
||||
float nPercent = 0;
|
||||
float nPercentW = 0;
|
||||
float nPercentH = 0;
|
||||
// Calculate width and height with new desired size
|
||||
nPercentW = ((float)size.Width / (float)sourceWidth);
|
||||
nPercentH = ((float)size.Height / (float)sourceHeight);
|
||||
nPercent = Math.Min(nPercentW, nPercentH);
|
||||
// New Width and Height
|
||||
int destWidth = (int)(sourceWidth * nPercent);
|
||||
int destHeight = (int)(sourceHeight * nPercent);
|
||||
Bitmap b = new Bitmap(destWidth, destHeight);
|
||||
Graphics g = Graphics.FromImage((System.Drawing.Image)b);
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
// Draw image with new width and height
|
||||
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
|
||||
g.Dispose();
|
||||
return (System.Drawing.Image)b;
|
||||
}
|
||||
|
||||
private System.Drawing.Image resizeImage(System.Drawing.Image imgToResize, Size size)
|
||||
{
|
||||
return (System.Drawing.Image)(new Bitmap(imgToResize, size));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Route("API/GetImageAsBase64")]
|
||||
|
||||
public IHttpActionResult GetImageAsBase64(int imageid, int ImageWidth = 0, int ImageHeight = 0)
|
||||
{
|
||||
string path = System.Configuration.ConfigurationManager.AppSettings["ImagePath"];
|
||||
string filename = "";
|
||||
int defaultheigt = 0;
|
||||
int defaultwidth = 0;
|
||||
APILogging.Log((HttpRequestMessage)Request, "Image-Bezug: " + imageid.ToString(), LogLevelType.Info);
|
||||
|
||||
//if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
||||
//{
|
||||
// return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
||||
//}
|
||||
System.Data.DataSet ds = new System.Data.DataSet();
|
||||
ds.ReadXml(path + "imageids.xml");
|
||||
filename = "";
|
||||
foreach (System.Data.DataRow row in ds.Tables[0].Rows)
|
||||
{
|
||||
if (Convert.ToInt32(row[0]) == imageid)
|
||||
{
|
||||
defaultheigt = Convert.ToInt32(row[3]);
|
||||
defaultwidth = Convert.ToInt32(row[2]);
|
||||
filename = path + row[1].ToString();
|
||||
}
|
||||
}
|
||||
ds.Dispose();
|
||||
if (filename == "")
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Image-Bezug - nicht vorhanden: " + imageid.ToString(), LogLevelType.Info);
|
||||
return Content(HttpStatusCode.NotFound, "Image ID: " + imageid.ToString()+"nicht gefunden");
|
||||
}
|
||||
|
||||
System.Drawing.Image iimg = System.Drawing.Image.FromFile(filename);
|
||||
System.Drawing.Image imgnew = null;
|
||||
|
||||
switch (ImageWidth)
|
||||
{
|
||||
case 0:
|
||||
ImageWidth =defaultwidth;
|
||||
ImageHeight = defaultheigt;
|
||||
Bitmap b = new Bitmap(iimg);
|
||||
imgnew = ResizeImage(b, new Size(ImageHeight, ImageWidth));
|
||||
b = null;
|
||||
break;
|
||||
case -1:
|
||||
imgnew = iimg;
|
||||
break;
|
||||
default:
|
||||
Bitmap b1 = new Bitmap(iimg);
|
||||
imgnew = ResizeImage(b1, new Size(ImageHeight, ImageWidth));
|
||||
b1 = null;
|
||||
break;
|
||||
|
||||
}
|
||||
using (MemoryStream m = new MemoryStream())
|
||||
{
|
||||
string newfilename = path + Guid.NewGuid().ToString() + ".jpg";
|
||||
imgnew.Save(newfilename);
|
||||
imgnew = System.Drawing.Image.FromFile(newfilename);
|
||||
imgnew.Save(m, imgnew.RawFormat);
|
||||
byte[] imageBytes = m.ToArray();
|
||||
imgnew.Dispose();
|
||||
m.Dispose();
|
||||
//yte[] imageArray = System.IO.File.ReadAllBytes(newfilename);
|
||||
// string base64ImageRepresentation = Convert.ToBase64String(imageArray);
|
||||
System.IO.File.Delete(newfilename);
|
||||
iimg.Dispose();
|
||||
iimg = null;
|
||||
imgnew = null;
|
||||
//return Ok(base64ImageRepresentation);
|
||||
return Ok(Convert.ToBase64String(imageBytes));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,317 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using System.Web.Mvc;
|
||||
|
||||
using System.Configuration;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using SecuringWebApiUsingApiKey.Middleware;
|
||||
using System.Threading.Tasks;
|
||||
using Model;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Web.Http.Results;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Drawing;
|
||||
using Syncfusion.DocIO.DLS;
|
||||
|
||||
|
||||
namespace OnDocAPI_NetFramework.Controllers
|
||||
{
|
||||
public class JsonRequestDto
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Json { get; set; }
|
||||
}
|
||||
|
||||
[System.Web.Http.RoutePrefix("api/json")]
|
||||
public class JsonController : ApiController
|
||||
{
|
||||
|
||||
private readonly string _connectionString = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["DocTesterconnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
||||
|
||||
// 🔹 JSON LESEN
|
||||
[System.Web.Http.HttpGet]
|
||||
[System.Web.Http.Route("load/{key}")]
|
||||
public IHttpActionResult LoadJson(string key)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(key))
|
||||
return BadRequest("Key fehlt");
|
||||
|
||||
string json;
|
||||
|
||||
using (SqlConnection con = new SqlConnection(_connectionString))
|
||||
using (SqlCommand cmd = new SqlCommand(
|
||||
"SELECT JavaScriptObject FROM ProvDokuments WHERE ProvDokumentid = @key", con))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@key", key);
|
||||
con.Open();
|
||||
json = cmd.ExecuteScalar()?.ToString();
|
||||
}
|
||||
|
||||
if (json == null)
|
||||
{
|
||||
using (SqlConnection con = new SqlConnection(_connectionString))
|
||||
using (SqlCommand cmd = new SqlCommand(
|
||||
"SELECT JsonObjekt FROM _OnDoc_API_TestScripts WHERE id = @key", con))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@key", key);
|
||||
con.Open();
|
||||
json = cmd.ExecuteScalar()?.ToString();
|
||||
}
|
||||
if (json == null) return NotFound();
|
||||
}
|
||||
|
||||
return Ok(json);
|
||||
}
|
||||
|
||||
// 🔹 JSON SPEICHERN
|
||||
[System.Web.Http.HttpPost]
|
||||
[System.Web.Http.Route("save")]
|
||||
public IHttpActionResult SaveJson(JsonRequestDto dto)
|
||||
{
|
||||
if (dto == null || string.IsNullOrWhiteSpace(dto.Key))
|
||||
return BadRequest("Key fehlt");
|
||||
|
||||
using (SqlConnection con = new SqlConnection(_connectionString))
|
||||
using (SqlCommand cmd = new SqlCommand(@"
|
||||
IF EXISTS (SELECT 1 FROM _OnDoc_API_TestScripts WHERE id = @key)
|
||||
UPDATE _OnDoc_API_TestScripts SET JsonObjekt =@json
|
||||
WHERE id = @key
|
||||
ELSE
|
||||
INSERT INTO _OnDoc_API_TestScripts (id,JsonObjekt)
|
||||
VALUES (@key, @json)
|
||||
", con))
|
||||
|
||||
//IF EXISTS (SELECT 1 FROM provdokuments WHERE provdokumentid = @key)
|
||||
// UPDATE provdokuments SET JavaScriptObject = @json, geaendertam = GETDATE()
|
||||
// WHERE provdokumentid = @key
|
||||
//ELSE
|
||||
// INSERT INTO provdokuments (provdokumentid,erstelltam,geaendertam, JavaScriptObject)
|
||||
// VALUES (@key, getdate(),getdate(),@json)
|
||||
//", con))
|
||||
{
|
||||
cmd.Parameters.AddWithValue("@key", dto.Key);
|
||||
cmd.Parameters.AddWithValue("@json", dto.Json);
|
||||
con.Open();
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
return Ok();
|
||||
}
|
||||
|
||||
public class JsonRequestDto
|
||||
{
|
||||
public string Key { get; set; }
|
||||
public string Json { get; set; } // ← reiner JSON-String
|
||||
}
|
||||
public class PdfBase64Response
|
||||
{
|
||||
public string PdfBase64 { get; set; }
|
||||
}
|
||||
// 🔹 PDF GENERIEREN
|
||||
[System.Web.Http.HttpPost]
|
||||
[System.Web.Http.Route("GeneratePDF")]
|
||||
public HttpResponseMessage GeneratePdf(JsonRequestDto dto)
|
||||
{
|
||||
|
||||
|
||||
if (dto == null || string.IsNullOrWhiteSpace(dto.Json))
|
||||
return new HttpResponseMessage(HttpStatusCode.BadRequest);
|
||||
|
||||
byte[] pdfBytes = CallExternalPdfApi(dto.Json);
|
||||
|
||||
var response = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
{
|
||||
Content = new ByteArrayContent(pdfBytes)
|
||||
};
|
||||
|
||||
|
||||
response.Content.Headers.ContentType =
|
||||
new MediaTypeHeaderValue("application/pdf");
|
||||
|
||||
response.Content.Headers.ContentDisposition =
|
||||
new ContentDispositionHeaderValue("inline")
|
||||
{
|
||||
FileName = $"{dto.Key}.pdf"
|
||||
};
|
||||
response.Content.Headers.ContentLength = pdfBytes.Length;
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
|
||||
private byte[] CallExternalPdfApi(string json)
|
||||
{
|
||||
|
||||
string ownHost = System.Configuration.ConfigurationManager.AppSettings["OwnHost"];
|
||||
string token = System.Configuration.ConfigurationManager.AppSettings["OwnToken"];
|
||||
string URL = ownHost + "API/DokumentGenerator";
|
||||
|
||||
try
|
||||
{
|
||||
var webRequest = System.Net.WebRequest.Create(URL);
|
||||
if (webRequest != null)
|
||||
{
|
||||
webRequest.Method = "POST";
|
||||
webRequest.Timeout = 20000;
|
||||
webRequest.ContentType = "application/json";
|
||||
webRequest.Headers["Authorization"] = "Bearer " + token;
|
||||
|
||||
using (System.IO.Stream s = webRequest.GetRequestStream())
|
||||
{
|
||||
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(s))
|
||||
sw.Write(json);
|
||||
}
|
||||
|
||||
using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream())
|
||||
{
|
||||
using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
|
||||
{
|
||||
var jsonResponse = sr.ReadToEnd();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//System.IO.File.WriteAllText(@"x:\log.txt", ex.ToString());
|
||||
System.Diagnostics.Debug.WriteLine(ex.ToString());
|
||||
}
|
||||
|
||||
string uri = ownHost + "/API/CreateCLM";
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization =
|
||||
new AuthenticationHeaderValue("Bearer", token);
|
||||
|
||||
client.DefaultRequestHeaders.Accept.Add(
|
||||
new MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
HttpResponseMessage response = client.PostAsync(uri, content).Result;
|
||||
|
||||
|
||||
string responseContent = response.Content.ReadAsStringAsync().Result;
|
||||
|
||||
try
|
||||
{
|
||||
// Erfolgsfall
|
||||
var apiok = JsonConvert.DeserializeObject<APIOK>(responseContent);
|
||||
|
||||
if (!string.IsNullOrEmpty(apiok?.file))
|
||||
{
|
||||
return Convert.FromBase64String(apiok.file);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Fehlerfall
|
||||
var apireturn = JsonConvert.DeserializeObject<APIErrorSimple>(responseContent);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logging.APIDocLog.Error("API-Call fehlgeschlagen", ex.Message,"","");
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
//try
|
||||
//{
|
||||
|
||||
// APIErrorSimple apireturn = new APIErrorSimple();
|
||||
// APIOK apiok = new APIOK();
|
||||
// ;
|
||||
// string jsonstring = json;
|
||||
|
||||
// WebRequest request;
|
||||
|
||||
// var data = Encoding.UTF8.GetBytes(jsonstring);
|
||||
// string OwnHost = System.Configuration.ConfigurationManager.AppSettings["OwnHost"].ToString();
|
||||
// string uri = OwnHost + "/API/CreateCLM";
|
||||
// uri = OwnHost + "/API/DokumentGenerator";
|
||||
// Logging.APIDocLog.Info("URI", "IIS", "123", uri);
|
||||
// request = WebRequest.Create(uri);
|
||||
// request.ContentLength = data.Length;
|
||||
// request.ContentType = "application/json";
|
||||
// request.Method = "POST";
|
||||
// request.Headers["Authorization"] = "Bearer " + System.Configuration.ConfigurationManager.AppSettings["OwnToken"].ToString();
|
||||
|
||||
// try
|
||||
// {
|
||||
|
||||
// using (Stream requestStream = request.GetRequestStream())
|
||||
// {
|
||||
|
||||
// requestStream.Write(data, 0, data.Length);
|
||||
// requestStream.Close();
|
||||
|
||||
// using (Stream responseStream = request.GetResponse().GetResponseStream())
|
||||
// {
|
||||
// using (var reader = new StreamReader(responseStream))
|
||||
// {
|
||||
// var response = reader.ReadToEnd();
|
||||
// try
|
||||
// {
|
||||
|
||||
// apiok = JsonConvert.DeserializeObject<APIOK>(response);
|
||||
// var jo = JObject.Parse(response.ToString());
|
||||
|
||||
// return Convert.FromBase64String(apiok.file);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
|
||||
// apireturn = JsonConvert.DeserializeObject<APIErrorSimple>(response);
|
||||
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
|
||||
// return null;
|
||||
// }
|
||||
//}
|
||||
//catch {
|
||||
// byte[] pdf;
|
||||
// return null;}
|
||||
|
||||
|
||||
//// var request = (HttpWebRequest)WebRequest.Create("https://api.example.com/generate-pdf");
|
||||
////request.Method = "POST";
|
||||
////request.ContentType = "application/json";
|
||||
|
||||
////byte[] payload = Encoding.UTF8.GetBytes(json);
|
||||
////request.ContentLength = payload.Length;
|
||||
|
||||
////using (var stream = request.GetRequestStream())
|
||||
//// stream.Write(payload, 0, payload.Length);
|
||||
|
||||
////using (var response = (HttpWebResponse)request.GetResponse())
|
||||
////using (var rs = response.GetResponseStream())
|
||||
////using (var ms = new MemoryStream())
|
||||
////{
|
||||
//// rs.CopyTo(ms);
|
||||
//// return ms.ToArray();
|
||||
////}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,233 @@
|
||||
using API_NetFramework.Controllers;
|
||||
using API_NetFramework.Models;
|
||||
using Database;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Web.Http;
|
||||
using System.Web.Management;
|
||||
using System.Configuration;
|
||||
using SecuringWebApiUsingApiKey.Middleware;
|
||||
using System.Text;
|
||||
using System.Net.Mail;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace OnDocAPI_NetFramework.Controllers
|
||||
{
|
||||
public class MailController : ApiController
|
||||
{
|
||||
string tokenfunction = "Mail";
|
||||
|
||||
//[HttpGet]
|
||||
//[Route("API/SendPSMail")]
|
||||
private IHttpActionResult SendPSMail(string MailID, string empfaenger, string betreff, string message, string dokumentid, string ondoclink, string absender, string bewilligungid)
|
||||
{
|
||||
string connectionstring = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
||||
string URI = "";
|
||||
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mailversand: " + empfaenger+""+betreff, LogLevelType.Debug);
|
||||
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
||||
{
|
||||
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
||||
}
|
||||
|
||||
if (Regex.IsMatch(empfaenger, @"^\d+$") == false &&!empfaenger.ToUpper().Contains("@TKB.CH"))
|
||||
{
|
||||
return Content(HttpStatusCode.Forbidden, empfaenger + ": Email nicht bei der TKB - Mail nicht versandt");
|
||||
}
|
||||
string s = "";
|
||||
DB db = new DB(connectionstring);
|
||||
try
|
||||
{
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@mailid", MailID.ToString());
|
||||
db.add_parameter("@empf",empfaenger);
|
||||
db.add_parameter("@dokid",dokumentid);
|
||||
db.add_parameter("@absender", absender);
|
||||
db.add_parameter("@bewilligungid", bewilligungid);
|
||||
db.Get_Tabledata("sp_ondoc_maildaten", true, false);
|
||||
if (message == null) { message = ""; }
|
||||
if (betreff == null) { betreff = ""; }
|
||||
if (betreff == "") { betreff = db.dsdaten.Tables[0].Rows[0][1].ToString(); }
|
||||
if (message == "") { message = db.dsdaten.Tables[0].Rows[0][2].ToString(); }
|
||||
if (Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][3]) == 0)
|
||||
{
|
||||
db = null;
|
||||
return Content(HttpStatusCode.OK, empfaenger + ": Mail gem. MA-Einstellung nicht zugestellt");
|
||||
}
|
||||
empfaenger = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
||||
|
||||
|
||||
db = null;
|
||||
|
||||
s = System.Configuration.ConfigurationManager.AppSettings["MailParam"];
|
||||
|
||||
|
||||
s = s.Replace("$$empfaenger$$", empfaenger);
|
||||
s = s.Replace("$$betreff$$", betreff);
|
||||
s = s.Replace("$$body$$", message);
|
||||
|
||||
|
||||
string debugdir = System.Configuration.ConfigurationManager.AppSettings["DebugDir"];
|
||||
string tmpfile = debugdir + @"\Mail_" + DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".ps1";
|
||||
System.IO.File.WriteAllText(tmpfile, s,new UTF8Encoding(true));
|
||||
//StreamWriter writer = new StreamWriter(tmpfile);
|
||||
//writer.Write(s);
|
||||
//writer.Close();
|
||||
//writer.Dispose();
|
||||
System.Diagnostics.Process.Start("powershell.exe", tmpfile);
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand: " + s, LogLevelType.Debug);
|
||||
//return Content(HttpStatusCode.OK, "Mail versand noch nicht implementiert");
|
||||
return Content(HttpStatusCode.OK, empfaenger + ": Mail versandt");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + e.Message+" " + s, LogLevelType.Debug);
|
||||
return Content(HttpStatusCode.InternalServerError, e.Message);
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
[Route("API/SendMail")]
|
||||
public IHttpActionResult SendMail(string MailID, string empfaenger, string betreff, string message, string dokumentid, string ondoclink, string absender, string bewilligungid)
|
||||
{
|
||||
string connectionstring = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
||||
string URI = "";
|
||||
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mailversand: " + empfaenger + "" + betreff, LogLevelType.Debug);
|
||||
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
||||
{
|
||||
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
||||
}
|
||||
|
||||
if (Regex.IsMatch(empfaenger, @"^\d+$") == false && !empfaenger.ToUpper().Contains("@TKB.CH"))
|
||||
{
|
||||
return Content(HttpStatusCode.Forbidden, empfaenger + ": Email nicht bei der TKB - Mail nicht versandt");
|
||||
}
|
||||
string s = "";
|
||||
DB db = new DB(connectionstring);
|
||||
try
|
||||
{
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@mailid", MailID.ToString());
|
||||
db.add_parameter("@empf", empfaenger);
|
||||
db.add_parameter("@dokid", dokumentid);
|
||||
db.add_parameter("@absender", absender);
|
||||
db.add_parameter("@bewilligungid", bewilligungid);
|
||||
db.Get_Tabledata("sp_ondoc_maildaten", true, false);
|
||||
if (message == null) { message = ""; }
|
||||
if (betreff == null) { betreff = ""; }
|
||||
if (betreff == "") { betreff = db.dsdaten.Tables[0].Rows[0][1].ToString(); }
|
||||
if (message == "") { message = db.dsdaten.Tables[0].Rows[0][2].ToString(); }
|
||||
if (Convert.ToInt32(db.dsdaten.Tables[0].Rows[0][3]) == 0)
|
||||
{
|
||||
db = null;
|
||||
return Content(HttpStatusCode.OK, empfaenger + ": Mail gem. MA-Einstelung nicht zugestellt");
|
||||
}
|
||||
empfaenger = db.dsdaten.Tables[0].Rows[0][0].ToString();
|
||||
db = null;
|
||||
|
||||
MailMessage mail = new MailMessage();
|
||||
SmtpClient SmtpServer = new SmtpClient();
|
||||
mail.To.Add(empfaenger);
|
||||
mail.From = new MailAddress("OnDoc@tkb.ch");
|
||||
mail.Subject = betreff;
|
||||
mail.IsBodyHtml = true;
|
||||
mail.Body = message;
|
||||
SmtpServer.Host = "smtp.tgcorp.ch";
|
||||
SmtpServer.Port = 25;
|
||||
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
|
||||
try
|
||||
{
|
||||
SmtpServer.Send(mail);
|
||||
APILogging.Log((HttpRequestMessage)Request, "SMTPMail Versand: " + empfaenger, LogLevelType.Debug);
|
||||
return Content(HttpStatusCode.OK, empfaenger + ": Mail versandt");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + ex.Message + " " + empfaenger, LogLevelType.Debug);
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK - Exception Inner: " + ex.InnerException, LogLevelType.Debug);
|
||||
}
|
||||
return Content(HttpStatusCode.InternalServerError, ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + e.Message + " " + s, LogLevelType.Debug);
|
||||
return Content(HttpStatusCode.InternalServerError, e.Message);
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("API/SendHTMLMail")]
|
||||
public IHttpActionResult SendMailManual()
|
||||
{
|
||||
string result = Request.Content.ReadAsStringAsync().Result;
|
||||
Model.EMail email = new Model.EMail();
|
||||
email = JsonConvert.DeserializeObject<Model.EMail>(result);
|
||||
if (Regex.IsMatch(email.empfaenger, @"^\d+$") == false && !email.empfaenger.ToUpper().Contains("@TKB.CH"))
|
||||
{
|
||||
return Content(HttpStatusCode.Forbidden, email.empfaenger + ": Email nicht bei der TKB - Mail nicht versandt");
|
||||
}
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mailversand: " + email.empfaenger + "" + email.betreff, LogLevelType.Debug);
|
||||
if (SecuringWebApiUsingApiKey.Middleware.ApiKeyMiddleware.Authorized((HttpRequestMessage)Request, tokenfunction) == false)
|
||||
{
|
||||
return Content(HttpStatusCode.Unauthorized, "Invalid Token or API-Key");
|
||||
}
|
||||
email = JsonConvert.DeserializeObject<Model.EMail>(result);
|
||||
if (Regex.IsMatch(email.empfaenger, @"^\d+$") == false && !email.empfaenger.ToUpper().Contains("@TKB.CH"))
|
||||
{
|
||||
return Content(HttpStatusCode.Forbidden, email.empfaenger + ": Email nicht bei der TKB - Mail nicht versandt");
|
||||
}
|
||||
string s = "";
|
||||
|
||||
try
|
||||
{
|
||||
MailMessage mail = new MailMessage();
|
||||
SmtpClient SmtpServer = new SmtpClient();
|
||||
string mailempfaengerdefault = System.Configuration.ConfigurationManager.AppSettings["Mailempfaenger"].ToString();
|
||||
if (email.empfaenger.ToString()=="")
|
||||
{
|
||||
email.empfaenger=mailempfaengerdefault;
|
||||
}
|
||||
//if (mailempfaenger!="") { email.empfaenger=mailempfaenger; }
|
||||
mail.To.Add(email.empfaenger);
|
||||
mail.From = new MailAddress("OnDoc@tkb.ch");
|
||||
mail.Subject = email.betreff;
|
||||
mail.IsBodyHtml = true;
|
||||
mail.Body = email.message;
|
||||
SmtpServer.Host = "smtp.tgcorp.ch";
|
||||
SmtpServer.Port = 25;
|
||||
SmtpServer.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
|
||||
try
|
||||
{
|
||||
SmtpServer.Send(mail);
|
||||
APILogging.Log((HttpRequestMessage)Request, "SMTPMail Versand: " + email.empfaenger, LogLevelType.Debug);
|
||||
return Content(HttpStatusCode.OK, email.empfaenger + ": Mail versandt");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + ex.Message + " " + email.empfaenger, LogLevelType.Debug);
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK - Exception Inner: " + ex.InnerException, LogLevelType.Debug);
|
||||
}
|
||||
return Content(HttpStatusCode.InternalServerError, ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
APILogging.Log((HttpRequestMessage)Request, "Mail Versand NOK: " + e.Message + " " + s, LogLevelType.Debug);
|
||||
return Content(HttpStatusCode.InternalServerError, e.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
|
||||
namespace OnDocAPI_NetFramework.Controllers
|
||||
{
|
||||
public class TokenController : ApiController
|
||||
{
|
||||
[HttpGet]
|
||||
[Route("API/Tokengenerator)")]
|
||||
|
||||
public IHttpActionResult TokenGenerator(string function, string pathphrase)
|
||||
{
|
||||
return Ok(SecuringWebApiUsingApiKey.Middleware.StringCipher.Encrypt (function, pathphrase));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,39 @@
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using System.Net;
|
||||
//using System.Net.Http;
|
||||
//using System.Web.Http;
|
||||
|
||||
//namespace API_NetFramework.Controllers
|
||||
//{
|
||||
// public class ValuesController : ApiController
|
||||
// {
|
||||
// // GET api/values
|
||||
// public IEnumerable<string> Get()
|
||||
// {
|
||||
// return new string[] { "value1", "value2" };
|
||||
// }
|
||||
|
||||
// // GET api/values/5
|
||||
// public string Get(int id)
|
||||
// {
|
||||
// return "value";
|
||||
// }
|
||||
|
||||
// // POST api/values
|
||||
// public void Post([FromBody] string value)
|
||||
// {
|
||||
// }
|
||||
|
||||
// // PUT api/values/5
|
||||
// public void Put(int id, [FromBody] string value)
|
||||
// {
|
||||
// }
|
||||
|
||||
// // DELETE api/values/5
|
||||
// public void Delete(int id)
|
||||
// {
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Web.Http;
|
||||
using DOCGEN;
|
||||
using Model;
|
||||
using Database;
|
||||
using Newtonsoft.Json;
|
||||
using API_NetFramework.Models;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.IO;
|
||||
using System.Web;
|
||||
using System.Net.Mime;
|
||||
using System.Security.Policy;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using System.Security.Cryptography;
|
||||
using System.Net.Http.Headers;
|
||||
using SecuringWebApiUsingApiKey.Middleware;
|
||||
using DOCGEN.Klassen;
|
||||
using CSVNET;
|
||||
using System.Data;
|
||||
using Helper;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Web.UI.WebControls;
|
||||
using edoka_dms;
|
||||
using API_NetFramework.Controllers;
|
||||
|
||||
namespace OnDocAPI_NetFramework.Controllers
|
||||
{
|
||||
public class VersandstrasseController : ApiController
|
||||
{
|
||||
string tokenfunction = "Archiv";
|
||||
string connectionstring = StringCipher.Decrypt(ConfigurationManager.ConnectionStrings["EDOKAConnectionstring"].ConnectionString, "i%!k!7pab%bNLdA5hE4pkR4XaB%E^jB3d9tHuQ4pbF&BZjF7SB#WBWit5#HrbJiLrLVm");
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user