Пример #1
0
        /// <summary>
        ///  完成日志记录此方法: AddInstitute
        /// </summary>
        /// <param name="moduleId"></param>
        /// <param name="instituteId"></param>
        /// <returns></returns>
        public IActionResult AddInstitute([Required] int moduleId, [Required] int instituteId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }

                if (_context.Modules.Any(val => val.ModuleId == moduleId) && _context.Institute.Any(ins => ins.InstituteId == instituteId))
                {
                    LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.ChangeInstituteToModule, " 学院id: {instituteId} 模块id {moduleId}", $"将一个学院归属要这个模块 学院id: {instituteId} 模块id {moduleId}");

                    if (_context.InstituteToModules.Any(one =>
                                                        one.InstituteId == instituteId))
                    {
                        _logger.Logger(log);
                        return(Json(new
                        {
                            isOk = false,
                            error = "学院有归属了! 一个学院不能属于两个模块"
                        }));
                    }
                    else
                    {
                        InstituteToModule im = new InstituteToModule {
                            InstituteId = instituteId, ModuleId = moduleId
                        };
                        log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                        _context.InstituteToModules.Add(im);
                        _context.LogPricipalOperations.Add(log);
                        _context.SaveChanges();
                        return(Json(new
                        {
                            isOk = true,
                        }));
                    }
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "模块或者学院不存在! 你不要搞我涩!"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = "参数错误"
                }));
            }
        }
Пример #2
0
        /// <summary>
        /// 启动日志记录
        /// </summary>
        /// <param name="rId"></param>
        /// <returns></returns>
        public async Task <IActionResult> Stop([Required] int rId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无课程管理操作权限"
                    }));
                }

                LogPricipalOperation operation = _logger.
                                                 GetDefaultLogPricipalOperation(PrincpalOperationCode.StopUseResource, $"停用课程资源 编号{rId}", "停用课程资源");

                Resource resource = _context.Resources.Find(rId);
                if (resource != null)
                {
                    resource.ResourceStatus           = ResourceStatus.Normal;
                    operation.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.LogPricipalOperations.Add(operation);
                    await _context.SaveChangesAsync();

                    return(Json(new
                    {
                        isOk = true,
                        title = "消息提示",
                        message = "修改成功!"
                    }));
                }
                else
                {
                    await _context.LogPricipalOperations.AddAsync(operation).ContinueWith(r =>
                    {
                        _context.SaveChangesAsync();
                    });


                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "资源不存在,或者已经被删除了"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #3
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 = $"参数错误! 传递了错误的参数!"
                }));
            }
        }
Пример #4
0
        /// <summary>
        /// 完成日志记录
        /// </summary>
        /// <param name="professionId"></param>
        /// <returns></returns>
        public IActionResult Delete([Required] int professionId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }
                if (_context.Student.Any(stu => stu.ProfessionId == professionId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        Error = "尚有学生属于此专业,无法删除此专业!"
                    }));
                }

                Profession pro = _context.Professions.FirstOrDefault(p => p.ProfessionId == professionId);
                if (pro != null)
                {
                    LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(
                        PrincpalOperationCode.ProfessionDelete, $"查询编号:{pro.InstituteId}",
                        $"删除专业{pro.Name}");

                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.Professions.Remove(pro);
                    _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 = "参数错误! 传递了错误的参数!"
                }));
            }
        }
Пример #5
0
        public IActionResult Delete([Required] String sId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.StudentManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误信息",
                        message = "你并无学生管理操作权限"
                    }));
                }
                Student stu = _context.Student.Find(sId);
                if (stu != null)
                {
                    LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(
                        PrincpalOperationCode.DeleteStudent, $"查询编码:{stu.StudentId}", $"删除学生{stu.Name}");
                    List <ApplicationForReExamination> apps = _context.ApplicationForReExaminations
                                                              .Where(app => app.StudentId == sId).ToList();
                    if (apps.Count > 0)
                    {
                        _context.ApplicationForReExaminations.RemoveRange(apps);
                    }

                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.Add(log);
                    _context.Student.Remove(stu);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = true,
                        title = "提示信息",
                        message = "删除成功!!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误信息",
                        message = "学生不存在或者已经被删除了!"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    title = "错误信息",
                    message = "传入的参数错误"
                }));
            }
        }
Пример #6
0
        public IActionResult Fail([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}", $"审核学生重考申请 不通过审核 操作类: {nameof(ApplicationForReExamination)}");
                ApplicationForReExamination application = _context.ApplicationForReExaminations.Find(apId);

                if (application != null)
                {
                    application.ApplicationStatus = ApplicationStatus.Fail;
                    _context.LogPricipalOperations.Add(operation);
                    _context.SaveChanges();

                    _email.SendReEmail(application.Email, application.StudentId, application.Student?.Name, application.AddTime, false);
                    return(Json(new
                    {
                        isOk = true,
                        title = "消息提示",
                        message = "审核完毕!"
                    }));
                }
                else
                {
                    _logger.Logger(operation);
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "学生申请记录不存在,或者已经被删除!"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #7
0
        /// <summary>
        /// 完成日志记录方法
        /// </summary>
        /// <param name="moduleId"></param>
        /// <param name="newName"></param>
        /// <returns></returns>
        public IActionResult ReName([Required] int moduleId, [Required] String newName)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }

                Module module = _context.Modules.Find(moduleId);
                if (module != null)
                {
                    LogPricipalOperation log =
                        _logger.GetDefaultLogPricipalOperation(
                            PrincpalOperationCode.ModuleReName,
                            $"查询编码:{moduleId} ",
                            $"重命名模块 {module.Name} 名称为 {newName}");

                    module.Name = newName;
                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.LogPricipalOperations.Add(log);
                    _context.SaveChanges();

                    return(Json(new
                    {
                        isOk = true
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "没有这个模块"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = "参数错误"
                }));
            }
        }
Пример #8
0
        /// <summary>
        /// 完成日志记录
        /// </summary>
        /// <param name="newName">模块新名称</param>
        /// <param name="instituteId">修改的模块的编码</param>
        /// <returns></returns>
        public async Task <IActionResult> Update([Required] String newName, [Required] int instituteId)
        {
            if (ModelState.IsValid && instituteId > 0)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }
                Institute ins = _context.Institute.FirstOrDefault(one => one.InstituteId == instituteId);
                if (ins != null)
                {
                    LogPricipalOperation log =
                        _logger.GetDefaultLogPricipalOperation(
                            PrincpalOperationCode.InstituteUpdate,
                            $"查询编码:{ins.InstituteId} ",
                            $"修改学院信息:{ins.Name} 名称改为 {newName}");

                    ins.Name = newName;
                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.LogPricipalOperations.Add(log);
                    await _context.SaveChangesAsync();

                    return(Json(new
                    {
                        isOk = true,
                        info = "修改成功!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "参数错误 !并不存在此学院"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = "参数错误"
                }));
            }
        }
Пример #9
0
        /// <summary>
        ///  完成日志记录方法 DeleteInstitute
        /// </summary>
        /// <param name="moduleId"></param>
        /// <param name="instituteId"></param>
        /// <returns></returns>
        public IActionResult DeleteInstitute([Required] int moduleId, [Required] int instituteId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }
                LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.DeleteInstituteFromModule, " 学院id: {instituteId} 模块id {moduleId}", $"将一个学院从此模块中排除出去 学院id: {instituteId} 模块id {moduleId}");

                InstituteToModule im = _context.InstituteToModules.FirstOrDefault(val =>
                                                                                  val.InstituteId == instituteId && val.ModuleId == moduleId);

                if (im != null)
                {
                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.InstituteToModules.Remove(im);
                    _context.LogPricipalOperations.Add(log);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = true
                    }));
                }
                else
                {
                    _logger.Logger(log);
                    return(Json(new
                    {
                        isOk = false,
                        error = "没有此条记录,记录着此学院属于此模块"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = "参数错误"
                }));
            }
        }
Пример #10
0
 public IActionResult Item([Required] Int32 logId)
 {
     if (ModelState.IsValid)
     {
         LogPricipalOperation log = _context.LogPricipalOperations.Find(logId);
         if (log == null)
         {
             return(Json(new
             {
                 isOk = false,
                 title = "错误提示",
                 message = "日志记录不存在,或者已经被删除!"
             }));
         }
         else
         {
             return(Json(new
             {
                 isOk = true,
                 title = "错误提示",
                 message = "加载成功",
                 principalId = log.PrincipalId,
                 addTime = _logger.FormatDateLocal(log.AddTime),
                 ip = log.OperationIp,
                 code = log.PrincpalOperationCode.ToString(),
                 target = log.PrincpalOperationName,
                 status = log.PrincpalOperationStatus == PrincpalOperationStatus.Success ? "操作成功" : "操作失败",
                 content = log.PrincpalOperationContent
             }));
         }
     }
     else
     {
         return(Json(new
         {
             isOk = false,
             error = _analysis.ModelStateDictionaryError(ModelState),
             title = "错误提示",
             message = "参数错误,传递了不符合规定的参数"
         }));
     }
 }
Пример #11
0
        /// <summary>
        /// 开启日志记录
        /// </summary>
        /// <param name="rId"></param>
        /// <returns></returns>
        public IActionResult Item([Required] int rId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无课程管理操作权限"
                    }));
                }

                Resource             r   = _context.Resources.Find(rId);
                LogPricipalOperation log =
                    _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.SearchData, $"查询编码:{rId}", "查询课程资源信息");
                if (r != null)
                {
                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.LogPricipalOperations.Add(log);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = true,
                        resourceId = r.ResourceId,
                        id = r.ResourceId,
                        name = r.Name,
                        addTime = r.AddTime,
                        lengthOfStudy = r.LengthOfStudy,
                        description = r.Description,
                        cource = r.Cource,
                        courceId = r.CourceId,
                        link = r.ResourceUrl,
                        url = $"/video/{r.ResourceUrl}",
                        rType = r.ResourceType,
                        isVideo = r.ResourceType != ResourceType.Link,
                        type = r.ResourceType == ResourceType.Link ? "链接资源" : "视频资源",
                        status = r.ResourceStatus == ResourceStatus.Normal ? "未使用" : "使用中",
                        title = "消息提示",
                        message = "加载成功!"
                    }));
                }
                else
                {
                    _context.LogPricipalOperations.Add(log);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = false,
                        error = _analysis.ModelStateDictionaryError(ModelState),
                        title = "错误提示",
                        message = "资源不存在!或者已经被删除了"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #12
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 = "参数错误"
                }));
            }
        }
Пример #13
0
        /// <summary>
        /// 完成日志记录
        /// </summary>
        /// <param name="moduleId"></param>
        /// <returns></returns>
        public IActionResult Delete([Required] int moduleId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemInfoManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        error = "你并无信息管理操作权限"
                    }));
                }

                if (_context.Cources.Any(cor => cor.ModuleId == moduleId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        Error = "此模块下具有课程信息! 请先删除此模块下辖的所有课程后再来删除模块!"
                    }));
                }

                if (_context.MultipleChoices.Any(mul => mul.ModuleId == moduleId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        Error = "此模块下具有多选题信息! 请先删除此模块下辖的所有多选题后再来删除模块!"
                    }));
                }

                if (_context.MultipleChoices.Any(mul => mul.ModuleId == moduleId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        Error = "此模块下具有多选题信息! 请先删除此模块下辖的所有多选题后再来删除模块!"
                    }));
                }

                if (_context.SingleChoices.Any(sig => sig.ModuleId == moduleId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        Error = "此模块下具有单选题信息! 请先删除此模块下辖的所有单选题后再来删除模块!"
                    }));
                }

                if (_context.JudgeChoices.Any(jud => jud.ModuleId == moduleId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        Error = "此模块下具有判断题信息! 请先删除此模块下辖的所有判断题后再来删除模块!"
                    }));
                }

                //判断是否具有学院属于它
                if (!_context.InstituteToModules.Any(im => im.ModuleId == moduleId))
                {
                    Module module = _context.Modules.FirstOrDefault(m => m.ModuleId == moduleId);
                    if (module != null)
                    {
                        /* 重写考试配置 */
                        SystemSetting setting = _config.LoadSystemSetting();
                        setting.ExamModuleSettings.Remove(moduleId);
                        _config.ReWriteSystemSetting(setting);

                        /* 重写开发配置*/
                        Dictionary <int, ExamOpenSetting> es = _config.LoadModuleExamOpenSetting();
                        es.Remove(module.ModuleId);
                        _config.ReWriteModuleExamOpenSetting(es);


                        _context.Remove(module); //删除这个模块
                        LogPricipalOperation log =
                            _logger.GetDefaultLogPricipalOperation(
                                PrincpalOperationCode.ModuleDelete,
                                $"查询编码:{moduleId} ",
                                $"删除模块:{module.Name}");

                        log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                        _context.LogPricipalOperations.Add(log);

                        _context.SaveChanges();
                        return(Json(new
                        {
                            isOk = true
                        }));
                    }
                    else
                    {
                        return(Json(new
                        {
                            isOk = false,
                            Error = "没有这个模块"
                        }));
                    }
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        Error = "此模块下具有学院信息! 请先删除此模块下辖的所有学院后再来删除模块!"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = "参数错误"
                }));
            }
        }
Пример #14
0
        public IActionResult All([Required] int iId, [Required] int type, [Required] int pId, [Required] int status, [Required] int grade, String keyName)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.StudentManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无学生管理操作权限"
                    }));
                }

                StringBuilder builder =
                    new StringBuilder("select * from  ApplicationJoinTheExaminations where ApplicationJoinId > 0");
                if (iId > 0)
                {
                    builder.Append($" and InstituteId = {iId}");
                }

                if (type >= 0)
                {
                    builder.Append($" and StudentType = {type}");
                }

                if (pId >= 0)
                {
                    builder.Append($" and ProfessionId = {pId}");
                }

                if (status >= 0)
                {
                    builder.Append($" and ApplicationStatus = {status}");
                }

                if (grade >= 0)
                {
                    builder.Append($" and Grade = {grade}");
                }

                List <SqlParameter> parameters = new List <SqlParameter>();
                if (keyName != null && keyName.Trim() != "")
                {
                    builder.Append($" and Name like '%@keyName%'");

                    SqlParameter parameter = new SqlParameter
                    {
                        SqlDbType     = SqlDbType.NVarChar,
                        ParameterName = "@keyName",
                        Value         = keyName
                    };
                    parameters.Add(parameter);

                    builder.Append($" or StudentId like '@id'");

                    SqlParameter parameterId = new SqlParameter
                    {
                        SqlDbType     = SqlDbType.NVarChar,
                        ParameterName = "@id",
                        Value         = keyName
                    };
                    parameters.Add(parameterId);
                }
                // ReSharper disable once CoVariantArrayConversion
                List <ApplicationJoinTheExamination> list = _context.ApplicationJoinTheExaminations
                                                            .FromSql(builder.ToString(), parameters.ToArray <SqlParameter>()).Where(app => app.ApplicationStatus == ApplicationStatus.Submit).ToList();

                if (list.Count == 0)
                {
                    return(Json(new
                    {
                        isOk = true,
                        title = "信息提示",
                        message = "并无未审核的考试申请"
                    }));
                }

                SystemSetting setting = _config.LoadSystemSetting();//记载配置文件

                foreach (var item in list)
                {
                    LogPricipalOperation operation = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.InspectAllJoinApplicationPass,
                                                                                            $"{item.ApplicationJoinId}", "审核所有学生加入考试申请 不允许通过 ");
                    item.ApplicationStatus = ApplicationStatus.Pass;
                    _context.LogPricipalOperations.Add(operation);
                    Student student = (Student)item;
                    //身份证后六位就是密码
                    student.Password = _encryption.EncodeByMd5(_encryption.EncodeByMd5(student.IDNumber.Substring(student.IDNumber.Length - 6, 6)));
                    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
                    {
                        //如果学院没有属于哪个模块 默认为 2
                        student.MaxExamCount = 2;
                    }

                    _context.Student.Add(student);
                    //邮件通知
                    _email.SendJoinEmail(item.Email, item.StudentId, item.Name, item.AddTime, true, "");
                }
                _context.SaveChanges();
                return(Json(new
                {
                    isOk = true,
                    title = "消息提示",
                    message = "审核成功!"
                }));
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #15
0
        public IActionResult Not([Required] int iId, [Required] int type, [Required] int pId, [Required] int status, [Required] int grade, String keyName)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.StudentManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无学生管理操作权限"
                    }));
                }

                StringBuilder builder =
                    new StringBuilder("select * from  ApplicationJoinTheExaminations where ApplicationJoinId > 0");
                if (iId > 0)
                {
                    builder.Append($" and InstituteId = {iId}");
                }

                if (type >= 0)
                {
                    builder.Append($" and StudentType = {type}");
                }

                if (pId >= 0)
                {
                    builder.Append($" and ProfessionId = {pId}");
                }

                if (status >= 0)
                {
                    builder.Append($" and ApplicationStatus = {status}");
                }

                if (grade >= 0)
                {
                    builder.Append($" and Grade = {grade}");
                }

                List <SqlParameter> parameters = new List <SqlParameter>();
                if (keyName != null && keyName.Trim() != "")
                {
                    builder.Append($" and Name like '%@keyName%'");

                    SqlParameter parameter = new SqlParameter
                    {
                        SqlDbType     = SqlDbType.NVarChar,
                        ParameterName = "@keyName",
                        Value         = keyName
                    };
                    parameters.Add(parameter);

                    builder.Append($" or StudentId like '@id'");

                    SqlParameter parameterId = new SqlParameter
                    {
                        SqlDbType     = SqlDbType.NVarChar,
                        ParameterName = "@id",
                        Value         = keyName
                    };
                    parameters.Add(parameterId);
                }
                // ReSharper disable once CoVariantArrayConversion
                List <ApplicationJoinTheExamination> list = _context.ApplicationJoinTheExaminations
                                                            .FromSql(builder.ToString(), parameters.ToArray <SqlParameter>()).Where(app => app.ApplicationStatus == ApplicationStatus.Submit).ToList();

                if (list.Count == 0)
                {
                    return(Json(new
                    {
                        isOk = true,
                        title = "信息提示",
                        message = "并无未审核的考试申请"
                    }));
                }

                foreach (var item in list)
                {
                    LogPricipalOperation operation = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.InspectAllJoinApplicationFail,
                                                                                            $"{item.ApplicationJoinId}", "审核所有学生加入考试申请 不允许通过");
                    item.ApplicationStatus = ApplicationStatus.Fail;
                    _context.LogPricipalOperations.Add(operation);
                    _email.SendJoinEmail(item.Email, item.StudentId, item.Name, item.AddTime, false, "申请原因说明不详细!或者个人信息有误!");
                }
                _context.SaveChanges();
                return(Json(new
                {
                    isOk = true,
                    title = "消息提示",
                    message = "审核成功!"
                }));
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #16
0
        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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #17
0
        /// <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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #18
0
 public int Logger(LogPricipalOperation operation)
 {
     _context.LogPricipalOperations.Add(operation);
     return(_context.SaveChanges());
 }
Пример #19
0
        /// <summary>
        /// 完成日志记录
        /// </summary>
        /// <param name="judgeId"></param>
        /// <param name="content"></param>
        /// <param name="answer"></param>
        /// <returns></returns>
        public IActionResult Update([Required] int judgeId, [Required] String content, [Required] String answer)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.QuestionBankManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无题库管理操作权限"
                    }));
                }

                JudgeChoices judge = _context.JudgeChoices.Find(judgeId);
                if (judge != null)
                {
                    LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.JudgeUpdate,
                                                                                      $"查询编码:{judge.JudgeId}", $"修改判断题题目内容!");
                    String Key = _encryption.EncodeByMd5(content.Trim());

                    //如果题干已经被改变了 那么重新编码
                    if (judge.Content != content)
                    {
                        //检查重复性
                        if (_context.JudgeChoices.Any(j => j.Key == Key))
                        {
                            return(Json(new
                            {
                                isOk = false,
                                title = "错误提示",
                                message = "你的题目已经存在! 或者未作出修改"
                            }));
                        }
                    }
                    judge.Content               = content.Trim();
                    judge.AddTime               = DateTime.Now;
                    judge.Key                   = Key;
                    judge.Answer                = answer.ToUpper().Trim(); //答案全部大写
                    judge.DegreeOfDifficulty    = 1;                       //重置题目难度
                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.LogPricipalOperations.Add(log);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = true,
                        title = "消息提示",
                        message = "修改成功!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "不存在此题目"
                    }));
                }
            }
            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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #20
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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #21
0
        /// <summary>
        /// 开启日志记录
        /// </summary>
        /// <param name="rId">资源编号Id</param>
        /// <returns></returns>
        public async Task <IActionResult> Delete([Required] int rId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无课程管理操作权限"
                    }));
                }

                Resource resource = _context.Resources.Find(rId);
                /*日志记录*/
                LogPricipalOperation operation =
                    _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.DeleteResource, $"删除资源编码:{rId}",
                                                           "删除课程资源");
                if (resource != null)
                {
                    if (resource.ResourceType == ResourceType.Vedio)
                    {
                        String path = Path.GetFullPath($@"{_hosting.WebRootPath}/video/{resource.ResourceUrl}");
                        if (System.IO.File.Exists(path))
                        {
                            System.IO.File.Delete(path);
                        }
                    }

                    _context.Resources.Remove(resource);
                    await _context.SaveChangesAsync().ContinueWith(result =>
                    {
                        operation.PrincpalOperationName   = $"删除资源编码:{rId} 资源名称{resource.Name}";
                        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 = "资源不存在或者已经被删除了"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #22
0
        public async Task <IActionResult> Upload()
        {
            if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
            {
                return(Json(new
                {
                    isOk = false,
                    title = "错误提示",
                    message = "你并无课程管理操作权限"
                }));
            }

            DateTime dt       = DateTime.Now;
            int      year     = dt.Year;
            String   month    = dt.Month > 9 ? dt.Month.ToString() : $"0{dt.Month}";
            String   day      = dt.Day > 9 ? dt.Day.ToString() : $"0{dt.Day}";
            String   hour     = dt.Hour > 9 ? dt.Hour.ToString() : $"0{dt.Hour}";
            String   m        = dt.Minute > 9 ? dt.Minute.ToString() : $"0{dt.Minute}";
            String   s        = dt.Second > 9 ? dt.Second.ToString() : $"0{dt.Second}";
            int      ms       = dt.Millisecond;
            String   fileName = $"{year}{month}{day}{hour}{m}{s}{ms}.mp4";

            FormValueProvider formModel = await Request.StreamFiles(Path.GetFullPath($@"{_hosting.WebRootPath}/video"), fileName);

            Resource resource = new Resource();;

            var bindingSuccessful = await TryUpdateModelAsync(resource, prefix : "", valueProvider : formModel);

            if (!bindingSuccessful)
            {
                if (!ModelState.IsValid)
                {
                    var path = Path.GetFullPath($@"{_hosting.WebRootPath}/video/{fileName}");
                    if (System.IO.File.Exists(path))
                    {
                        System.IO.File.Delete(path);
                    }
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误信息",
                        model = resource,
                        message = $"参数错误! 增加错误!"
                    }));
                }
            }

            LogPricipalOperation operation = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.AddResource,
                                                                                    $"新添资源类型{resource.ResourceType}", "添加新的课程资源");

            if (!_context.Cources.Any(c => c.CourceId == resource.CourceId))
            {
                _context.LogPricipalOperations.Add(operation);
                _context.SaveChanges();
                return(Json(new
                {
                    isOk = false,
                    title = "错误提示",
                    message = "资源所属课程不存在或者已经被删除!"
                }));
            }

            if (_context.Resources.Any(r => r.Name == resource.Name && r.ResourceType == ResourceType.Vedio))
            {
                var path = Path.GetFullPath($@"{_hosting.WebRootPath}/video/{fileName}");
                if (System.IO.File.Exists(path))
                {
                    System.IO.File.Delete(path);
                }
                _context.LogPricipalOperations.Add(operation);
                _context.SaveChanges();
                return(Json(new
                {
                    isOk = false,
                    title = "错误信息",
                    message = $"这个资源已经具有同名的了!请另外取一个名字吧!"
                }));
            }
            else
            {
                resource.Name           = resource.Name.Trim();
                resource.ResourceType   = ResourceType.Vedio;
                resource.Description    = resource.Description.Trim();
                resource.ResourceStatus = ResourceStatus.Normal;
                resource.ResourceUrl    = fileName;
                resource.AddTime        = DateTime.Now;
                resource.PrincipalId    = _analysis.GetLoginUserModel(HttpContext).UserId;
                _context.Resources.Add(resource);
                operation.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                _context.LogPricipalOperations.Add(operation);
                await _context.SaveChangesAsync();

                return(Json(new
                {
                    isOk = true,
                    title = "信息提示",
                    message = $"添加成功!"
                }));
            }
        }
Пример #23
0
        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;
            }
        }
Пример #24
0
        /// <summary>
        /// 开启日志记录
        /// </summary>
        /// <param name="rId">编号</param>
        /// <param name="name">新名称</param>
        /// <param name="link">新连接</param>
        /// <returns></returns>
        public IActionResult Update([Required] int rId, [Required] String name, [Required] String link)
        {
            if (ModelState.IsValid || name.Length > 150 || link.Length >= 400)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无题库管理操作权限"
                    }));
                }

                Resource             r   = _context.Resources.Find(rId);
                LogPricipalOperation log =
                    _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.UpdateResource, $"查询编码:{rId}", $"修改链接资源信息 新连接{link}, 修改新名称:{name}");
                if (r != null)
                {
                    try
                    {
                        if (r.ResourceType == ResourceType.Link)
                        {
                            r.ResourceUrl = link.Trim();
                        }
                        r.Name = name.Trim();
                        log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                        _context.LogPricipalOperations.Add(log);
                        _context.SaveChanges();
                        return(Json(new
                        {
                            isOk = true,
                            title = "提示信息",
                            message = "修改成功!"
                        }));
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
                else
                {
                    _context.LogPricipalOperations.Add(log);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = false,
                        error = _analysis.ModelStateDictionaryError(ModelState),
                        title = "错误提示",
                        message = "资源不存在!或者已经被删除了"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #25
0
        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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #26
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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #27
0
        public IActionResult All([Required] int iId, [Required] int type, [Required] int pId, [Required] int status, [Required] int grade, String keyName)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.StudentManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无学生管理操作权限"
                    }));
                }

                StringBuilder builder = new StringBuilder("select * from  ReExamApplicationView where ApplicationExamId > 0");
                if (iId > 0)
                {
                    builder.Append($" and InstituteId = {iId}");
                }

                if (type >= 0)
                {
                    builder.Append($" and StudentType = {type}");
                }

                if (pId >= 0)
                {
                    builder.Append($" and ProfessionId = {pId}");
                }

                if (status >= 0)
                {
                    builder.Append($" and ApplicationStatus = {status}");
                }

                if (grade >= 0)
                {
                    builder.Append($" and Grade = {grade}");
                }

                List <SqlParameter> parameters = new List <SqlParameter>();
                if (keyName != null && keyName.Trim() != "")
                {
                    builder.Append($" and Name like '%@keyName%'");

                    SqlParameter parameter = new SqlParameter
                    {
                        SqlDbType     = SqlDbType.NVarChar,
                        ParameterName = "@keyName",
                        Value         = keyName
                    };
                    parameters.Add(parameter);

                    builder.Append($" or StudentId like '@id'");

                    SqlParameter parameterId = new SqlParameter
                    {
                        SqlDbType     = SqlDbType.NVarChar,
                        ParameterName = "@id",
                        Value         = keyName
                    };
                    parameters.Add(parameterId);
                }
                // ReSharper disable once CoVariantArrayConversion
                List <vReExamApplicationMap> list = _context.VReExamApplicationMaps
                                                    .FromSql(builder.ToString(), parameters.ToArray <SqlParameter>()).Where(app => app.ApplicationStatus == ApplicationStatus.Submit).ToList();

                if (list.Count == 0)
                {
                    return(Json(new
                    {
                        isOk = true,
                        title = "信息提示",
                        message = "并无未审核的考试申请"
                    }));
                }

                SystemSetting setting = _config.LoadSystemSetting();//记载配置文件

                foreach (var item in list)
                {
                    LogPricipalOperation operation = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.InspectAllReExamApplicationFail, $"查询编码:{item.ApplicationExamId}", $"审核所有学生重考申请 不通过 操作类: {nameof(ApplicationForReExamination)}");
                    _context.Database.ExecuteSqlCommand($"UPDATE [dbo].[ApplicationForReExaminations] SET [ApplicationStatus] = {(int)ApplicationStatus.Fail} Where  [ApplicationExamId] = {item.ApplicationExamId}");
                    _email.SendReEmail(item.Email, item.StudentId, item.Name, item.AddTime, true, "");
                    _context.LogPricipalOperations.Add(operation);
                }
                _context.SaveChanges();
                return(Json(new
                {
                    isOk = true,
                    title = "消息提示",
                    message = "审核成功!"
                }));
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #28
0
        /// <summary>
        /// 完成日志记录
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public IActionResult Update([Bind(include: "SingleId,ModuleId,Content,Answer,A,B,C,D,E,F")] SingleChoices item)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.QuestionBankManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无题库管理操作权限"
                    }));
                }

                SingleChoices single = _context.SingleChoices.Find(item.SingleId);
                if (single != null)
                {
                    String key = _encryption.EncodeByMd5(item.Content.Trim());

                    //如果题干已经被改变了 那么重新编码
                    if (single.Content != item.Content.Trim())
                    {
                        //检查重复性
                        if (_context.SingleChoices.Any(i => i.Key == key && i.ModuleId == item.ModuleId))
                        {
                            return(Json(new
                            {
                                isOk = false,
                                title = "错误提示",
                                message = "你的题目已经存在! 或者未作出修改"
                            }));
                        }
                    }
                    single.Content = item.Content.Trim();
                    single.AddTime = DateTime.Now;
                    single.Key     = key;
                    //答案排序一下
                    Char[] answer = item.Answer.ToUpper().Trim().ToCharArray();
                    Array.Sort(answer);
                    single.Answer             = String.Join("", answer); //答案全部大写
                    single.DegreeOfDifficulty = 1;                       //重置题目难度
                    single.A = item.A.Trim();
                    single.B = item.B.Trim();
                    single.C = item.C?.Trim();
                    single.D = item.D?.Trim();
                    single.E = item.E?.Trim();
                    single.F = item.F?.Trim();
                    LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.SingleUpdate,
                                                                                      $"查询编码:{item.SingleId}", $"修改单择题:{item.Content}!");

                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.LogPricipalOperations.Add(log);

                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = true,
                        title = "消息提示",
                        message = "修改成功!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "不存在此题目"
                    }));
                }
            }
            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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Пример #29
0
 public async Task <int> LoggerAsync(LogPricipalOperation operation)
 {
     _context.LogPricipalOperations.Add(operation);
     return(await _context.SaveChangesAsync());
 }
Пример #30
0
        /// <summary>
        /// 完成日志记录
        /// </summary>
        /// <param name="singleId"></param>
        /// <returns></returns>
        public IActionResult Delete([Required] int singleId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.QuestionBankManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无题库管理操作权限"
                    }));
                }

                #region 功能实现区域
                SingleChoices item = _context.SingleChoices.Find(singleId);
                if (item != null)
                {
                    SystemSetting setting = _config.LoadSystemSetting();
                    if (setting.LoginSetting.StudentLogin)
                    {
                        return(Json(new
                        {
                            isOk = false,
                            title = "信息提示",
                            message = "无法删除,当前系统打开了学生学习通道,在实验室安全考试期间无法删除任何考题!以免引起数据不正常!"
                        }));
                    }

                    LogPricipalOperation log = _logger.GetDefaultLogPricipalOperation(PrincpalOperationCode.SingleDelete,
                                                                                      $"查询编码:{item.SingleId}", $"删除单择题:{item.Content}!");

                    log.PrincpalOperationStatus = PrincpalOperationStatus.Success;
                    _context.LogPricipalOperations.Add(log);

                    _context.SingleChoices.Remove(item);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = true,
                        title = "信息提示",
                        message = "删除成功!"
                    }));
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }