This file contains 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
<div id="credits"> | |
Created by | |
<br /> | |
<a href="http://jgn.me/">Jérôme Gravel-Niquet</a>. <br />Cleanup, edits: <a href="http://addyosmani.com">Addy Osmani</a>. | |
</div> |
This file contains 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 http = require('http'); | |
http.createServer(function (req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.end('Hello World\n'); | |
}).listen(1337, '127.0.0.1'); | |
console.log('Server running at http://127.0.0.1:1337/'); |
This file contains 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
DECLARE @finish int = 8, | |
@start int = 1, | |
@EventDate datetime = '2012-03-13T20:07:25' | |
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY RsvpCount desc | |
) AS RowNumber FROM ( | |
SELECT d.*, COUNT(r.DinnerID) AS RsvpCount | |
FROM Dinners d LEFT OUTER JOIN RSVP r ON d.DinnerID = r.DinnerID | |
WHERE EventDate >= @EventDate |
This file contains 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 interface IDinnerRepository | |
{ | |
Dinner NewDinner(); | |
RSVP NewRsvp(int dinnerId); | |
PagedList<Dinner> FindByLocation(float latitude, float longitude, string orderBy = "DinnerID", int page = 1, int pageSize = 20); | |
PagedList<Dinner> FindUpcomingDinners(string orderBy = "DinnerID", int page = 1, int pageSize = 20); | |
PagedList<Dinner> FindUpcomingDinners(DateTime? eventDate, string orderBy = "DinnerID", int page = 1, int pageSize = 20); | |
PagedList<Dinner> FindDinnersByText(string q, string orderBy = "DinnerID", int page = 1, int pageSize = 20); | |
IEnumerable<Dinner> AllDinnersByUser(string name); |
This file contains 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 PagedList<Dinner> FindDinners(string where, object parameters, string orderBy = "DinnerID", int page = 1, int pageSize = 20) | |
{ | |
using (var connection = MvcApplication.GetOpenConnection()) | |
{ | |
var builder = new SqlBuilder(); | |
var start = (page - 1) * pageSize + 1; | |
var finish = page * pageSize; | |
var selectTemplate = builder.AddTemplate(pagedQuery, new { start, finish }); |
This file contains 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.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using Dapper; | |
using System.Data.Common; | |
namespace DapperDinner.Models | |
{ | |
public class DapperDinnerRepository : IDinnerRepository |
This file contains 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 connection = MvcApplication.GetOpenConnection()) { | |
connection.Delete<Post>( new Post { ID = 1 } ); | |
} |
This file contains 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
// Entity Framework - Delete | |
using (var db = new BlogContext()) { | |
var post = db.Posts.Find(1); | |
db.Posts.Remove(post); | |
db.SaveChanges(); | |
} |
This file contains 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 class ConnectionFactory { | |
public static DbConnection GetOpenConnection() { | |
var connection = new SqlConnection("MyConnectionString"); | |
connection.Open(); | |
return connection; | |
} | |
} |