/// <summary> /// Gets the count of items that would be returned by the query /// </summary> /// <param name="query"> /// The query. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> internal override int Count(IQuery <IAuditLog> query) { using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork())) { return(repository.Count(query)); } }
/// <summary> /// Saves a collection of <see cref="IAuditLog"/> /// </summary> /// <param name="auditLogs"> /// The collection of <see cref="IAuditLog"/>s to be saved /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Save(IEnumerable <IAuditLog> auditLogs, bool raiseEvents = true) { var auditLogsArray = auditLogs as IAuditLog[] ?? auditLogs.ToArray(); if (raiseEvents) { Saving.RaiseEvent(new SaveEventArgs <IAuditLog>(auditLogsArray), this); } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateAuditLogRepository(uow)) { foreach (var auditLog in auditLogsArray) { repository.AddOrUpdate(auditLog); } uow.Commit(); } } Saved.RaiseEvent(new SaveEventArgs <IAuditLog>(auditLogsArray), this); }
/// <summary> /// Creates an audit record and saves it to the database /// </summary> /// <param name="entityKey"> /// The entity key. /// </param> /// <param name="entityTfKey"> /// The entity type field key. /// </param> /// <param name="message"> /// The message. /// </param> /// <param name="extendedData"> /// The extended data. /// </param> /// <param name="isError"> /// Designates whether or not this is an error log record /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> /// <returns> /// The <see cref="IAuditLog"/>. /// </returns> public IAuditLog CreateAuditLogWithKey(Guid?entityKey, Guid?entityTfKey, string message, ExtendedDataCollection extendedData, bool isError = false, bool raiseEvents = true) { var auditLog = new AuditLog() { EntityKey = entityKey, EntityTfKey = entityTfKey, Message = message, ExtendedData = extendedData, IsError = isError }; if (raiseEvents) { if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IAuditLog>(auditLog), this)) { auditLog.WasCancelled = true; return(auditLog); } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateAuditLogRepository(uow)) { repository.AddOrUpdate(auditLog); uow.Commit(); } } Created.RaiseEvent(new Events.NewEventArgs <IAuditLog>(auditLog), this); return(auditLog); }
/// <summary> /// Gets an <see cref="IAuditLog"/> by it's key /// </summary> /// <param name="key"> /// The key. /// </param> /// <returns> /// The <see cref="IAuditLog"/>. /// </returns> public override IAuditLog GetByKey(Guid key) { using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork())) { return(repository.Get(key)); } }
/// <summary> /// Gets a <see cref="Page{IAuditLog}"/> /// </summary> /// <param name="page"> /// The page. /// </param> /// <param name="itemsPerPage"> /// The items per page. /// </param> /// <param name="sortBy"> /// The sort by. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <returns> /// The <see cref="Page{TEntity}"/>. /// </returns> public override Page <IAuditLog> GetPage(long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending) { var query = Persistence.Querying.Query <IAuditLog> .Builder.Where(x => x.Key != Guid.Empty); using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork())) { return(repository.GetPage(page, itemsPerPage, query, ValidateSortByField(sortBy), sortDirection)); } }
/// <summary> /// Gets a collection of <see cref="IAuditLog"/> for an entity type /// </summary> /// <param name="entityTfKey"> /// The entity type field key. /// </param> /// <param name="page"> /// The page. /// </param> /// <param name="itemsPerPage"> /// The items per page. /// </param> /// <param name="sortBy"> /// The sort by. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <returns> /// The <see cref="Page{IAuditLog}"/>. /// </returns> public Page <IAuditLog> GetAuditLogsByEntityTfKey(Guid entityTfKey, long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending) { using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork())) { var query = Persistence.Querying.Query <IAuditLog> .Builder.Where(x => x.EntityTfKey == entityTfKey); return(repository.GetPage(page, itemsPerPage, query, ValidateSortByField(sortBy), sortDirection)); } }
/// <summary> /// Gets a collection of <see cref="IAuditLog"/> for a particular entity /// </summary> /// <param name="entityKey"> /// The entity key. /// </param> /// <returns> /// The <see cref="IEnumerable{IAuditLog}"/>. /// </returns> public IEnumerable <IAuditLog> GetAuditLogsByEntityKey(Guid entityKey) { using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork())) { var query = Persistence.Querying.Query <IAuditLog> .Builder.Where(x => x.EntityKey == entityKey); return(repository.GetByQuery(query)); } }
/// <summary> /// The get paged keys. /// </summary> /// <param name="page"> /// The page. /// </param> /// <param name="itemsPerPage"> /// The items per page. /// </param> /// <param name="sortBy"> /// The sort by. /// </param> /// <param name="sortDirection"> /// The sort direction. /// </param> /// <returns> /// The <see cref="Page{Guid}"/>. /// </returns> internal override Page <Guid> GetPagedKeys(long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending) { var query = Persistence.Querying.Query <IAuditLog> .Builder.Where(x => x.Key != Guid.Empty); return(GetPagedKeys( RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork()), query, page, itemsPerPage, ValidateSortByField(sortBy), sortDirection)); }
/// <summary> /// Deletes a <see cref="IAuditLog"/> /// </summary> /// <param name="auditLog"> /// The <see cref="IAuditLog"/> to be deleted /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> public void Delete(IAuditLog auditLog, bool raiseEvents = true) { if (raiseEvents) { if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IAuditLog>(auditLog), this)) { ((AuditLog)auditLog).WasCancelled = true; return; } } using (new WriteLock(Locker)) { var uow = UowProvider.GetUnitOfWork(); using (var repository = RepositoryFactory.CreateAuditLogRepository(uow)) { repository.Delete(auditLog); uow.Commit(); } } Deleted.RaiseEvent(new DeleteEventArgs <IAuditLog>(auditLog), this); }