Skip to content

Instantly share code, notes, and snippets.

@crgrieve
crgrieve / BlogController.cs
Created April 6, 2021 16:08
Umbraco dotnet core API controller with annotations
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using Umbraco.Cms.Core;
using Umbraco.Cms.Web.Common.Controllers;
using Umbraco.Extensions;
using Umbracov9AlphaAPIs.APIModels;
namespace Umbracov9AlphaAPIs.Controllers
{
[ApiController]
@crgrieve
crgrieve / Startup.cs
Last active May 2, 2023 11:40
Umbraco v9 startup.cs with Swagger
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Extensions;
namespace Umbraco.Cms.Web.UI.NetCore
@crgrieve
crgrieve / DiscordWebhookComposer.cs
Created October 17, 2020 09:26
Umbraco Discord Webhook
using System;
using System.IO;
using System.Net;
using System.Web.Script.Serialization;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Services.Implement;
namespace WebhooksExample.Events
{
@crgrieve
crgrieve / Startup.cs
Created October 30, 2021 08:34
Snippet of startup to add our notifications
public void ConfigureServices(IServiceCollection services)
{
services.AddUmbraco(_env, _config)
.AddBackOffice()
.AddWebsite()
.AddPublishNotifications()
.AddComposers()
.Build();
}
@crgrieve
crgrieve / NotificationsHandler.cs
Created October 30, 2021 08:28
Notifications example for v9
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Core.Notifications;
namespace UmbracoHackathon.Notifications
{
public static class NotificationsHandler
@crgrieve
crgrieve / DiscordNotification.cs
Created October 30, 2021 08:19
Discord notification for on publish in Umbraco
using Newtonsoft.Json;
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
namespace UmbracoHackathon.Notifications
@crgrieve
crgrieve / Program.cs
Last active September 3, 2021 22:14
C#10 filescoped namespace
namespace Umbracov9DotNet6;
public class Program
{
public static void Main(string[] args)
=> CreateHostBuilder(args)
.Build()
.Run();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
@crgrieve
crgrieve / Startup.cs
Created September 3, 2021 21:13
C#9 API Startup.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using System;
@crgrieve
crgrieve / Program.cs
Created September 3, 2021 21:12
C#9 API Program.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace dotnet5API
@crgrieve
crgrieve / Program.cs
Created September 3, 2021 21:08
C#10 API program.cs
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new() { Title = "dotnet6PreviewAPI", Version = "v1" });