Skip to content

Instantly share code, notes, and snippets.

View shammelburg's full-sized avatar

Sander Hammelburg shammelburg

View GitHub Profile
@shammelburg
shammelburg / ErrorHandlingMiddleware.cs
Last active September 25, 2017 08:03
ErrorHandlingMiddleware
public class ErrorHandlingMiddleware
{
private readonly RequestDelegate _next;
private readonly EmailSettings _settings;
public ErrorHandlingMiddleware(RequestDelegate next, IOptions<EmailSettings> settings)
{
_next = next;
_settings = settings.Value;
}
@shammelburg
shammelburg / udt.cs
Last active April 5, 2022 18:05
Passing UDT into SP using EF Core
//https://forums.asp.net/t/2071573.aspx?Call+SQL+Server+Function+with+UDT+as+input+parameter
public async Task<int> MainCategorySort(int BrandId, IEnumerable<MainCategoryViewModel> vm, string ModifiedBy)
{
var udt = new DataTable();
udt.Columns.Add("MainCategoryId", typeof(int));
udt.Columns.Add("CMSOrder", typeof(int));
foreach(var item in vm)
@shammelburg
shammelburg / controller.cs
Last active August 15, 2017 11:45
Windows Auth CORS for .Net Core
// [DisableCors]
[Authorize]
[Route("api/[controller]")]
public class AuthController : Controller
{
private AuthicationSettings _authSettings { get; set; }
public AuthController(IOptions<AuthicationSettings> settings)
{
_authSettings = settings.Value;
@shammelburg
shammelburg / win-auth-dotnet-core.xml
Created July 5, 2017 13:06
Windows Auth for .Net Core
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\WebApiCore3.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true"/>
</system.webServer>
</configuration>
<!--ProjectGuid: f6a83dd6-0abf-4ebf-bc7e-b4e620ca6fa9-->
Email Validator: ^[a-zA-Z0–9_.+-]+@[a-zA-Z0–9-]+.[a-zA-Z0–9.]+$
@shammelburg
shammelburg / converttoxml.cs
Last active May 25, 2017 08:46
Collection to Xml
public static string DataTableToXML(DataTable dt)
{
var stringwriter = new System.IO.StringWriter();
var serializer = new XmlSerializer(dt.GetType());
serializer.Serialize(stringwriter, dt);
stringwriter.ToString();
System.IO.StringWriter writer = new System.IO.StringWriter();
writer = new System.IO.StringWriter();
@shammelburg
shammelburg / excel.cs
Created May 8, 2017 10:24
Create an excel file
string fileName = string.Empty;
var grid = new System.Web.UI.WebControls.GridView();
grid.DataSource = _db.spArtworkContentReport_ContentOnly_DI_Buyer(true, false).ToList();
fileName = "DataReport";
grid.DataBind();
Response.ClearContent();
@shammelburg
shammelburg / delete-json.cs
Created March 27, 2017 07:55
CRUD for .json file
private void Delete(string Customer)
{
// not tested
var array = Read().Item1;
var path = Read().Item2;
array.RemoveAt(array.FindIndex(x => x.Customer.Equals(Customer)));
string jsonData = JsonConvert.SerializeObject(array);
File.WriteAllText(path, jsonData);
@shammelburg
shammelburg / connection.cs
Created February 9, 2017 09:41
A partial class for connecting to ASP.NET Core with full .NET framework from a Class Library using ADO.NET Entity Data Model
using System.Data.Common;
using System.Data.Entity.Core.EntityClient;
namespace DataAccessLayer.Models
{
public partial class MyEntities
{
public MyEntities(string connString)
: base(GetSqlConnection(connString), true)
{
@shammelburg
shammelburg / HttpClient.cs
Created January 25, 2017 12:06
Using HttpClient and Deserialize
using (var client = new HttpClient())
{
var data = client.GetAsync(new Uri($"{AppSettingsHelper.api_url}/Controller/Action?Parameter={variable}")).Result;
string json = data.Content.ReadAsStringAsync().Result;
list = JsonConvert.DeserializeObject<List<ViewModel>>(json);
}