/// <summary> /// Called after saving of the specified enumeration of entities has taken place. /// </summary> /// <param name="entities">The entities.</param> /// <param name="state">The state.</param> public void OnAfterSave(IEnumerable <IEntity> entities, IDictionary <string, object> state) { object duplicates; HashSet <long> entitiesToDeleteSet = new HashSet <long>(); // Get any merged duplicates to delete if (state.TryGetValue(ResourceKeyHelper.MergedDuplicatesStateKey, out duplicates)) { var duplicatesAsHashSet = duplicates as HashSet <long>; if (duplicatesAsHashSet != null && duplicatesAsHashSet.Count != 0) { entitiesToDeleteSet.UnionWith(duplicatesAsHashSet.Select(id => EventTargetStateHelper.GetIdFromTemporaryId(state, id))); } } Dictionary <long, ResourceKeyDataHash> dataHashesToDelete = ResourceKeyHelper.GetResourceKeyDataHashToDeleteState(state); // Get any datahashes to delete if (dataHashesToDelete != null && dataHashesToDelete.Count != 0) { entitiesToDeleteSet.UnionWith(dataHashesToDelete.Keys); } if (entitiesToDeleteSet.Count != 0) { Entity.Delete(entitiesToDeleteSet); } object movedEntitiesObject; if (state.TryGetValue("movedEntities", out movedEntitiesObject)) { Dictionary <long, ISet <long> > movedEntities = movedEntitiesObject as Dictionary <long, ISet <long> >; if (movedEntities != null) { using (DatabaseContext context = DatabaseContext.GetContext( )) { foreach (KeyValuePair <long, ISet <long> > pair in movedEntities) { using (IDbCommand command = context.CreateCommand("spPostEntityMove", CommandType.StoredProcedure)) { command.AddIdListParameter("@entityIds", pair.Value); command.AddParameter("@tenantId", DbType.Int64, RequestContext.TenantId); command.AddParameter("@solutionId", DbType.Int64, pair.Key); command.ExecuteNonQuery( ); } } } } } // Save the resource key data hashes for any resources at the reverse end // of any key relationships. ResourceKeyHelper.SaveResourceKeyDataHashesForReverseRelationships(entities, state); }
/// <summary> /// Called after saving of the specified enumeration of entities has taken place. /// </summary> /// <param name="entities">The entities.</param> /// <param name="state">The state passed between the before save and after save callbacks.</param> public void OnAfterSave(IEnumerable <IEntity> entities, IDictionary <string, object> state) { foreach (long entityId in entities.Select(e => e.Id)) { _auditLogEventTarget.WriteSaveAuditLogEntries(true, entityId, state); } var newTenantTempIds = (List <long>)state[NewTenantKey]; Database.DatabaseContext.GetContext().AddPostDisposeAction(() => { foreach (var tempId in newTenantTempIds) { var tenantId = EventTargetStateHelper.GetIdFromTemporaryId(state, tempId); TenantHelper.NotifyTenantCreate(tenantId); } }); }
/// <summary> /// Processes the new solutions. /// </summary> /// <param name="entities">The entities.</param> /// <param name="state">The state.</param> private static void ProcessNewSolutions(IEnumerable <IEntity> entities, IDictionary <string, object> state) { object newSolutionsObject; if (state.TryGetValue(NewSolutionsKey, out newSolutionsObject)) { var newSolutions = (List <IEntity>)newSolutionsObject; IList <IEntity> enumerable = entities as IList <IEntity> ?? entities.ToList(); foreach (IEntity newSolution in newSolutions) { long temporaryId = EventTargetStateHelper.GetIdFromTemporaryId(state, newSolution.Id); IEntity entity = enumerable.FirstOrDefault(e => e.Id == temporaryId); if (entity != null) { var solution = entity.As <Solution>(); if (solution == null) { continue; } if (solution.IsReadOnly) { solution = solution.AsWritable <Solution>(); } SetInSolutionRelationship(solution); solution.Save(); } } DetermineIfNewTabNeeded(enumerable); state.Remove(NewSolutionsKey); } }