/// <summary> /// Returns the entries by a keyword. /// </summary> /// <param name="keyword">Search keyword.</param> /// <param name="from">Date From.</param> /// <param name="to">Date To.</param> /// <param name="page">Page number.</param> /// <param name="entriesCount">Number of entries.</param> /// <param name="heo">HistoryEntryOrderBy</param> /// <returns>Returns all the entries</returns> public Entry[] GetEntries(string keyword, DateTime from, DateTime to, int page, int entriesCount, HistoryEntryOrderBy heo) { var col = Database.GetEntries(keyword, from, to, page, entriesCount, heo); if (!col.Any()) { return(new Entry[] { }); } else { return(col.ToArray()); } }
public IEnumerable <Entry> GetEntries(string keyword, DateTime from, DateTime to, int page, int entriesCount, HistoryEntryOrderBy heo) { using (var db = new LiteDatabase(ConnectionString)) { var col = db.GetCollection <Entry>("entries"); var keywordToLower = keyword.ToLower(); int skip = (page - 1) * entriesCount; Query query; if (!string.IsNullOrEmpty(keyword)) { query = Query.And(Query.Or(Query.Contains("Name", keywordToLower), Query.Contains("Description", keywordToLower)) , Query.And(Query.GTE("StatusDate", from), Query.LTE("StatusDate", to))); } else { query = Query.And(Query.GTE("StatusDate", from), Query.LTE("StatusDate", to)); } switch (heo) { case HistoryEntryOrderBy.StatusDateAscending: return(col.Find( Query.And( Query.All("StatusDate") , query ) , skip , entriesCount )); case HistoryEntryOrderBy.StatusDateDescending: return(col.Find( Query.And( Query.All("StatusDate", Query.Descending) , query ) , skip , entriesCount )); case HistoryEntryOrderBy.WorkflowIdAscending: return(col.Find( Query.And( Query.All("WorkflowId") , query ) , skip , entriesCount )); case HistoryEntryOrderBy.WorkflowIdDescending: return(col.Find( Query.And( Query.All("WorkflowId", Query.Descending) , query ) , skip , entriesCount )); case HistoryEntryOrderBy.NameAscending: return(col.Find( Query.And( Query.All("Name") , query ) , skip , entriesCount )); case HistoryEntryOrderBy.NameDescending: return(col.Find( Query.And( Query.All("Name", Query.Descending) , query ) , skip , entriesCount )); case HistoryEntryOrderBy.LaunchTypeAscending: return(col.Find( Query.And( Query.All("LaunchType") , query ) , skip , entriesCount )); case HistoryEntryOrderBy.LaunchTypeDescending: return(col.Find( Query.And( Query.All("LaunchType", Query.Descending) , query ) , skip , entriesCount )); case HistoryEntryOrderBy.DescriptionAscending: return(col.Find( Query.And( Query.All("Description") , query ) , skip , entriesCount )); case HistoryEntryOrderBy.DescriptionDescending: return(col.Find( Query.And( Query.All("Description", Query.Descending) , query ) , skip , entriesCount )); case HistoryEntryOrderBy.StatusAscending: return(col.Find( Query.And( Query.All("Status") , query ) , skip , entriesCount )); case HistoryEntryOrderBy.StatusDescending: return(col.Find( Query.And( Query.All("Status", Query.Descending) , query ) , skip , entriesCount )); } return(new Entry[] { }); } }