コード例 #1
0
        /// <summary>
        /// 完成日志记录
        /// </summary>
        /// <param name="professionId"></param>
        /// <param name="newName"></param>
        /// <param name="instituteId"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public IActionResult Update([Required] Int32 professionId, [Required] String newName, [Required] Int32 instituteId, [Required] ProfessionType type)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }
                if (!_context.Institute.Any(ins => ins.InstituteId == instituteId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "不存在此学院!"
                    }));
                }

                Profession pro = _context.Professions.FirstOrDefault(p => p.ProfessionId == professionId);
                if (pro != null)
                {
                    LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(
                        PrincpalOperationCode.ProfessionUpdate, $"查询编号:{pro.InstituteId}",
                        $"修改专业信息被修改后的专业名{newName} 修改前{pro.Name} 或修改专业类型");

                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    pro.InstituteId             = instituteId;
                    pro.Name           = newName;
                    pro.ProfessionType = type;
                    _context.LogPricipalOperations.Add(log);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = true,
                        info = "修改成功!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "专业已经不存在,或者已被删除!"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = $"参数错误! 传递了错误的参数!"
                }));
            }
        }
コード例 #2
0
ファイル: ReExamController.cs プロジェクト: kickgod/lab
        public IActionResult Pass([Required] int apId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.StudentManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无学生管理操作权限"
                    }));
                }
                LogPricipalOperation operation =
                    _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.InspectReExamApplication, $"查询编码:{apId}", $"审核学生重考申请 通过审核 操作类:{nameof(ApplicationForReExamination)}");

                ApplicationForReExamination application = _context.ApplicationForReExaminations.FirstOrDefault(app => app.ApplicationExamId == apId && app.ApplicationStatus == ApplicationStatus.Submit);

                if (application != null)
                {
                    operation.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    application.ApplicationStatus     = ApplicationStatus.Pass;
                    Student student = _context.Student.Find(application.StudentId);
                    if (student == null)
                    {
                        return(Json(new
                        {
                            isOk = false,
                            title = "错误提示",
                            message = "学生不存在,或者已经删除"
                        }));
                    }

                    if (student.IsPassExam)
                    {
                        application.ApplicationStatus = ApplicationStatus.Fail;
                        _context.SaveChanges();
                        return(Json(new
                        {
                            isOk = false,
                            title = "错误提示",
                            message = "此人已经通过考试,自动判定审核失败"
                        }));
                    }
                    else
                    {
                        application.ApplicationStatus = ApplicationStatus.Pass;
                        student.MaxExamCount         += 2;
                        _context.SaveChanges();
                        return(Json(new
                        {
                            isOk = true,
                            title = "消息提示",
                            message = "审核成功"
                        }));
                    }
                }
                else
                {
                    operation.PrincpalOperationStatus = PrincpalOperationStatus.Fail;
                    _logger.Logger(operation);
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "申请不存在,或者已经被审核或删除"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    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;
            }
        }
コード例 #4
0
ファイル: ApplicationController.cs プロジェクト: kickgod/lab
        public IActionResult Pass([Required] int apId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.StudentManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无学生管理操作权限"
                    }));
                }
                LogPricipalOperation operation =
                    _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.InspectJoinApplication, $"{apId}", $"审核学生加入考试申请 通过审核");

                ApplicationJoinTheExamination applicationJoin = _context.ApplicationJoinTheExaminations.Find(apId);

                if (applicationJoin != null)
                {
                    //是否已经存在了
                    if (_context.Student.Any(s => s.StudentId == applicationJoin.StudentId))
                    {
                        _email.SendJoinEmail(applicationJoin.Email, applicationJoin.StudentId, applicationJoin.Name, applicationJoin.AddTime, false, "你已经在考试范围内!");
                        _context.SaveChanges();
                        return(Json(new
                        {
                            isOk = false,
                            title = "错误提示",
                            message = "审核结果: 此学生已经在考试范围内! 审核此申请失败."
                        }));
                    }
                    else
                    {
                        Student student = (Student)applicationJoin;
                        // //身份证后六位就是密码
                        student.Password = _encryption.EncodeByMd5(_encryption.EncodeByMd5(student.IDNumber.Substring(student.IDNumber.Length - 6, 6)));

                        SystemSetting setting = _config.LoadSystemSetting();
                        //如果这个学院有对应的模块 然后找到这个模块的 考试设置类
                        var insModule = _context.InstituteToModules.FirstOrDefault(im => im.InstituteId == student.InstituteId);
                        if (insModule != null)
                        {
                            //如果这个模块具有加载类
                            Boolean isHave = setting.ExamModuleSettings.TryGetValue(insModule.ModuleId, out var meSetting);
                            student.MaxExamCount = isHave? meSetting.AllowExamTime:2;
                        }
                        else
                        {
                            //如果学院灭有属于哪个模块
                            student.MaxExamCount = 2;
                        }

                        operation.PrincpalOperationStatus = PrincpalOperationStatus.Success; //日志记录 成功
                        applicationJoin.ApplicationStatus = ApplicationStatus.Pass;

                        _context.LogPricipalOperations.Add(operation);
                        _context.Student.Add(student);
                        _context.SaveChanges();

                        _email.SendJoinEmail(applicationJoin.Email, applicationJoin.StudentId, applicationJoin.Name, applicationJoin.AddTime, true, "");
                        return(Json(new
                        {
                            isOk = true,
                            title = "信息提示",
                            message = "审核完成!"
                        }));
                    }
                }
                else
                {
                    operation.PrincpalOperationStatus = PrincpalOperationStatus.Fail;
                    _logger.Logger(operation);
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "申请不存在,或者已经被删除"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
コード例 #5
0
        /// <summary>
        /// 完成日志记录
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public IActionResult Create([Bind(include: "ModuleId,Content,Answer,Count,A,B,C,D,E,F")] SingleChoices item)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.QuestionBankManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无题库管理操作权限"
                    }));
                }
                #region 功能实现区域
                LoginUserModel user = _analysis.GetLoginUserModel(HttpContext);
                String         Key  = _encryption.EncodeByMd5(item.Content.Trim());
                if (_context.SingleChoices.Any(s => s.Key == Key && s.ModuleId == item.ModuleId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你的题目已经存在! 重复题目无法加入"
                    }));
                }

                item.Content = item.Content.Trim();
                item.AddTime = DateTime.Now;
                item.Key     = Key;
                Char[] answer = item.Answer.ToUpper().Trim().ToCharArray();
                Array.Sort(answer);
                item.Answer             = String.Join("", answer); //答案全部大写
                item.A                  = item.A.Trim();
                item.B                  = item.B.Trim();
                item.C                  = item.C?.Trim();
                item.D                  = item.D?.Trim();
                item.E                  = item.E?.Trim();
                item.F                  = item.F?.Trim();
                item.Count              = item.Count;
                item.PrincipalId        = user.UserId;
                item.DegreeOfDifficulty = 1;
                LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.SingleAdd,
                                                                                  $"查询编码:{item.SingleId}", $"添加单择题:{item.Content}!");

                log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                _context.LogPricipalOperations.Add(log);
                _context.SingleChoices.Add(item);
                _context.SaveChanges();
                return(Json(new
                {
                    isOk = true,
                    title = "消息提示",
                    message = "添加成功!"
                }));

                #endregion
            }
            else
            {
                List <string> sb   = new List <string>();
                List <string> Keys = ModelState.Keys.ToList();
                foreach (var key in Keys)
                {
                    var errors = ModelState[key].Errors.ToList();
                    //将错误描述添加到sb中
                    foreach (var error in errors)
                    {
                        sb.Add(error.ErrorMessage);
                    }
                }
                return(Json(new
                {
                    isOk = false,
                    error = sb,
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
コード例 #6
0
        public async Task <IActionResult> Link([Bind(include: "Name,CourceId,Description,LengthOfStudy,ResourceUrl,ResourceType")] Resource resource)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无课程管理操作权限"
                    }));
                }
                #region 功能实现区域

                LogPricipalOperation operation =
                    _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.AddResource,
                                                           $"查询编码:无", "添加课程资源:资源链接{resource.ResourceUrl}");

                if (_context.Cources.Any(c => c.CourceId == resource.CourceId))
                {
                    if (_context.Resources.Any(r => r.Name == resource.Name && r.ResourceType == ResourceType.Link))
                    {
                        await _context.LogPricipalOperations.AddAsync(operation).ContinueWith(async r =>
                        {
                            await _context.SaveChangesAsync();
                        });


                        return(Json(new
                        {
                            isOk = false,
                            title = "错误提示",
                            message = "此名称的资源已经存在"
                        }));
                    }

                    resource.Name           = resource.Name.Trim();
                    resource.Description    = resource.Description.Trim();
                    resource.ResourceUrl    = resource.ResourceUrl.Trim();
                    resource.ResourceStatus = ResourceStatus.Normal;
                    resource.AddTime        = DateTime.Now;
                    resource.PrincipalId    = _analysis.GetLoginUserModel(HttpContext).UserId;
                    _context.Resources.Add(resource);

                    await _context.SaveChangesAsync().ContinueWith(result =>
                    {
                        operation.PrincpalOperationContent = $"添加资源ID {resource.ResourceId}";
                        operation.PrincpalOperationStatus  = PrincpalOperationStatus.Success;
                        _context.LogPricipalOperations.Add(operation);
                        _context.SaveChanges();
                    });

                    return(Json(new
                    {
                        isOk = true,
                        title = "消息提示",
                        message = "添加成功"
                    }));
                }
                else
                {
                    _context.LogPricipalOperations.Add(operation);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "资源所属课程不存在或者已经被删除!"
                    }));
                }
                #endregion
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
コード例 #7
0
ファイル: JudgeController.cs プロジェクト: kickgod/lab
        /// <summary>
        /// 记录日志
        /// </summary>
        /// <param name="judge"></param>
        /// <returns></returns>
        public IActionResult Create([Bind(include: "ModuleId,Content,Answer")] JudgeChoices judge)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.QuestionBankManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无题库管理操作权限"
                    }));
                }

                LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.AddJudge,
                                                                                  "查询编码:无", $"增加判断题 题目内容{judge.Content}");

                #region 功能实现区域
                LoginUserModel user = _analysis.GetLoginUserModel(HttpContext);
                String         Key  = _encryption.EncodeByMd5(judge.Content.Trim());
                if (_context.JudgeChoices.Any(j => j.Key == Key))
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你的题目已经存在! 重复题目无法加入"
                    }));
                }

                judge.Content            = judge.Content.Trim();
                judge.AddTime            = DateTime.Now;
                judge.Key                = Key;
                judge.Answer             = judge.Answer.ToUpper().Trim(); //答案全部大写
                judge.A                  = "是";
                judge.B                  = "否";
                judge.Count              = 2;
                judge.PrincipalId        = user.UserId;
                judge.DegreeOfDifficulty = 1;

                _context.JudgeChoices.Add(judge);
                _context.SaveChanges();

                log.PrincpalOperationName = $"查询编码:{judge.JudgeId}";
                _logger.Logger(log);
                return(Json(new
                {
                    isOk = true,
                    title = "消息提示",
                    message = "添加成功!"
                }));

                #endregion
            }
            else
            {
                List <string> sb   = new List <string>();
                List <string> Keys = ModelState.Keys.ToList();
                foreach (var key in Keys)
                {
                    var errors = ModelState[key].Errors.ToList();
                    //将错误描述添加到sb中
                    foreach (var error in errors)
                    {
                        sb.Add(error.ErrorMessage);
                    }
                }
                return(Json(new
                {
                    isOk = false,
                    error = sb,
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
コード例 #8
0
        /// <summary>
        /// 创建一个新的学院
        /// </summary>
        /// <param name="name"></param>
        /// <param name="moduleId"></param>
        /// <returns></returns>
        public async Task <IActionResult> Create([Required] String name, [Required] int moduleId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }

                if (_context.Modules.Any(m => m.ModuleId == moduleId))
                {
                    if (_context.Institute.Any(ins => ins.Name == name))
                    {
                        return(Json(new
                        {
                            isOk = false,
                            error = "新建学院名称重复,已经存在此学院"
                        }));
                    }
                    else
                    {
                        LogPricipalOperation log =
                            _logger.GetDefaultLogPricipalOperation(
                                PrincpalOperationCode.InstituteAdd,
                                $"添加新的学院",
                                $"添加新的学院名称 {name}");

                        log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                        _context.LogPricipalOperations.Add(log);
                        Institute institute = new Institute {
                            Name = name
                        };
                        _context.Institute.Add(institute);
                        await _context.SaveChangesAsync().ContinueWith(t =>
                        {
                            int result = t.Result;
                            if (result == 1)
                            {
                                InstituteToModule instituteToModule = new InstituteToModule();
                                instituteToModule.ModuleId          = moduleId;
                                instituteToModule.InstituteId       = institute.InstituteId;
                                _context.Add(instituteToModule);
                                _context.SaveChangesAsync();
                            }
                        });

                        return(Json(new
                        {
                            isOk = true,
                        }));
                    }
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "不存在此模块!学院不可属于此模块"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = "参数错误"
                }));
            }
        }
コード例 #9
0
ファイル: ManagerController.cs プロジェクト: kickgod/lab
        public IActionResult Create([Bind(include: "StudentId,IDNumber,InstituteId,Name,ProfessionId,BirthDate,Sex,StudentType,Grade,Email")] Student student)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.StudentManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误",
                        message = "你并无学生管理操作权限"
                    }));
                }
                Institute  ins = _context.Institute.FirstOrDefault(i => i.InstituteId == student.InstituteId);
                Profession pro = _context.Professions.FirstOrDefault(p => p.ProfessionId == student.ProfessionId);
                if (ins == null)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误",
                        message = "参数错误! 学院不存在! "
                    }));
                }
                if (pro == null)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误",
                        message = "参数错误! 专业不存在! "
                    }));
                }
                if (pro.InstituteId != ins.InstituteId)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误",
                        message = "此专业不属于此学院 !"
                    }));
                }
                if (_context.Student.Any(val => val.StudentId == student.StudentId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误",
                        message = "此学号的学生已经存在!"
                    }));
                }
                else
                {
                    var belong =
                        _context.InstituteToModules.FirstOrDefault(im => im.InstituteId == student.InstituteId);

                    if (belong != null)
                    {
                        SystemSetting setting  = _config.LoadSystemSetting();
                        Boolean       isConfig = setting.ExamModuleSettings.TryGetValue(belong.ModuleId, out var moduleExamSetting);
                        student.MaxExamCount = isConfig ? moduleExamSetting.AllowExamTime : 3;
                    }
                    else
                    {
                        student.MaxExamCount = 3; //系统默认考试次数三次
                    }

                    /* logger start */
                    LogPricipalOperation operation = _logger.GetDefaultLogPricipalOperation(
                        PrincpalOperationCode.AddStudent, $"{student.StudentId}",
                        $"增加学生 学号{student.InstituteId} 名称:{student.Name} ");
                    operation.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    /* logger end*/

                    student.IsPassExam   = false;
                    student.MaxExamScore = 0;
                    student.Password     = _ncryption.EncodeByMd5(_ncryption.EncodeByMd5(student.IDNumber.Substring(student.IDNumber.Length - 6, 6)));
                    _context.LogPricipalOperations.Add(operation);
                    _context.Student.Add(student);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = true,
                        title = "温馨提示",
                        message = "添加成功!"
                    }));
                }
            }
            else
            {
                List <string> errorParamters = new List <string>();
                List <string> Keys           = ModelState.Keys.ToList();
                foreach (var key in Keys)
                {
                    var errors = ModelState[key].Errors.ToList();
                    foreach (var error in errors)
                    {
                        errorParamters.Add(error.ErrorMessage);
                    }
                }
                return(Json(new
                {
                    error = errorParamters,
                    isOk = false,
                    title = "错误",
                    message = "参数错误!传入了错误的信息! "
                }));
            }
        }