This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using(var scope = new TransactionScope(TransactionScopeOption.Required, | |
new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) | |
{ | |
// Do something | |
context.SaveChanges(); | |
// Do something else | |
context.SaveChanges(); | |
scope.Complete(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.replaceAll = function( token, newToken, ignoreCase ) { | |
var _token; | |
var str = this + ""; | |
var i = -1; | |
if ( typeof token === "string" ) { | |
if ( ignoreCase ) { | |
_token = token.toLowerCase(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://www.peterprovost.org/blog/2012/06/16/unit-testing-asp-dot-net-web-api/ | |
private static void SetupControllerForTests(ApiController controller) | |
{ | |
var config = new HttpConfiguration(); | |
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/api/products"); | |
var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}"); | |
var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "products" } }); | |
controller.ControllerContext = new HttpControllerContext(config, routeData, request); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string[] names = new string[] { "Bill", "Jane", "Bob", "Frank" }; | |
var Bs_1 = names.Where(delegate(string s) { return s.StartsWith("B"); }); // Delegate | |
var Bs_2 = names.Where(s => s.StartsWith("B")); // Lambda |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tasks = new Task[10]; | |
for (var i = 0; i < 10; i++) | |
{ | |
var x = i; | |
tasks[i] = Task.Factory.StartNew(() => new WorkerClass(x).Do()); | |
} | |
Task.WaitAll( tasks ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string GetJsonFromURL(string url) | |
{ | |
var request = WebRequest.Create(url); | |
var response = request.GetResponse(); | |
var dataStream = response.GetResponseStream(); | |
var reader = new StreamReader(dataStream); | |
string json = HttpUtility.HtmlDecode(reader.ReadToEnd()); | |
reader.Close(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void RegisterRoutes(RouteCollection routes) | |
{ | |
routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); | |
routes.MapRoute( | |
name: "CustomRoute", | |
url: "{controller}/{action}/{startYear}/{startMonth}/{startDay}/{endYear}/{endMonth}/{endDay}", | |
defaults: new | |
{ | |
controller = "Home", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Install-Package EntityFramework.SqlServerCompact -version 6.0.1 | |
Install-Package MvcScaffolding -Version 1.0.8-vs2013 -Pre | |
public class Category { | |
public int CategoryId { get; set; } | |
public string Name { get; set; } | |
} | |
public class Product | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net.Http; | |
using System.Threading.Tasks; | |
namespace RequestBinExample | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// first install this NuGet package: Install-Package ftplib | |
static void Main(string[] args) | |
{ | |
using (var tConn = new FtpConnection("00.000.00.000", "UserName", "Password")) | |
{ | |
tConn.Open(); | |
tConn.Login(); | |
if (tConn.DirectoryExists("/www")) |