public bool Delete(Entity entity, string key, IEnumerable <PropertyDeleteOption> options) { var existingRecord = _source.GetRecord(entity, key); if (existingRecord == null) { _notificator.Error(IlaroAdminResources.EntityNotExist); return(false); } entity.SetKeyValue(key); options = options ?? new List <PropertyDeleteOption>(); var deleteOptions = options.ToDictionary(x => x.PropertyName, x => x.DeleteOption); foreach (var property in entity.GetForeignsForUpdate()) { if (!deleteOptions.ContainsKey(property.ForeignEntity.Name)) { deleteOptions[property.ForeignEntity.Name] = property.DeleteOption; } } var result = _deleter.Delete(entity, deleteOptions, () => _changeDescriber.DeleteChanges(entity, existingRecord)); if (result) { var propertiesWithFilesToDelete = entity .CreateProperties(getForeignCollection: false) .Where(x => x.TypeInfo.IsFile && x.TypeInfo.IsFileStoredInDb == false); _filesHandler.Delete(propertiesWithFilesToDelete); } return(result); }
public bool Delete(Entity entity, string key, IEnumerable <PropertyDeleteOption> options) { var existingRecord = _source.GetRecord(entity, key); if (existingRecord == null) { _notificator.Error(IlaroAdminResources.EntityNotExist); return(false); } var entityRecord = entity.CreateRecord(existingRecord); options = options ?? new List <PropertyDeleteOption>(); var deleteOptions = options.ToDictionary(x => x.HierarchyName); var result = _deleter.Delete( entityRecord, deleteOptions, () => _changeDescriber.DeleteChanges(entityRecord, existingRecord)); if (result) { var propertiesWithFilesToDelete = entityRecord.Values .Where(value => value.Property.TypeInfo.IsFile && value.Property.TypeInfo.IsFileStoredInDb == false); _filesHandler.Delete(propertiesWithFilesToDelete); } return(result); }