public bool Import(Guid solutionId, IList <Domain.OptionSet> optionSets) { if (optionSets.NotEmpty()) { foreach (var item in optionSets) { foreach (var d in item.Items) { d.OptionSetId = item.OptionSetId; } var entity = _optionSetFinder.FindById(item.OptionSetId); if (entity != null) { item.CreatedBy = _appContext.GetFeature <ICurrentUser>().SystemUserId; item.CreatedOn = DateTime.Now; item.SolutionId = solutionId; item.OrganizationId = _appContext.OrganizationId; _optionSetUpdater.Update(item); //_optionSetDetailService.DeleteByParentId(entity.OptionSetId); //_optionSetDetailService.CreateMany(item.Items); foreach (var d in item.Items) { var dd = _optionSetDetailFinder.Find(x => x.OptionSetId == item.OptionSetId && x.OptionSetDetailId == d.OptionSetDetailId); if (dd != null) { dd.Name = d.Name; dd.Value = d.Value; _optionSetDetailUpdater.Update(dd); } else { d.OptionSetId = item.OptionSetId; _optionSetDetailCreater.Create(d); } } } else { item.CreatedBy = _appContext.GetFeature <ICurrentUser>().SystemUserId; item.CreatedOn = DateTime.Now; item.SolutionId = solutionId; item.OrganizationId = _appContext.GetFeature <ICurrentUser>().OrganizationId; _optionSetCreater.Create(item); _optionSetDetailCreater.CreateMany(item.Items); } } } return(true); }
public IActionResult CreateOptionSet(EditOptionSetModel model) { if (ModelState.IsValid) { bool hasDupName = model.OptionSetName.GroupBy(x => x).Where(g => g.Count() > 1).Count() > 0; if (hasDupName) { return(JError(T["validation_name_duplicated"])); } bool hasDupVal = model.OptionSetValue.GroupBy(x => x).Where(g => g.Count() > 1).Count() > 0; if (hasDupVal) { return(JError(T["validation_value_duplicated"])); } Schema.Domain.OptionSet os = new Schema.Domain.OptionSet(); os.OptionSetId = Guid.NewGuid(); os.Name = model.Name; os.IsPublic = true; os.SolutionId = model.SolutionId; os.CreatedBy = CurrentUser.SystemUserId; List <Schema.Domain.OptionSetDetail> details = new List <Schema.Domain.OptionSetDetail>(); int i = 0; foreach (var item in model.OptionSetName) { if (item.IsEmpty()) { continue; } Schema.Domain.OptionSetDetail osd = new Schema.Domain.OptionSetDetail(); osd.OptionSetDetailId = Guid.NewGuid(); osd.OptionSetId = os.OptionSetId; osd.Name = item; osd.Value = model.OptionSetValue[i]; osd.IsSelected = model.IsSelectedOption[i]; osd.DisplayOrder = i; details.Add(osd); i++; } os.Items = details; _optionSetCreater.Create(os); return(CreateSuccess(new { id = os.OptionSetId })); } return(CreateFailure(GetModelErrors())); }
public bool Create(Domain.Attribute entity) { //检查名称是否已存在 if (_attributeRepository.Exists(x => x.EntityId == entity.EntityId && x.Name == entity.Name)) { throw new XmsException(_loc["ATTRIBUTE_NAME_EXISTS"]); } var result = true; if (entity.DefaultValue.IsEmpty() && (entity.TypeIsBit() || entity.TypeIsDecimal() || entity.TypeIsFloat() || entity.TypeIsInt() || entity.TypeIsMoney() || entity.TypeIsSmallInt() || entity.TypeIsSmallMoney() || entity.TypeIsState() || entity.TypeIsStatus())) { entity.DefaultValue = "0"; } var parentEntity = _entityFinder.FindById(entity.EntityId); using (UnitOfWork.Build(_attributeRepository.DbContext)) { result = _attributeRepository.Create(entity); if (result) { //引用类型 if (entity.TypeIsLookUp() || entity.TypeIsOwner() || entity.TypeIsCustomer()) { var referencing = _entityFinder.FindById(entity.EntityId); var referenced = _attributeRepository.Find(x => x.EntityId == entity.ReferencedEntityId.Value && x.AttributeTypeName == AttributeTypeIds.PRIMARYKEY); var relationShip = new Domain.RelationShip { Name = "lk_" + referencing.Name + "_" + entity.Name, RelationshipType = RelationShipType.ManyToOne, ReferencingAttributeId = entity.AttributeId, ReferencingEntityId = entity.EntityId, ReferencedAttributeId = referenced.AttributeId, ReferencedEntityId = referenced.EntityId, CascadeLinkMask = parentEntity.ParentEntityId.HasValue ? 1 : 2, CascadeAssign = parentEntity.ParentEntityId.HasValue ? 1 : 4, CascadeDelete = parentEntity.ParentEntityId.HasValue ? 1 : 4, CascadeShare = parentEntity.ParentEntityId.HasValue ? 1 : 4, CascadeUnShare = parentEntity.ParentEntityId.HasValue ? 1 : 4, IsCustomizable = !parentEntity.ParentEntityId.HasValue }; _relationShipCreater.Create(relationShip); } //选项类型 else if (entity.TypeIsPickList()) { if (entity.OptionSet != null && !entity.OptionSet.IsPublic) { _optionSetCreater.Create(entity.OptionSet); } } //bit类型 else if (entity.TypeIsBit()) { _stringMapCreater.CreateMany(entity.PickLists); } //update db view _metadataService.AlterView(_entityFinder.FindById(entity.EntityId)); //依赖项 _dependencyService.Create(entity); //本地化标签 _localizedLabelService.Append(SolutionDefaults.DefaultSolutionId, entity.LocalizedName.IfEmpty(""), AttributeDefaults.ModuleName, "LocalizedName", entity.AttributeId) .Append(SolutionDefaults.DefaultSolutionId, entity.Description.IfEmpty(""), AttributeDefaults.ModuleName, "Description", entity.AttributeId) .Save(); //add to cache _cacheService.SetEntity(entity); } } return(result); }