public bool DeleteById(params Guid[] id) { Guard.NotEmpty(id, nameof(id)); var result = false; var deleteds = _systemFormRepository.Query(x => x.SystemFormId.In(id)); if (deleteds.NotEmpty()) { result = DeleteCore(deleteds, (deleted) => { if (deleted.IsDefault) { return(false); } //检查依赖项 _dependencyChecker.CheckAndThrow <Schema.Domain.Entity>(FormDefaults.ModuleName, deleted.SystemFormId); return(true); }); } return(result); }
public bool UpdateDefault(Guid entityId, Guid systemFormId) { Guard.NotEmpty(entityId, nameof(entityId)); Guard.NotEmpty(systemFormId, nameof(systemFormId)); //其他记录设置为非默认 var context = UpdateContextBuilder.Build <Domain.SystemForm>(); context.Set(f => f.IsDefault, false); context.Where(f => f.EntityId == entityId && f.SystemFormId != systemFormId); _systemFormRepository.Update(context); //设置为默认 context = UpdateContextBuilder.Build <Domain.SystemForm>(); context.Set(f => f.IsDefault, true); context.Set(f => f.AuthorizationEnabled, false); context.Where(f => f.SystemFormId == systemFormId); var result = true; using (UnitOfWork.Build(_systemFormRepository.DbContext)) { result = _systemFormRepository.Update(context); _eventPublisher.Publish(new AuthorizationStateChangedEvent { ObjectId = new List <Guid> { systemFormId } , State = false , ResourceName = FormDefaults.ModuleName }); //set to cache var items = _systemFormRepository.Query(f => f.EntityId == entityId).ToList(); foreach (var item in items) { _cacheService.SetEntity(item); } } return(result); }
public Domain.SystemForm FindEntityDefaultForm(Guid entityId) { List <Domain.SystemForm> items = _cacheService.GetVersionItems(entityId.ToString(), () => { return(_systemFormRepository.Query(f => f.EntityId == entityId)?.ToList()); }); Domain.SystemForm defaultForm = null; if (items.NotEmpty()) { defaultForm = items.FirstOrDefault(n => n.IsDefault == true); } if (defaultForm != null) { WrapLocalizedLabel(defaultForm); } return(defaultForm); }