Skip to content

Instantly share code, notes, and snippets.


Randle csharpforevermore

View GitHub Profile
csharpforevermore / Index.cshtml
Created Sep 26, 2021
Example of JavaScript plugin jQuery connecting to MVC ApiController
View Index.cshtml
@using MyWebAPjQuery.WebAPI.Controllers
<div class="jumbotron">
<h1>ASP.NET jQuery to Web API AJAX call</h1>
<p class="lead">This sentence has a class that denotes it as a lead phrase.</p>
<div class="row">
<div class="col-md-4">
<h2>My MVC API AJAX Call</h2>
<form id="form1">
Name :- <input type="text" name="name" id="name" value="Chris" />
csharpforevermore / test_connection.ps1
Created Aug 30, 2021
How to test your connection string using Powershell
View test_connection.ps1
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=(local);Database=Sample;Integrated Security=True;"
csharpforevermore / gist:383c91e37d5ad030c9dae7ae1834d878
Created Aug 30, 2021
How to test your connection string using Powershell
View gist:383c91e37d5ad030c9dae7ae1834d878
$conn = New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = "Server=(local)\SQLEXPRESS;Database=SampleDatabase;Integrated Security=True;"
csharpforevermore / EnterInteger.cs
Created Aug 28, 2021
User input for an integer
View EnterInteger.cs
int X;
String Result = Console.ReadLine();
while(!Int32.TryParse(Result, out X))
Console.WriteLine("Not a valid number, try again.");
Result = Console.ReadLine();
csharpforevermore / ClassParser.cs
Created Jul 22, 2021
Lists out the methods of the class Student
View ClassParser.cs
public void GetMethodsUsingReflection()
MethodInfo[] methodInfos = typeof(Student).GetMethods();
foreach (MethodInfo methodInfo in methodInfos)
Response.Write(Environment.NewLine + methodInfo.Name);
csharpforevermore / AssertionExamples.cs
Last active Jun 25, 2021
Examples of NUnit and Moq assertions
View AssertionExamples.cs
public void SetUp()
_MockRepository = new MockRepository(MockBehavior.Strict);
_MockLogger = _MockRepository.Create<ILogger<TagController>>();
_MockTagManager = _MockRepository.Create<ITagManager>();
_MockApplicationConfigManager = _MockRepository.Create<IApplicationConfigManager>();
View changeindex.js
function detach(element) {
return element.parentElement.removeChild(element);
function move(src, dest, isBefore) {
dest.insertAdjacentElement(isBefore ? 'beforebegin' : 'afterend', detach(src));
function children(element, selector) {
return element.querySelectorAll(selector);
csharpforevermore / TableToPoco.sql
Created May 20, 2021
Stored Procedure that generates a POCO from SQL
View TableToPoco.sql
-- =============================================
-- Author: Chris Randle
-- Create date: 17/02/2021
-- Description: Converts a SQL table into a basic CLR object (a "POCO" or "plain old CLR object")
-- =============================================
ALTER PROCEDURE [dbo].[TableToPoco]
csharpforevermore / EntityCache.cs
Created Apr 14, 2021
MVC Core cache example - create one per entity and use DI to inject
View EntityCache.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Logging;
using Paige.Caching.BaseCache;
using Paige.ModelLayer.Enums;
using Paige.ModelLayer.Interfaces.Cache;
csharpforevermore / styles.css
Last active Nov 19, 2020
Common CSS tips and tricks - taken from YouTube video -
View styles.css
// always (definitely!) centre
.ex1 .parent {
display: grid;
place: centre;