/* * Глобальные коллекции */ #region public void Save(BaseSmartCoreObject saveObject) public void Save(BaseEntityObject saveObject) { if (saveObject == null) { return; } saveObject.CorrectorId = _casEnvironment.IdentityUser.ItemId; var type = AuditOperation.Created; if (saveObject.ItemId > 0) { type = AuditOperation.Changed; } CasEnvironment.Keeper.Save(saveObject); _auditRepository.WriteAsync(saveObject, type, _casEnvironment.IdentityUser); if (saveObject is AbstractDictionary) { IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType()); if (col == null) { return; } AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId); if (dict == null || saveObject.ItemId != dict.ItemId) { col.Add(saveObject); } else { dict.SetProperties((AbstractDictionary)saveObject); } } if (saveObject is Store) { Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.Stores.Add((Store)saveObject); } } if (saveObject is BaseComponent) { BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.BaseComponents.Add((BaseComponent)saveObject); } } }
/// <summary> /// Новый метод для сохранения объектов /// </summary> /// <param name="saveObject">Сохраняемый объект</param> /// <param name="saveChild">Сохранять дочерние объекты</param> /// <param name="saveForced">Сохранять свойтсва, помеченные как "принудительные"</param> public void SaveAll(BaseEntityObject saveObject, bool saveChild = false, bool saveForced = false) { if (saveObject == null) { return; } CasEnvironment.Keeper.SaveAll(saveObject, saveChild, saveForced); if (saveObject is AbstractDictionary) { IDictionaryCollection col = CasEnvironment.GetDictionary(saveObject.GetType()); if (col == null) { return; } AbstractDictionary dict = (AbstractDictionary)col.GetItemById(saveObject.ItemId); if (dict == null || saveObject.ItemId != dict.ItemId) { col.Add(saveObject); } else { dict.SetProperties((AbstractDictionary)saveObject); } } if (saveObject is Store) { Store o = CasEnvironment.Stores.GetItemById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.Stores.Add((Store)saveObject); } } if (saveObject is BaseComponent) { BaseComponent o = _componentCore.GetBaseComponentById(saveObject.ItemId); if (o == null || saveObject.ItemId != o.ItemId) { CasEnvironment.BaseComponents.Add((BaseComponent)saveObject); } } }