Esempio n. 1
0
        /// <summary>
        /// Audits the sent item
        /// </summary>
        /// <remarks>Error codes follow the format DAL-DMB-5XX</remarks>
        /// <typeparam name="T">The type of the object to audit</typeparam>
        /// <param name="item">The item to audit</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>
        public async Task AuditItem <T>(T item, string auditCollectionName, string auditSettingsKey = null, string auditUser = null)
        {
            //set the user name if sent
            if (!String.IsNullOrEmpty(AuditUser) && String.IsNullOrEmpty(auditUser))
            {
                auditUser = AuditUser;
            }
            //create the new item or update the item audit fields
            bool newItem = (item is IAuditFieldsWithId) ? AuditManager.SetAuditFields(item as IAuditFieldsWithId, auditUser) : true;
            //set audit by default value item has not yet been created
            bool auditItem = AuditByDefault;

            if (auditItem)
            {
                //check the audit settings allow
                auditItem = (!String.IsNullOrEmpty(auditSettingsKey) && AuditSettings != null && AuditSettings.ContainsKey(auditSettingsKey))? bool.Parse(AuditSettings[auditSettingsKey]) : auditItem;
            }
            //audit item if set
            if (auditItem)
            {
                await AuditManager.AuditItem <T>(Repository.Database, item, newItem, auditCollectionName, auditUser);
            }
        }
Esempio n. 2
0
        /// <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="items">An IEnumerable list of items to audit</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 AuditItems(string[] ids, 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 { }
                FilterDefinitionBuilder <BaseIdWithQuickSearchModel> filterBuilder = Builders <BaseIdWithQuickSearchModel> .Filter;
                var filter = filterBuilder.Empty;
                filter = filter & filterBuilder.Where(w => ids.Contains(w.Id));
                var collection = Repository.Database.GetCollection <BaseIdWithQuickSearchModel>(collectionName);
                var items      = await collection.Find(filter).ToListAsync <BaseIdWithQuickSearchModel>();

                foreach (var item in items)
                {
                    await AuditManager.AuditItem <BaseIdWithQuickSearchModel>(Repository.Database, item, false, auditCollectionName, auditUser, auditCapSize);
                }
            }
        }
Esempio n. 3
0
        /// <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="items">An IEnumerable list of items to audit</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 AuditItems <T>(IEnumerable <T> items, 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 { }
                foreach (var item in items)
                {
                    await AuditManager.AuditItem <T>(Repository.Database, item, false, auditCollectionName, auditUser, auditCapSize);
                }
            }
        }
Esempio n. 4
0
        /// <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);
            }
        }