/// <summary> /// Search the items with the matching search term /// This search lets you alter the object type being returned /// </summary> /// <remarks>Error codes follow the format DAL-CM-3XX</remarks> /// <typeparam name="I">A type to return from the search</typeparam> /// <param name="searchTerm">Optional search term to match on</param> /// <param name="filter">The filter with match types gt, lt, eq, regex (greater than, less than, equal and regex). E.g filter=name:contains:Visa or filter=allowChildren:eq:true</param> /// <param name="sort">The sort order E.g search=name desc,createdDate asc</param> /// <param name="startAt">Start at index, defualts to 0</param> /// <param name="pageSize">Page size, defaults to 500</param> /// <param name="deleted">Optional flag to set to filter deleted items on = defaulted to false</param> /// <param name="ignoreDeleteFlag">Optional flag to advise if the results should be filtered by the deleted value</param> /// <param name="archived">Optional flag to set to filter archive items on = defaulted to false</param> /// <param name="ignoreArchiveFlag">Optional flag to advise if the results should be filtered by the archived value</param> /// <returns>A SearchResult with the list of items</returns> public async Task <SearchResult <I> > Search <I>(string searchTerm = null, string filter = null, string sort = null, int startAt = 0, int pageSize = 500, bool deleted = false, bool ignoreDeleteFlag = false, bool archived = false, bool ignoreArchiveFlag = false) { //create promotionId filter FilterDefinitionBuilder <I> filterBuilder = Builders <I> .Filter; var filterDef = filterBuilder.Empty; if (!String.IsNullOrEmpty(filter)) { filterDef = SearchManager.AddFilter(filter, filterDef); } return(await SearchManager.Search <I>(Repository.Database, CollectionName, WorkingClientId, searchTerm, sort, startAt, pageSize, filter : filterDef, filterStr : filter, deleted : deleted, ignoreDeleteFlag : ignoreDeleteFlag, archived : archived, ignoreArchiveFlag : ignoreArchiveFlag)); }
/// <summary> /// Retrieves a list of all the audit items /// </summary> /// <remarks>Error codes follow the format DAL-AM-3XX</remarks> /// <typeparam name="T">The type of the object to audit</typeparam> /// <param name="database">The IMongoDatabase to store the audit in</param> /// <param name="id">The id of the item within the audit trail</param> /// <param name="collectionName">The name of the audit collection</param> /// <returns>A JSON string of the matching audit item</returns> public static async Task <SearchResult <T> > RetrieveAuditContainer <T>(IMongoDatabase database, string id, string clientId = null, string collectionName = "Audit", int startAt = 0, int pageSize = 500) { SearchResult <T> result = new SearchResult <T>() { PageSize = pageSize, StartAt = startAt, Results = new List <T>() }; //make the id contain the client id for AuditContainers and null the sent client id //if (!String.IsNullOrEmpty(clientId)) id += ":" + clientId; var item = await SearchManager.Find <AuditContainer <T> >(database, collectionName, id, null); if (item != null) { result.TotalCount = item.AuditItems.Count(); item.AuditItems.Reverse(); result.Results = item.AuditItems.Skip(result.StartAt).Take(pageSize); } return(result); }
/// <summary> /// Returns a matching item from the data store /// </summary> /// <remarks>Error codes follow the format DAL-CM-1XX</remarks> /// <param name="id">The id of the item to find</param> /// <returns>The matching item or null</returns> public async Task <T> Find(string id) { var result = await SearchManager.Find <T>(Repository.Database, CollectionName, id, WorkingClientId); return(result); }