Skip to content

Instantly share code, notes, and snippets.

View csharpforevermore's full-sized avatar
💭
Developing

Randle csharpforevermore

💭
Developing
View GitHub Profile
@csharpforevermore
csharpforevermore / TableToPoco.sql
Created May 20, 2021 10:40
Stored Procedure that generates a POCO from SQL
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- 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
csharpforevermore / EntityCache.cs
Created April 14, 2021 19:43
MVC Core cache example - create one per entity and use DI to inject
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
csharpforevermore / styles.css
Last active November 19, 2020 23:07
Common CSS tips and tricks - taken from YouTube video - https://youtu.be/qm0IfG1GyZU
// always (definitely!) centre
.ex1 .parent {
display: grid;
place: centre;
}
@csharpforevermore
csharpforevermore / dev-to_create-new-post_css-fix.css
Last active November 11, 2020 08:13
Fix styling on dev.to create post page. The height of the heading is too low for the font-size, so we'll lower the font-size. We'll also lower the font-size for the actual main body text so we don't omit the first character by having the window scroll slightly when you are editing a line of text and the text wraps to a newline.
/* Fix the title */
#article-form-title{
font-size:12px !important;
}
/* Fix the content body text */
#article_body_markdown{
font-size: 11px;
}
@csharpforevermore
csharpforevermore / WebService.cs
Created September 16, 2020 09:37
Return a PDF as a file from a web API service
[HttpGet]
public FileStreamResult Download()
{
var stream = System.IO.File.OpenRead(AppSettings.PdfFileName);
return new FileStreamResult(stream, AppSettings.MimeType);
}
[HttpGet("open-pdf")]
public IActionResult Get()
{
@csharpforevermore
csharpforevermore / WriteFIle.cs
Created September 9, 2020 20:50
C# - Create a text file - by writing to a path
System.IO.File.WriteAllText(filePath, "Hello World!", System.Text.Encoding.UTF8);
@csharpforevermore
csharpforevermore / filename.cs
Created September 9, 2020 19:19
C# - DotNet - Get a folder to save files in
// C:\Users\cshar\AppData\Local\Temp\tmp4550.tmp
Path.GetTempFileName();
// C:\Users\cshar\AppData\Roaming\DateLinks.csv
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "DateLinks.csv");
// See https://www.mikesdotnetting.com/article/302/server-mappath-equivalent-in-asp-net-core for DotNetCore method
@csharpforevermore
csharpforevermore / MyContentAppFactory_v7.cs
Last active August 25, 2020 01:21
Create a Content App in Umbraco using C# rather than package.manifest. For documentation see the website (https://bit.ly/3jbH1zE), the PDF (https://bit.ly/34t2Iqz) and the YouTube video (https://bit.ly/2EsUELE). You have the code-first or configuration-first approaches. The configuration-first approach uses the package.manifest file. Code-first …
using System.Web.Http.Filters;
using Umbraco.Core.Models.ContentEditing;
using Umbraco.Web.Editors;
using Umbraco.Web.Models.ContentEditing;
public class MyContentAppFactory
{
// Works in v7
public void Initialize() =>
// on startup bind to this event
@csharpforevermore
csharpforevermore / Pluralsight.GetTableOfContentsText.js
Last active August 14, 2020 17:47
This is a jQuery snippet that, when used during a Pluralsight video, will output the Table of Contents text to the debugger console window. I recommend using it with a browser plugin or extension that injects JQuery into the current web page.
$('span.u-truncate').each(function(index){ console.log($(this).text()); })
@csharpforevermore
csharpforevermore / GetUmbracoTagValues.cshtml
Last active May 12, 2020 22:06
Umbraco 8 - output "Tags" backoffice Data Type values. Description: How to output the value of a Tag data type in the View in Umbraco 8 (using both Model Builder version and non-MB version).
@if(!string.IsNullOrEmpty(Request["debug"])){
if(Model.GetProperty("tags") !=null){
<ul>
@foreach(var tag in Model.GetProperty("tags").Value<IEnumerable<string>>()){
<li>@tag</li>
}
</ul>
}
}