/// <summary> /// Audits the item based on the sent id and collection /// </summary> /// <remarks>Error codes follow the format DAL-DMB-4XX</remarks> /// <typeparam name="T">The type of the object to audit</typeparam> /// <param name="id">The id of the item to audit</param> /// <param name="collectionName">The collection name of the audit item</param> /// <param name="auditCollectionName">The collection name for the audit</param> /// <param name="auditSettingsKey">Optional audit setting key to reference the AuditSettings dictionary</param> /// <param name="auditUser">Optional string for the audit user</param> /// <param name="auditCapSize">Optional int to set the audit cap size</param> public async Task AuditItem <T>(string id, string collectionName, string auditCollectionName, string auditSettingsKey = null, string auditUser = null, int auditCapSize = 100) { //set audit by default value item has not yet been created bool auditItem = AuditByDefault; if (auditItem) { //check the audit settings allow try { auditItem = (!String.IsNullOrEmpty(auditSettingsKey) && AuditSettings != null && AuditSettings.ContainsKey(auditSettingsKey)) ? bool.Parse(AuditSettings[auditSettingsKey]) : auditItem; } catch { } } //audit item if set if (auditItem) { try { auditCapSize = (!String.IsNullOrEmpty(auditCollectionName + ".Size") && AuditSettings != null && AuditSettings.ContainsKey(auditCollectionName + ".Size")) ? int.Parse(AuditSettings[auditCollectionName + ".Size"]) : auditCapSize; } catch { } T item = await SearchManager.Find <T>(Repository.Database, collectionName, id, WorkingClientId); await AuditManager.AuditItem <T>(Repository.Database, item, false, auditCollectionName, auditUser, auditCapSize); } }
/// <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); }