Example #1
0
        private bool CreateCore(Domain.SystemForm entity, Action <Domain.SystemForm> createDependents)
        {
            if (entity.FormConfig.IsEmpty())
            {
                return(false);
            }
            entity.OrganizationId = _appContext.OrganizationId;
            _formService.Init(entity);
            var result = true;

            using (UnitOfWork.Build(_systemFormRepository.DbContext))
            {
                result = _systemFormRepository.Create(entity);
                //依赖项
                createDependents?.Invoke(entity);
                //本地化标签
                _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), entity.FormType == (int)FormType.Dashboard ? DashBoardDefaults.ModuleName : FormDefaults.ModuleName, "LocalizedName", entity.SystemFormId)
                .Append(entity.SolutionId, entity.Description.IfEmpty(""), entity.FormType == (int)FormType.Dashboard ? DashBoardDefaults.ModuleName : FormDefaults.ModuleName, "Description", entity.SystemFormId)
                .Save();
                _formService.UpdateLocalizedLabel(null);
                if (entity.FormType == (int)FormType.Dashboard)
                {
                    //solution component
                    result = _solutionComponentService.Create(entity.SolutionId, entity.SystemFormId, DashBoardDefaults.ModuleName);
                }
                //add to cache
                _cacheService.SetEntity(_systemFormRepository.FindById(entity.SystemFormId));
            }
            return(result);
        }
Example #2
0
        public bool Create(Domain.OptionSet entity)
        {
            Guard.NotNullOrEmpty(entity.Items, "items");
            entity.SolutionId     = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案
            entity.OrganizationId = _appContext.OrganizationId;
            bool result = true;

            using (UnitOfWork.Build(_optionSetRepository.DbContext))
            {
                result = _optionSetRepository.Create(entity);
                //solution component
                if (entity.IsPublic)
                {
                    result = _solutionComponentService.Create(entity.SolutionId, entity.OptionSetId, OptionSetDefaults.ModuleName);
                }
                //存在明细项,不缓存,
                //_cacheService.SetEntity(entity);
                //details
                _optionSetDetailCreater.CreateMany(entity.Items);

                //本地化标签
                _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), OptionSetDefaults.ModuleName, "LocalizedName", entity.OptionSetId)
                .Append(entity.SolutionId, entity.Description.IfEmpty(""), OptionSetDefaults.ModuleName, "Description", entity.OptionSetId)
                .Save();
            }
            return(result);
        }
Example #3
0
        public bool Create(Domain.Entity entity, params string[] defaultAttributeNames)
        {
            if (_entityRepository.Exists(x => x.Name == entity.Name))
            {
                throw new XmsException(_loc["name_already_exists"]);
            }
            var solutionid = entity.SolutionId;                     //当前解决方案

            entity.SolutionId = SolutionDefaults.DefaultSolutionId; //组件属于默认解决方案
            var result = true;

            if (defaultAttributeNames.IsEmpty())
            {
                //默认添加主键字段
                defaultAttributeNames = new string[] { entity.Name + "Id" };
            }
            else if (!defaultAttributeNames.Contains(entity.Name + "Id", StringComparer.InvariantCultureIgnoreCase))
            {
                var namesList = defaultAttributeNames.ToList();
                namesList.Add(entity.Name + "Id");
                defaultAttributeNames = namesList.ToArray();
            }
            var parentEntity      = entity.ParentEntityId.HasValue ? _entityRepository.FindById(entity.ParentEntityId.Value) : null;
            var defaultAttributes = _defaultAttributeProvider.GetSysAttributes(entity).Where(x => defaultAttributeNames.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase)).Distinct().ToList();

            using (UnitOfWork.Build(_entityRepository.DbContext))
            {
                result = _entityRepository.Create(entity, defaultAttributes, _defaultAttributeProvider.GetSysAttributeRelationShips(entity, defaultAttributes));

                //创建默认字段
                _attributeCreater.CreateDefaultAttributes(entity, defaultAttributeNames);
                //如果是子实体,则创建引用字段
                if (parentEntity != null)
                {
                    _attributeCreater.Create(new Domain.Attribute {
                        Name = parentEntity.Name + "Id"
                        , AttributeTypeName  = AttributeTypeIds.LOOKUP
                        , EntityId           = entity.EntityId
                        , EntityName         = entity.Name
                        , IsRequired         = true
                        , LocalizedName      = parentEntity.LocalizedName
                        , ReferencedEntityId = parentEntity.EntityId
                    });
                }
                //事件发布
                _eventPublisher.Publish(new ObjectCreatedEvent <Domain.Entity>(entity));
                //solution component
                _solutionComponentService.Create(solutionid, entity.EntityId, EntityDefaults.ModuleName);
                //本地化标签
                _localizedLabelService.Append(entity.SolutionId, entity.LocalizedName.IfEmpty(""), EntityDefaults.ModuleName, "LocalizedName", entity.EntityId)
                .Append(entity.SolutionId, entity.Description.IfEmpty(""), EntityDefaults.ModuleName, "Description", entity.EntityId)
                .Save();

                //add to cache
                _cacheService.SetEntity(entity);
            }
            return(result);
        }
Example #4
0
        public bool Create(WorkFlow entity)
        {
            entity.OrganizationId = _appContext.OrganizationId;
            var result = true;

            using (UnitOfWork.Build(_workFlowRepository.DbContext))
            {
                result = _workFlowRepository.Create(entity);
                //solution component
                _solutionComponentService.Create(entity.SolutionId, entity.WorkFlowId, WorkFlowDefaults.ModuleName);
                //依赖于实体
                _dependencyService.Create(entity);
                //本地化标签
                _localizedLabelService.Create(entity.SolutionId, entity.Name.IfEmpty(""), WorkFlowDefaults.ModuleName, "LocalizedName", entity.WorkFlowId, _appContext.BaseLanguage);
                _localizedLabelService.Create(entity.SolutionId, entity.Description.IfEmpty(""), WorkFlowDefaults.ModuleName, "Description", entity.WorkFlowId, _appContext.BaseLanguage);
            }
            return(result);
        }
Example #5
0
        public bool Create(Domain.Report entity)
        {
            entity.OrganizationId = _appContext.OrganizationId;
            var result = true;

            using (UnitOfWork.Build(_reportRepository.DbContext))
            {
                result = _reportRepository.Create(entity);
                //solution component
                _solutionComponentService.Create(entity.SolutionId, entity.ReportId, ReportDefaults.ModuleName);
                //依赖于实体
                _dependencyService.Create(ReportDefaults.ModuleName, entity.ReportId, EntityDefaults.ModuleName, entity.EntityId, entity.RelatedEntityId);
                //本地化标签
                _localizedLabelService.Create(entity.SolutionId, entity.Name.IfEmpty(""), ReportDefaults.ModuleName, "LocalizedName", entity.ReportId, this._appContext.BaseLanguage);
                _localizedLabelService.Create(entity.SolutionId, entity.Description.IfEmpty(""), ReportDefaults.ModuleName, "Description", entity.ReportId, this._appContext.BaseLanguage);
            }
            return(result);
        }
Example #6
0
        public bool Create(EntityPlugin entity)
        {
            entity.SolutionId     = SolutionDefaults.DefaultSolutionId;//组件属于默认解决方案
            entity.CreatedBy      = _appContext.GetFeature <ICurrentUser>().SystemUserId;
            entity.OrganizationId = _appContext.OrganizationId;
            var result = true;

            using (UnitOfWork.Build(_entityPluginRepository.DbContext))
            {
                result = _entityPluginRepository.Create(entity);
                //solution component
                _solutionComponentService.Create(entity.SolutionId, entity.EntityPluginId, PluginDefaults.ModuleName);
                //依赖于实体
                _dependencyService.Create(PluginDefaults.ModuleName, entity.EntityPluginId, EntityDefaults.ModuleName, entity.EntityId);
                //add to cache
                _cacheService.SetEntity(entity);
            }
            return(result);
        }
Example #7
0
        public bool Create(Domain.SerialNumberRule entity)
        {
            //检查是否已存在相同字段的编码规则
            if (_serialNumberRuleRepository.Exists(x => x.EntityId == entity.EntityId && x.AttributeId == entity.AttributeId))
            {
                throw new XmsException(_loc["serial_number_duplicated"]);
            }
            entity.OrganizationId = this._appContext.OrganizationId;
            var result = true;

            using (UnitOfWork.Build(_serialNumberRuleRepository.DbContext))
            {
                result = _serialNumberRuleRepository.Create(entity);
                //依赖于字段
                _dependencyService.Create(entity);
                //solution component
                result = _solutionComponentService.Create(entity.SolutionId, entity.SerialNumberRuleId, SerialNumberRuleDefaults.ModuleName);
                //本地化标签
                _localizedLabelService.Create(entity.SolutionId, entity.Name.IfEmpty(""), SerialNumberRuleDefaults.ModuleName, "LocalizedName", entity.SerialNumberRuleId, this._appContext.BaseLanguage);
                _localizedLabelService.Create(entity.SolutionId, entity.Description.IfEmpty(""), SerialNumberRuleDefaults.ModuleName, "Description", entity.SerialNumberRuleId, this._appContext.BaseLanguage);
                //plugin
                _entityPluginCreater.Create(new EntityPlugin()
                {
                    AssemblyName = SerialNumberRuleDefaults.AssemblyName
                    ,
                    ClassName = SerialNumberRuleDefaults.PluginClassName
                    ,
                    EntityId = entity.EntityId
                    ,
                    EventName = Enum.GetName(typeof(OperationTypeEnum), OperationTypeEnum.Create)
                    ,
                    IsVisibled = false
                    ,
                    TypeCode = 0
                    ,
                    StateCode = RecordState.Enabled
                });
                //add to cache
                _cacheService.SetEntity(_serialNumberRuleRepository.FindById(entity.SerialNumberRuleId));
            }
            return(result);
        }
Example #8
0
        public bool Create(Domain.WebResource entity)
        {
            var solutionid = entity.SolutionId;                     //当前解决方案

            entity.SolutionId = SolutionDefaults.DefaultSolutionId; //组件属于默认解决方案
            var result = true;

            using (UnitOfWork.Build(_webResourceRepository.DbContext))
            {
                result = _webResourceRepository.Create(entity);
                //solution component
                _solutionComponentService.Create(solutionid, entity.WebResourceId, WebResourceDefaults.ModuleName);
                //本地化标签
                _localizedLabelService.Append(entity.SolutionId, entity.Name.IfEmpty(""), WebResourceDefaults.ModuleName, "LocalizedName", entity.WebResourceId)
                .Append(entity.SolutionId, entity.Description.IfEmpty(""), WebResourceDefaults.ModuleName, "Description", entity.WebResourceId)
                .Save();
                _cacheService.SetEntity(entity);
            }
            return(result);
        }