Skip to content

Instantly share code, notes, and snippets.

@bcnzer
bcnzer / Startup.cs
Last active September 26, 2016 07:44
Example of a Startup configuration
public class Startup
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", true, true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
.AddEnvironmentVariables();
@bcnzer
bcnzer / appsettings.json
Created September 26, 2016 08:05
Sample appsettings.json
{
"ApplicationInsights": {
"InstrumentationKey": "ABC123"
},
"ConnectionStrings": {
"DefaultConnection": "Server=BostonCreme\\donutfactorysecrets;Database=donutfactorydb;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"Logging": {
"IncludeScopes": false,
"LogLevel": {
@bcnzer
bcnzer / project.json
Last active September 26, 2016 09:11
Snippet from project.json showing how to add Views folder
"publishOptions": {
"include": [
"wwwroot",
"Views",
"web.config"
]
},
@bcnzer
bcnzer / project.json
Created January 2, 2017 00:03
project.json with Moq
{
"dependencies": {
"dotnet-test-xunit": "1.0.0-*",
"Microsoft.AspNetCore.TestHost": "1.0.0",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
},
"Moq": "4.6.38-alpha",
"Newtonsoft.Json": "9.0.1",
@bcnzer
bcnzer / StorageLocation.cs
Created February 13, 2017 19:03
List of storage locations based on isHardcover
public class StorageLocation
{
public bool IsHardcover { get; set; }
public string LocationName { get; set; }
}
// My static storage data, for the purposes of this demo
private readonly List<StorageLocation> _locations = new List<StorageLocation>()
{
new StorageLocation() { IsHardcover = true, LocationName = "General Circulation" },
@bcnzer
bcnzer / BookDetailsController.cs
Created February 13, 2017 19:06
Simple method to get a list of storage locations
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult StorageLocations(bool isHardcover)
{
var locations = _locations.Where(x => x.IsHardcover).ToList();
return Json(locations);
}
<form asp-controller="BookDetails" asp-action="BookDetail" id="bookForm" method="post">
@Html.AntiForgeryToken()
<!-- all my other form controls would be somewhere in here -->
<fieldset>
<label asp-for="IsHardcover" class="label"></label>
<label class="select">
<select asp-for="IsHardcover">
<option value="true">Yes</option>
@bcnzer
bcnzer / scripts.cshtml
Last active January 5, 2018 20:04
Portion of the cshtml containing the JQuery
@section Scripts {
<script type="text/javascript">
function determineStorageLocation() {
var token = $('input[name="__RequestVerificationToken"]', $('#bookForm')).val();
var myData = { isHardcover: $("#IsHardcover").val() };
var dataWithAntiforgeryToken = $.extend(myData, { '__RequestVerificationToken': token });
$.ajax({
url: "/BookDetails/StorageLocations",
type: "POST",
@bcnzer
bcnzer / SetCsProjVersion.ps1
Last active November 3, 2022 22:01
Powershell script for generating a version number and inserting it into the csproj
$csprojPath = $args[0] # path to the file i.e. 'C:\Users\ben\Code\csproj powershell\MySmallLibrary.csproj'
$newVersion = $args[1] # the build version, from VSTS build i.e. "1.1.20170323.1"
Write-Host "Starting process of generating new version number for the csproj"
$splitNumber = $newVersion.Split(".")
if( $splitNumber.Count -eq 4 )
{
$majorNumber = $splitNumber[0]
$minorNumber = $splitNumber[1]
@bcnzer
bcnzer / MySmallLIbrary.csproj
Created March 23, 2017 17:33
Sample csproj with a version number
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.4</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Description>I entered a really nice description. This will show up later in my build</Description>
<Version>1.2.3.4</Version>
</PropertyGroup>
</Project>