public static List<EditHistory> GetHistoryList(string orderBy, int pageNumber, int pageSize,
Guid siteID, bool showLatestOnly, DateTime? editDate, Guid? editUserID)
{
SortParm srt = new SortParm(orderBy);
if (String.IsNullOrEmpty(srt.SortField)) {
srt.SortField = "EditDate";
}
if (String.IsNullOrEmpty(srt.SortDirection)) {
srt.SortDirection = "DESC";
}
Guid userID = Guid.Empty;
if (editUserID.HasValue) {
userID = editUserID.Value;
}
DateTime dateStart = DateTime.UtcNow.Date.AddDays(-2);
DateTime dateEnd = DateTime.UtcNow.Date.AddDays(1);
if (editDate.HasValue) {
dateStart = editDate.Value.Date.AddDays(-8);
dateEnd = editDate.Value.Date.AddDays(1);
}
int startRec = pageNumber * pageSize;
if (pageSize < 0 || pageSize > 200) {
pageSize = 25;
}
if (pageNumber < 0 || pageNumber > 10000) {
pageNumber = 0;
}
bool IsContentProp = false;
srt.SortField = (from p in ReflectionUtilities.GetPropertyStrings(typeof(vw_carrot_EditHistory))
where p.ToLowerInvariant().Trim() == srt.SortField.ToLowerInvariant().Trim()
select p).FirstOrDefault();
if (!String.IsNullOrEmpty(srt.SortField)) {
IsContentProp = ReflectionUtilities.DoesPropertyExist(typeof(vw_carrot_EditHistory), srt.SortField);
}
using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) {
List<EditHistory> _history = null;
IQueryable<vw_carrot_EditHistory> QueryInput = (from h in _db.vw_carrot_EditHistories
where h.SiteID == siteID
&& (!showLatestOnly || h.IsLatestVersion == true)
&& (!editDate.HasValue
|| (h.EditDate.Date >= dateStart.Date && h.EditDate.Date <= dateEnd.Date))
&& (!editUserID.HasValue || h.EditUserId == userID)
select h);
if (IsContentProp) {
QueryInput = ReflectionUtilities.SortByParm<vw_carrot_EditHistory>(QueryInput, srt.SortField, srt.SortDirection);
} else {
QueryInput = (from c in QueryInput
orderby c.EditDate descending
where c.SiteID == siteID
select c).AsQueryable();
}
_history = (from h in QueryInput.Skip(startRec).Take(pageSize) select new EditHistory(h)).ToList();
return _history;
}
}