Skip to content

Instantly share code, notes, and snippets.

View mahizsas's full-sized avatar

MAHIZ mahizsas

View GitHub Profile
@mahizsas
mahizsas / Demo-Entity-Framework.cs
Last active August 29, 2015 14:12 — forked from hudo/Program.cs
Create Standalone Entity-Framework Model-Test
class Program
{
static void Main(string[] args)
{
Database.SetInitializer(new DropCreateDatabaseAlways<PeopleContext>());
var context = new PeopleContext();
context.Database.Log = Console.WriteLine; // so we can inspect SQL statements
AddOnePerson(context);
Dropping Database.
Rebuild Database with latest Schema.
Load basic test environment data.
Loading basic account data.
Opening outer Transaction scope
Executing test 1.
Executing test 2.
Roll back transaction scope.
@mahizsas
mahizsas / DatabaseServerStatusController.cs
Last active August 29, 2015 14:08 — forked from darrelmiller/gist:972f01aa64c6e5df37df
DatabaseServerStatusController
using System;
using System.Data;
using System.Data.SqlClient;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using Newtonsoft.Json.Linq;
@mahizsas
mahizsas / web.config
Last active August 29, 2015 14:08 — forked from wullemsb/web.config
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="X-UA-Compatible" value="IE=Edge" />
</customHeaders>
</httpProtocol>
<system.webServer>
@constellates
constellates / timeago.filter.js
Last active August 29, 2015 14:03 — forked from rodyhaddad/timeago.filter.js
A time ago filter with built in timezone conversion from a UTC time source.
.filter('timeago', function () {
/*
* time: the time
* local: compared to what time? default: now
* raw: wheter you want in a format of "5 minutes ago", or "5 minutes"
*/
// parse string date to milliseconds
// Note: months are 0-based

Owin Authentication with Web API 2

Using Microsoft.Owin.Security along with .NET Web API 2 for authentication on Single Page Applications.

My example is split up into 2 different projects, API which is WebAPI2 project and MyProj which is a basic MVC that contains primarily only JavaScript/CSS/etc and the startup classes.

API > AccountController.cs

namespace API

{

@mhinze
mhinze / BaseController.cs
Created November 19, 2013 19:43
BaseController.cs with Async
using System.Threading.Tasks;
using System.Web.Mvc;
using JetBrains.Annotations;
using ShortBus;
public abstract class BaseController : Controller
{
public IMediator Mediator { get; set; }
protected Response<TResult> Query<TResult>(IQuery<TResult> query)
public static class HtmlExtensions
{
public static IHtmlString DropDownListFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, Dictionary<string, IEnumerable<SelectListItem>> selectList)
{
/*
* <select name="tmodel">
* <optgroup title="Items">
* <option value="item">Item</option>
* </select>
*/
@rarous
rarous / Maybe.cs
Last active December 16, 2015 01:29
using System;
using System.Collections.Generic;
using System.Linq;
public interface Maybe<T> { }
public class Nothing<T> : Maybe<T> { }
public class Just<T> : Maybe<T> {
public T Value { get; private set; }
@mahizsas
mahizsas / DbContext.cs
Created April 5, 2013 07:05
Flat DbEntityValidationException errors
public override int SaveChanges()
{
try
{
return base.SaveChanges();
}
catch (DbEntityValidationException ex)
{
// Retrieve the error messages as a list of strings.
var errorMessages = ex.EntityValidationErrors