コード例 #1
0
        public IActionResult Module([Required] int moduleId, [Required] String data)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemSettingManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无系统设置操作权限"
                    }));
                }
                Module module = _context.Modules.FirstOrDefault(m => m.ModuleId == moduleId);

                if (module == null)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示!",
                        message = "模块不存在或者已经被删除..."
                    }));
                }
                else
                {
                    try
                    {
                        ModuleExamSetting setting = JsonConvert.DeserializeObject <ModuleExamSetting>(data);
                        setting.ModuleName = module.Name;

                        int judgeCount  = _context.JudgeChoices.Count(j => j.ModuleId == setting.ModuleId);
                        int multiCount  = _context.MultipleChoices.Count(m => m.ModuleId == setting.ModuleId);
                        int singleCount = _context.SingleChoices.Count(s => s.ModuleId == setting.ModuleId);


                        if (setting.Judge.Count > judgeCount)
                        {
                            return(Json(new
                            {
                                isOk = false,
                                title = "提示!",
                                message = "判断题出题个数大于了题库中判断题题目的个数!"
                            }));
                        }

                        if (setting.Multiple.Count > multiCount)
                        {
                            return(Json(new
                            {
                                isOk = false,
                                title = "提示!",
                                message = "多选题出题个数大于了题库中多选题题目的个数!"
                            }));
                        }

                        if (setting.Single.Count > singleCount)
                        {
                            return(Json(new
                            {
                                isOk = false,
                                title = "提示!",
                                message = "单选题出题个数大于了题库中单选题题目的个数!"
                            }));
                        }

                        SystemSetting systemSetting = _config.LoadSystemSetting();
                        systemSetting.ExamModuleSettings[setting.ModuleId] = setting;
                        _config.ReWriteSystemSetting(systemSetting);

                        return(Json(new
                        {
                            isOk = true,
                            title = "提示!",
                            message = "更新成功!"
                        }));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    title = "错误提示",
                    message = "参数错误,输入了非法参数"
                }));
            }
        }
コード例 #2
0
        public IActionResult LoadSetting([Required] int moduleId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemSettingManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无系统设置操作权限"
                    }));
                }
                Module module = _context.Modules.FirstOrDefault(m => m.ModuleId == moduleId);
                if (module == null)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "模块不存在或者已经删除"
                    }));
                }
                if (System.IO.File.Exists(Path.GetFullPath($@"{_hosting.ContentRootPath}/SettingConfig.json")))
                {
                    try
                    {
                        using (var stream = new FileStream(Path.GetFullPath($@"{_hosting.ContentRootPath}/SettingConfig.json"),
                                                           FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                        {
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                String        json    = reader.ReadToEnd();
                                SystemSetting setting = JsonConvert.DeserializeObject <SystemSetting>(json);
                                Boolean       isOk    = setting.ExamModuleSettings.TryGetValue(moduleId, out var _moduleSetting);

                                if (isOk == true)
                                {
                                    return(Json(new
                                    {
                                        moduleSetting = _moduleSetting,
                                        isOk = true,
                                        title = "提示",
                                        message = "加载成功!"
                                    }));
                                }
                                else
                                {
                                    //如果没有模块设置将会加载默认设置
                                    ModuleExamSetting msetting = SystemSetting.GetDefault();
                                    msetting.ModuleId   = module.ModuleId;
                                    msetting.ModuleName = module.Name;

                                    return(Json(new
                                    {
                                        moduleSetting = msetting,
                                        isOk = true,
                                        title = "提示",
                                        message = "加载成功!"
                                    }));
                                }
                            };
                        };
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "严重错误提示!",
                        message = "系统配置文件丢失...请联系系统维护人员!及时处理..."
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    title = "错误提示",
                    message = "参数错误,模块信息插入失败"
                }));
            }
        }
コード例 #3
0
ファイル: ModuleController.cs プロジェクト: kickgod/lab
        public async Task <IActionResult> Create([Required] String name)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                    {
                        return(Json(new
                        {
                            isOk = false,
                            error = "你并无信息管理操作权限"
                        }));
                    }

                    LogPricipalOperation operation = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.AddModule, $"添加模块 模块名称{name.Trim()}", $"添加新的的模块:{name.Trim()}");

                    if (_context.Modules.FirstOrDefault(m => m.Name.Equals(name)) == null)
                    {
                        operation.PrincpalOperationStatus = PrincpalOperationStatus.Success;

                        Module module = new Module {
                            AddTime = DateTime.Now, Name = name.Trim(), PrincipalId = _analysis.GetLoginUserModel(HttpContext).UserId
                        };

                        _context.LogPricipalOperations.Add(operation);
                        _context.Modules.Add(module);

                        await _context.SaveChangesAsync().ContinueWith(r =>
                        {
                            /* 考试出题配置 */
                            SystemSetting setting = _config.LoadSystemSetting();
                            ModuleExamSetting mes = SystemSetting.GetDefault();
                            mes.ModuleId          = module.ModuleId;
                            mes.ModuleName        = module.Name;
                            setting.ExamModuleSettings.Add(module.ModuleId, mes);
                            _config.ReWriteSystemSetting(setting);

                            /* 考试开放配置 */
                            Dictionary <int, ExamOpenSetting> es = _config.LoadModuleExamOpenSetting();
                            ExamOpenSetting examSetting          = new ExamOpenSetting();
                            examSetting.ModuleId   = module.ModuleId;
                            examSetting.IsOpen     = false;
                            examSetting.ModuleName = module.Name;
                            es.Add(module.ModuleId, examSetting);
                            _config.ReWriteModuleExamOpenSetting(es);
                        });

                        return(Json(new
                        {
                            isOk = true
                        }));
                    }
                    else
                    {
                        await _logger.LoggerAsync(operation);

                        return(Json(new
                        {
                            isOk = false,
                            error = "模块名重复,此模块已经存在"
                        }));
                    }
                }
                else
                {
                    return(RedirectToAction("ParameterError", "Error"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }