Skip to content

Instantly share code, notes, and snippets.

@DalSoft
DalSoft / ExampleModel.cs
Created January 10, 2012 12:33
ASP.NET MVC 3 - Improved JsonValueProviderFactory using Json.Net
//Example of a model that won't work with the current JsonValueProviderFactory but will work with JsonDotNetValueProviderFactory
public class CmsViewModel
{
public bool IsVisible { get; set; }
public string Content { get; set; }
public DateTime Modified { get; set; }
public DateTime Created { get; set; }
//This property will not work with the current JsonValueProviderFactory
public dynamic UserDefined { get; set; }
}
@DalSoft
DalSoft / RavenDBNinjectModule
Created April 11, 2012 15:43
MVC – Get RavenDB up and running in 5 minutes using Ninject
using Ninject;
using Ninject.Modules;
using Ninject.Web.Common;
using Raven.Client;
using Raven.Client.Embedded;
using Raven.Database.Server;
namespace RavenDBInFiveMinutes
{
public class RavenDBNinjectModule : NinjectModule
public static IDictionary<string, object> GetUnobtrusiveValidationAttributesFor<TModel, TValue>(this HtmlHelper<TModel> html, Expression<Func<TModel, TValue>> expression)
{
return html.GetUnobtrusiveValidationAttributes(ExpressionHelper.GetExpressionText(expression));
}
public class MyAppConfig : JsonConfig<MyAppConfig>
{
public string Website { get; set; }
public string DatabaseConnectionString { get; set; }
}
<appSettings>
<add key="MyAppConfig" value="
{
'Website': 'http://dalsoft.co.uk/',
'DatabaseConnectionString': 'Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;'
}" />
</appSettings>
@DalSoft
DalSoft / Raygun4NetExtensions.cs
Last active August 29, 2015 14:03
Stop Raygun4Net logging RawData and other sensitive data
using System.Collections.Generic;
using System.Web;
using Mindscape.Raygun4Net.Messages;
namespace Logging.Extensions
{
public static class Raygun4NetExtensions
{
public static void SetNonSensitiveHttpDetails(this RaygunMessage message)
{
@DalSoft
DalSoft / h1.css
Last active August 29, 2015 14:09
Introducing Brunch Below is a trivial example, it's obviously not a production quality and is for brevity just to show brunch working http://www.dalsoft.co.uk/blog/index.php/2014/10/15/introducing-brunch
h1 {
font-size: 3rem;
color:red;
}
@DalSoft
DalSoft / Get.cs
Last active August 29, 2015 14:14
Introducing DalSoft.RestClient the dynamic rest client
dynamic client = new RestClient("http://jsonplaceholder.typicode.com");
var post = await client.Posts(1).Get();
Assert.That(post.HttpResponseMessage.StatusCode, Is.EqualTo(HttpStatusCode.OK));
Assert.That(post.id, Is.EqualTo(1));
@DalSoft
DalSoft / Put.cs
Last active June 3, 2021 09:28
Introducing DalSoft.RestClient the dynamic rest client
dynamic client = new RestClient("http://jsonplaceholder.typicode.com");
var post = new { title = "foo", body = "bar", userId = 10 };
var result = await client.Posts(1).Put(post);
Assert.That(result.title, Is.EqualTo(post.title));
Assert.That(result.body, Is.EqualTo(post.body));
Assert.That(result.userId, Is.EqualTo(post.userId));
Assert.That(result.HttpResponseMessage.StatusCode, Is.EqualTo(HttpStatusCode.OK));
@DalSoft
DalSoft / CreateMessage.cs
Last active August 29, 2015 14:21
DalSoft.RestClient - dynamic C# rest client in action PushWoosh SDK
// Method /createMessage https://www.pushwoosh.com/programming-push-notification/pushwoosh-push-notification-remote-api/#PushserviceAPI-Method-messages-create
dynamic pushwoosh = new RestClient("https://cp.pushwoosh.com/json/1.3");
var pushWooshResponse = await pushwoosh.CreateMessage.Post(new
{
request = new
{
application = "APPLICATION_CODE",
auth = "API_ACCESS_TOKEN",
notifications = new[] { new {
send_date = "now", // YYYY-MM-DD HH:mm OR 'now'