Beispiel #1
0
        /// <summary>
        /// 实体级联删除
        /// </summary>
        /// <param name="parent">被删除的实体</param>
        public void CascadeDelete(params Domain.Entity[] parent)
        {
            if (parent.IsEmpty())
            {
                return;
            }
            var entityIds  = parent.Select(x => x.EntityId).ToArray();
            var attributes = _attributeRepository.Query(x => x.EntityId.In(entityIds));

            if (attributes.NotEmpty())
            {
                var ids = attributes.Select(x => x.AttributeId).ToArray();
                using (UnitOfWork.Build(_attributeRepository.DbContext))
                {
                    //cascade delete
                    _cascadeDeletes?.ToList().ForEach((x) => { x.CascadeDelete(attributes.ToArray()); });
                    _attributeRepository.DeleteMany(x => x.EntityId.In(entityIds));
                    //删除依赖项
                    _dependencyService.Delete(ids);
                    //localization
                    _localizedLabelService.DeleteByObject(ids);
                    foreach (var deleted in attributes)
                    {
                        //remove from cache
                        _cacheService.RemoveEntity(deleted);
                    }
                }
            }
        }
Beispiel #2
0
        private bool DeleteCore(params FilterRule[] deleteds)
        {
            Guard.NotEmpty(deleteds, nameof(deleteds));
            var result = false;
            var ids    = deleteds.Select(x => x.FilterRuleId);

            using (UnitOfWork.Build(_filterRuleRepository.DbContext))
            {
                result = _filterRuleRepository.DeleteMany(ids);
                //删除依赖项
                _dependencyService.Delete(ids.ToArray());
                var entityIds = deleteds.Select(x => x.EntityId).Distinct().ToArray();
                //plugin
                foreach (var eid in entityIds)
                {
                    _entityPluginDeleter.DeleteByEntityId(eid);
                }
                foreach (var deleted in deleteds)
                {
                    //remove from cache
                    _cacheService.RemoveEntity(deleted);
                }
            }
            return(result);
        }
Beispiel #3
0
        public bool DeleteById(params Guid[] id)
        {
            Guard.NotEmpty(id, nameof(id));
            var result = true;

            foreach (var item in id)
            {
                var deleted = _webResourceRepository.FindById(item);
                if (deleted == null)
                {
                    return(false);
                }
                //检查依赖项
                _dependencyChecker.CheckAndThrow <Domain.WebResource>(WebResourceDefaults.ModuleName, deleted.WebResourceId);
                bool flag = _webResourceRepository.DeleteById(item);
                if (flag)
                {
                    //删除依赖项
                    _dependencyService.DeleteByDependentId(WebResourceDefaults.ModuleName, id);
                    //solution component
                    _solutionComponentService.DeleteObject(deleted.SolutionId, deleted.WebResourceId, WebResourceDefaults.ModuleName);
                    //localization
                    _localizedLabelService.DeleteByObject(item);
                    _cacheService.RemoveEntity(deleted);
                }
            }
            return(result);
        }
        private bool DeleteCore(params Domain.SerialNumberRule[] deleteds)
        {
            Guard.NotEmpty(deleteds, nameof(deleteds));
            var result = true;
            var ids    = deleteds.Select(x => x.SerialNumberRuleId).ToArray();

            using (UnitOfWork.Build(_serialNumberRuleRepository.DbContext))
            {
                result = _serialNumberRuleRepository.DeleteMany(ids);
                //删除依赖项
                _dependencyService.Delete(ids);
                //localization
                _localizedLabelService.DeleteByObject(ids);
                //solution component
                _solutionComponentService.DeleteObject(deleteds.First().SolutionId, SerialNumberRuleDefaults.ModuleName, ids);
                var entityIds = deleteds.Select(x => x.EntityId).Distinct().ToArray();
                //plugin
                foreach (var eid in entityIds)
                {
                    _entityPluginDeleter.DeleteByEntityId(eid);
                }
                foreach (var deleted in deleteds)
                {
                    //remove from cache
                    _cacheService.RemoveEntity(deleted);
                }
            }
            return(result);
        }
Beispiel #5
0
        private bool DeleteCore(params EntityMap[] deleteds)
        {
            Guard.NotEmpty(deleteds, nameof(deleteds));
            var ids    = deleteds.Select(x => x.EntityMapId);
            var result = true;

            using (UnitOfWork.Build(_entityMapRepository.DbContext))
            {
                result = _entityMapRepository.DeleteMany(ids);
                //删除依赖项
                _dependencyService.Delete(ids.ToArray());
                foreach (var deleted in deleteds)
                {
                    //cascade delete
                    _cascadeDeletes?.ToList().ForEach((x) => { x.CascadeDelete(deleted); });
                    //remove from cache
                    _cacheService.RemoveEntity(deleted);
                }
                //删除子项
                var childs = _entityMapRepository.Query(x => x.ParentEntityMapId.In(ids));
                if (childs.NotEmpty())
                {
                    DeleteCore(childs.ToArray());
                }
            }
            return(result);
        }
Beispiel #6
0
        public bool DeleteById(bool deleteTable = true, params Guid[] id)
        {
            Guard.NotEmpty(id, nameof(id));
            var result = false;

            using (UnitOfWork.Build(_entityRepository.DbContext))
            {
                foreach (var item in id)
                {
                    var deleted = _entityRepository.FindById(item);
                    if (deleted == null || !deleted.IsCustomizable)
                    {
                        continue;
                    }
                    //检查依赖项
                    _dependencyChecker.CheckAndThrow <Domain.Entity>(EntityDefaults.ModuleName, item);
                    //cascade delete
                    _cascadeDeletes?.ToList().ForEach((x) => { x.CascadeDelete(deleted); });
                    result = _entityRepository.DeleteById(item, deleteTable);
                    //删除依赖项
                    _dependencyService.DeleteByDependentId(EntityDefaults.ModuleName, item);
                    //solution component
                    _solutionComponentService.DeleteObject(deleted.SolutionId, deleted.EntityId, EntityDefaults.ModuleName);
                    //entity localization
                    _localizedLabelService.DeleteByObject(deleted.EntityId);
                    //remove from cache
                    _cacheService.RemoveEntity(deleted);
                }
            }
            return(result);
        }
Beispiel #7
0
        private bool DeleteCore(IEnumerable <Domain.OptionSet> deleteds, Func <Domain.OptionSet, bool> validation)
        {
            Guard.NotEmpty(deleteds, nameof(deleteds));
            var result = true;

            foreach (var deleted in deleteds)
            {
                result = validation?.Invoke(deleted) ?? true;
            }
            if (result)
            {
                var ids = deleteds.Select(x => x.OptionSetId).ToArray();
                using (UnitOfWork.Build(_optionSetRepository.DbContext))
                {
                    //cascade delete
                    _cascadeDeletes?.ToList().ForEach((x) => { x.CascadeDelete(deleteds.ToArray()); });
                    result = _optionSetRepository.DeleteMany(ids);
                    //删除依赖项
                    _dependencyService.DeleteByDependentId(OptionSetDefaults.ModuleName, ids);
                    //localization
                    _localizedLabelService.DeleteByObject(ids);
                    foreach (var deleted in deleteds)
                    {
                        //solution component
                        _solutionComponentService.DeleteObject(deleted.SolutionId, deleted.OptionSetId, OptionSetDefaults.ModuleName);
                        //remove from cache
                        _cacheService.RemoveEntity(deleted);
                    }
                }
            }
            return(result);
        }
Beispiel #8
0
        public bool Update(Domain.Attribute entity)
        {
            var result = true;

            using (UnitOfWork.Build(_attributeRepository.DbContext))
            {
                result = _attributeRepository.Update(entity);
                if (entity.OptionSetId.HasValue && entity.OptionSet != null && !entity.OptionSet.IsPublic)
                {
                    var details = _optionSetDetailFinder.Query(n => n.Select(f => f.OptionSetDetailId).Where(f => f.OptionSetId == entity.OptionSetId.Value));
                    foreach (var item in entity.OptionSet.Items)
                    {
                        if (item.OptionSetDetailId.Equals(Guid.Empty))
                        {
                            item.OptionSetDetailId = Guid.NewGuid();
                            result = _optionSetDetailCreater.Create(item);
                        }
                        else
                        {
                            result = _optionSetDetailUpdater.Update(item);
                        }
                    }
                    //delete lost
                    var ids    = entity.OptionSet.Items.Select(n => n.OptionSetDetailId);
                    var lostid = details.Select(n => n.OptionSetDetailId).Except(ids).ToList();
                    if (lostid.NotEmpty())
                    {
                        result = _optionSetDetailDeleter.DeleteById(lostid.ToArray());
                    }
                }
                if (entity.PickLists.NotEmpty())//bit
                {
                    foreach (var item in entity.PickLists)
                    {
                        if (item.StringMapId.Equals(Guid.Empty))
                        {
                            result = _stringMapCreater.Create(item);
                        }
                        else
                        {
                            result = _stringMapUpdater.Update(item);
                        }
                    }
                }
                //localization
                _localizedLabelService.Update(entity.LocalizedName.IfEmpty(""), "LocalizedName", entity.AttributeId, this._appContext.BaseLanguage);
                _localizedLabelService.Update(entity.Description.IfEmpty(""), "Description", entity.AttributeId, this._appContext.BaseLanguage);
                //set to cache
                var optionSetEntity = _optionSetFinder.FindById(entity.OptionSet.OptionSetId);
                _cacheService.SetEntity(entity);
                _cacheServiceOption.RemoveEntity(optionSetEntity);
            }
            return(result);
        }
Beispiel #9
0
        public bool Update(EntityMap entity)
        {
            bool result = true;

            using (UnitOfWork.Build(_entityMapRepository.DbContext))
            {
                result = _entityMapRepository.Update(entity);
                ////内容不全,不能缓存
                _cacheService.RemoveEntity(entity);
            }
            return(result);
        }
Beispiel #10
0
        public bool DeleteById(Guid id)
        {
            var entity = _privilegeRepository.FindById(id);
            var flag   = _privilegeRepository.DeleteById(id);

            if (flag)
            {
                //localization
                _localizedLabelService.DeleteByObject(id);
                //remove from cache
                _cacheService.RemoveEntity(entity);
            }
            return(flag);
        }
Beispiel #11
0
        public bool Update(Domain.OptionSet entity)
        {
            bool result = false;

            using (UnitOfWork.Build(_optionSetRepository.DbContext))
            {
                result = _optionSetRepository.Update(entity);
                //localization
                _localizedLabelService.Update(entity.Name.IfEmpty(""), "LocalizedName", entity.OptionSetId, _appContext.BaseLanguage);
                _localizedLabelService.Update(entity.Description.IfEmpty(""), "Description", entity.OptionSetId, _appContext.BaseLanguage);

                //存在明细项,丢弃缓存,
                _cacheService.RemoveEntity(entity);
            }
            return(result);
        }
Beispiel #12
0
        private bool DeleteCore(params Domain.RelationShip[] deleted)
        {
            Guard.NotEmpty(deleted, nameof(deleted));
            var result = false;

            if (deleted != null)
            {
                using (UnitOfWork.Build(_relationShipRepository.DbContext))
                {
                    result = _relationShipRepository.DeleteMany(deleted.Select(x => x.RelationshipId));
                    foreach (var item in deleted)
                    {
                        _cacheService.RemoveEntity(item);
                    }
                }
            }
            return(result);
        }
Beispiel #13
0
        private bool DeleteCore(params EntityPlugin[] deleteds)
        {
            Guard.NotEmpty(deleteds, nameof(deleteds));
            var result     = true;
            var solutionId = deleteds.First().SolutionId;
            var ids        = deleteds.Select(x => x.EntityPluginId).ToArray();

            using (UnitOfWork.Build(_entityPluginRepository.DbContext))
            {
                result = _entityPluginRepository.DeleteMany(ids);
                //solution component
                _solutionComponentService.DeleteObject(solutionId, PluginDefaults.ModuleName, ids);
                //删除依赖项
                _dependencyService.DeleteByDependentId(PluginDefaults.ModuleName, ids);
                //remove from cache
                foreach (var deleted in deleteds)
                {
                    _cacheService.RemoveEntity(deleted);
                }
            }
            return(result);
        }
Beispiel #14
0
        private bool DeleteCore(IEnumerable <Domain.SystemForm> deleteds, Func <Domain.SystemForm, bool> validation)
        {
            Guard.NotEmpty(deleteds, nameof(deleteds));
            var result = true;

            foreach (var deleted in deleteds)
            {
                result = validation?.Invoke(deleted) ?? true;
            }
            if (result)
            {
                var ids = deleteds.Select(x => x.SystemFormId).ToArray();
                using (UnitOfWork.Build(_systemFormRepository.DbContext))
                {
                    result = _systemFormRepository.DeleteMany(ids);
                    //删除依赖项
                    _dependencyService.Delete(ids);
                    foreach (var deleted in deleteds)
                    {
                        if (deleted.FormType == (int)FormType.Dashboard)
                        {
                            //solution component
                            result = _solutionComponentService.DeleteObject(deleted.SolutionId, deleted.SystemFormId, DashBoardDefaults.ModuleName);
                        }
                        //localization
                        _localizedLabelService.DeleteByObject(ids);
                        _formService.Init(deleted).DeleteOriginalLabels(deleted);
                        _eventPublisher.Publish(new ObjectDeletedEvent <Domain.SystemForm>(deleted.FormType == (int)FormType.Dashboard ? DashBoardDefaults.ModuleName : FormDefaults.ModuleName, deleted));
                        //remove from cache
                        _cacheService.RemoveEntity(deleted);
                    }
                    //cascade delete
                    _cascadeDeletes?.ToList().ForEach((x) => { x.CascadeDelete(deleteds.ToArray()); });
                }
            }
            return(result);
        }
Beispiel #15
0
        private bool DeleteCore(IEnumerable <Domain.QueryView> deleteds, Func <Domain.QueryView, bool> validation)
        {
            Guard.NotEmpty(deleteds, nameof(deleteds));
            var result = true;

            if (validation != null)
            {
                foreach (var deleted in deleteds)
                {
                    result = validation?.Invoke(deleted) ?? true;
                }
            }
            if (result)
            {
                var ids = deleteds.Select(x => x.QueryViewId).ToArray();
                using (UnitOfWork.Build(_queryViewRepository.DbContext))
                {
                    //cascade delete
                    _cascadeDeletes?.ToList().ForEach((x) => { x.CascadeDelete(deleteds.ToArray()); });
                    _queryViewRepository.DeleteMany(ids);
                    //删除依赖项
                    _dependencyService.Delete(ids);
                    //localization
                    _localizedLabelService.DeleteByObject(ids);
                    //remove from cache
                    foreach (var item in deleteds)
                    {
                        _cacheService.RemoveEntity(item);
                    }
                    foreach (var item in deleteds)
                    {
                        _eventPublisher.Publish(new ObjectDeletedEvent <Domain.QueryView>(QueryViewDefaults.ModuleName, item));
                    }
                }
            }
            return(result);
        }