public ModuleDTO Add(ModuleDTO moduleDTO) { var module = moduleDTO.ToModel(); module.Id = IdentityGenerator.NewSequentialGuid(); module.Created = DateTime.UtcNow; if (module.Name.IsNullOrBlank()) { throw new DefinedException(UserSystemMessagesResources.Name_Empty); } if (_Repository.Exists(module)) { throw new DataExistsException(string.Format(UserSystemMessagesResources.Module_Exists_WithValue, module.Name)); } _Repository.Add(module); #region 操作日志 var moduleDto = module.ToDto(); OperateRecorder.RecordOperation(moduleDto.Id.ToString(), UserSystemMessagesResources.Add_Module, moduleDto.GetOperationLog()); #endregion //commit the unit of work _Repository.UnitOfWork.Commit(); return(module.ToDto()); }
public void UpdateInstancesType(string source) { foreach (var instance in _instanceRepository.GetBy(source)) { if (!_moduleRepository.Exists(source, instance.ModuleName)) { continue; } instance.Type = InstanceType.Module; _instanceRepository.Update(instance); } }
public void Replace(string netlist, string gateToReplace, string newGate, PortsMapping portsMapping) { if (_moduleRepository.Exists(netlist, gateToReplace)) { throw new InvalidOperationException("can replace only library gates"); } var instances = _instanceRepository.GetByModuleName(netlist, gateToReplace); _instanceMutator.Take(instances) .MutateModuleName(newGate) .ReplacePorts(portsMapping); _instanceRepository.UpdateMany(instances); }
public async Task <IResultModel> Sync() { if (!_options.RefreshModuleOrPermission) { return(ResultModel.Success()); } var modules = _moduleCollection.Select(m => new ModuleEntity { Number = m.Id, Code = m.Code, Name = m.Name, Icon = m.Icon, Version = m.Version, Remarks = m.Description }); _logger.LogDebug("Sync Module Info"); using (var uow = _dbContext.NewUnitOfWork()) { foreach (var module in modules) { if (!await _repository.Exists(module, uow)) { if (!await _repository.AddAsync(module)) { uow.Rollback(); return(ResultModel.Failed()); } } else { if (!await _repository.UpdateByCode(module)) { uow.Rollback(); return(ResultModel.Failed()); } } } uow.Commit(); } return(ResultModel.Success()); }
public async Task <IResultModel> Sync() { using var uow = _dbContext.NewUnitOfWork(); var modules = _moduleCollection.Select(m => new ModuleEntity { Number = m.Id, Name = m.Name, Code = m.Code, Icon = m.Icon, Version = m.Version, Remarks = m.Description }); _logger.LogInformation("开始:同步模块信息"); foreach (var module in modules) { if (!await _repository.Exists(module, uow)) { if (!await _repository.AddAsync(module)) { return(ResultModel.Failed()); } } else { if (!await _repository.UpdateByCode(module)) { return(ResultModel.Failed()); } } } uow.Commit(); _logger.LogInformation("结束:同步模块信息"); return(ResultModel.Success()); }
protected override OperationResult OnBeforeAdd(Module entity) { OperationResult result = new OperationResult(); if (entity == null) { result.ResultType = OperationResultType.ParamError; result.Message = string.Format("{0}失败,{1}", Msg_BeforeAdd, "实体不能为空"); return(result); } //1、校验模块编号是否已存在 bool check = _moduleRepository.Exists(m => m.Code == entity.Code); if (check) { result.ResultType = OperationResultType.CheckFailedBeforeProcess; result.Message = string.Format("{0}失败,{1}", Msg_BeforeAdd, "模块编号已存在"); return(result); } result.ResultType = OperationResultType.Success; return(result); }
public void AddFlowToModule(string route, string system, string moduleName, FlowDefinition flow) { var moduleExists = _moduleRepository.Exists(route, system, moduleName); if (moduleExists) { _moduleRepository.AddFlowToExistingModule(route, system, moduleName, flow); } else { var module = new ModuleDefinition { Route = route, System = system, Module = moduleName, Flows = new List <FlowDefinition> { flow } }; _moduleRepository.AddModule(module); } }
private bool ModuleExists(int id) { return(moduleRepo.Exists(id) > 0); }
public async Task <IResultModel> Sync(List <PermissionEntity> permissions) { using var uow = _dbContext.NewUnitOfWork(); #region ==同步模块信息== var modules = _moduleCollection.Select(m => new ModuleEntity { Number = m.Id, Name = m.Name, Code = m.Code, Icon = m.Icon, Version = m.Version, Remarks = m.Description }); _logger.LogDebug("Sync Module Info"); foreach (var module in modules) { if (!await _repository.Exists(module, uow)) { if (!await _repository.AddAsync(module)) { return(ResultModel.Failed()); } } else { if (!await _repository.UpdateByCode(module)) { return(ResultModel.Failed()); } } } #endregion #region ==同步权限信息= if (permissions != null && permissions.Any()) { _logger.LogDebug("Sync Permission Info"); //先清除已有权限信息 if (await _permissionRepository.ClearAsync(uow)) { foreach (var permission in permissions) { if (!await _permissionRepository.AddAsync(permission, uow)) { return(ResultModel.Failed("同步失败")); } } //删除所有账户的权限缓存 await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_PERMISSIONS); } } #endregion uow.Commit(); return(ResultModel.Success()); }