-
-
Save zappan/9d9283419c4921ad1b52 to your computer and use it in GitHub Desktop.
Massive repository wrapper class - FanClub demo
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; | |
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