Skip to content

Instantly share code, notes, and snippets.

@zappan
Created August 29, 2011 19:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zappan/9d9283419c4921ad1b52 to your computer and use it in GitHub Desktop.
Save zappan/9d9283419c4921ad1b52 to your computer and use it in GitHub Desktop.
Massive repository wrapper class - FanClub demo
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
public static class Repository
{
public static IEnumerable<dynamic> GetFanClubArticles()
{
var now = DateTime.Now;
var tblArticles = new Articles();
return tblArticles.All // although a bit more complicated compared to direct query, this is DB agnostic, so let's leave it that way
( columns: "publishDate, title, leadText"
, where: @"publishDate < @0
AND expiryDate >= @1
AND deleted = 0"
, orderBy: "publishDate DESC"
, limit: 5
, args: new object[] { now, now }
);
}
public static IEnumerable<dynamic> GetActiveOffers()
{
var today = DateTime.Now.Date;
var tblOffers = new FanClubOffer();
return tblOffers.Query // direct SQL query, may be DB specific
(@" SELECT *
FROM FanClubOffer
INNER JOIN FanClubCategory ON FanClubOffer.offerCategoryId = FanClubCategory.categoryId
INNER JOIN FanClubPartner ON FanClubOffer.offerPartnerId = FanClubPartner.partnerId
WHERE
offerStarts <= @0
AND (offerEnds IS NULL OR offerEnds >= @0)
ORDER BY
FanClubCategory.categoryDisplayOrder ASC
, CASE WHEN offerEnds Is NULL Then 1 Else 0 End ASC
, offerEnds ASC
", today);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment