Create a gist now

Instantly share code, notes, and snippets.

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