예제 #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
        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
        public IActionResult LoadSetting([Required] int moduleId)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.SystemSettingManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无系统设置操作权限"
                    }));
                }
                Module module = _context.Modules.FirstOrDefault(m => m.ModuleId == moduleId);
                if (module == null)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "模块不存在或者已经删除"
                    }));
                }
                if (System.IO.File.Exists(Path.GetFullPath($@"{_hosting.ContentRootPath}/SettingConfig.json")))
                {
                    try
                    {
                        using (var stream = new FileStream(Path.GetFullPath($@"{_hosting.ContentRootPath}/SettingConfig.json"),
                                                           FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
                        {
                            using (StreamReader reader = new StreamReader(stream))
                            {
                                String        json    = reader.ReadToEnd();
                                SystemSetting setting = JsonConvert.DeserializeObject <SystemSetting>(json);
                                Boolean       isOk    = setting.ExamModuleSettings.TryGetValue(moduleId, out var _moduleSetting);

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

                                    return(Json(new
                                    {
                                        moduleSetting = msetting,
                                        isOk = true,
                                        title = "提示",
                                        message = "加载成功!"
                                    }));
                                }
                            };
                        };
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e);
                        throw;
                    }
                }
                else
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "严重错误提示!",
                        message = "系统配置文件丢失...请联系系统维护人员!及时处理..."
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    title = "错误提示",
                    message = "参数错误,模块信息插入失败"
                }));
            }
        }
예제 #4
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;
            }
        }
예제 #5
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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
예제 #6
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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
예제 #7
0
        public IActionResult List([Required] int cId, [Required] int status, [Required] int type)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无题库管理操作权限"
                    }));
                }

                String sql = "select * from Resources where ResourceId > 0";

                if (cId != -1)
                {
                    sql += $" and CourceId = {cId}";
                }

                if (status != -1)
                {
                    sql += $" and ResourceStatus = {status}";
                }

                if (type != -1)
                {
                    sql += $" and ResourceType = {type}";
                }

                var resources = _context.Resources.FromSql(sql).Include("Cource").Select(r => new
                {
                    resourceId    = r.ResourceId,
                    name          = r.Name,
                    lengthOfStudy = r.LengthOfStudy,
                    description   = r.Description,
                    cource        = r.Cource,
                    courceId      = r.CourceId,
                    type          = r.ResourceType == ResourceType.Link?"链接文件":"视频文件",
                    status        = r.ResourceStatus == ResourceStatus.Normal ? "未使用" : "使用中"
                }).ToList();

                return(Json(new
                {
                    isOk = true,
                    title = "消息提示",
                    items = resources,
                    message = "加载成功"
                }));
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
예제 #8
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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
예제 #9
0
        public IActionResult Create([Required] String id, [Required] String jobId, [Required] String name,
                                    [Required] String phone, [Required] String pwd)
        {
            if (ModelState.IsValid)
            {
                PrincipalConfig principalConfig = _analysis.GetLoginUserConfig(HttpContext);
                if (!principalConfig.Power.SystemManager)
                {
                    if (!_context.Principals.Any(p => p.PrincipalId == principalConfig.PrincipalId && p.PrincipalStatus == PrincipalStatus.Super))
                    {
                        return(Json(new
                        {
                            isOk = false,
                            message = "你并无系统管理操作权限"
                        }));
                    }
                }
                if (_context.Student.Any(stu => stu.StudentId == id))
                {
                    return(Json(new
                    {
                        isOk = false,
                        message = $"编号:{id}是已经存在的学号!无法使用!"
                    }));
                }

                if (id.Length == 12 || id.Length == 10)
                {
                    return(Json(new
                    {
                        isOk = false,
                        message = $"编号:{id}属于学号范围!长度不能为10位或者12位 无法使用!"
                    }));
                }

                if (_context.Principals.Any(admin => admin.PrincipalId == id || admin.JobNumber == jobId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        message = $"编号:{id}或者工号{jobId} 已经使用!"
                    }));
                }
                else
                {
                    Principal principal = new Principal
                    {
                        PrincipalId     = id,
                        JobNumber       = jobId,
                        Name            = name,
                        Phone           = phone,
                        PrincipalStatus = PrincipalStatus.Normal,
                        PrincipalConfig = $"{id}.json"
                    };
                    String password = _encryption.EncodeByRsa(_encryption.EncodeByMd5(_encryption.EncodeByMd5(pwd)));
                    principal.Password = password;
                    _context.Principals.Add(principal);

                    int result = _context.SaveChanges();

                    if (result == 1)
                    {
                        //配置权限
                        PrincipalConfig config = new PrincipalConfig
                        {
                            SettingTime = DateTime.Now, PrincipalId = id, Power = new Power()
                        };

                        using (var stream = new FileStream(
                                   Path.GetFullPath($@"{_hosting.ContentRootPath}/JsonConfig/{id}.json"), FileMode.Create,
                                   FileAccess.Write, FileShare.None))
                        {
                            using (var writer = new StreamWriter(stream))
                            {
                                JsonSerializer serializer = JsonSerializer.Create(new JsonSerializerSettings());
                                String         jsonResult = JsonConvert.SerializeObject(config, Formatting.Indented);
                                writer.Write(jsonResult);
                            }
                        }

                        return(Json(new
                        {
                            isOk = true,
                            message = "信息插入成功"
                        }));
                    }
                    else
                    {
                        return(Json(new
                        {
                            isOk = false,
                            message = "信息插入失败"
                        }));
                    }
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    message = $"参数错误!输入了不合规范的参数。 "
                }));
            }
        }
예제 #10
0
        public IActionResult Create([Required] String name, [Required] int moduleId, [Required] float mark, [Required] String description)
        {
            if (ModelState.IsValid)
            {
                if (!_analysis.GetLoginUserConfig(HttpContext).Power.CourcesManager)
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "你并无课程管理操作权限"
                    }));
                }

                if (!_context.Modules.Any(m => m.ModuleId == moduleId))
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "模块不存在,或者已经被删除"
                    }));
                }

                if (_context.Cources.Any(c => c.Name == name))
                {
                    return(Json(new
                    {
                        isOk = false,
                        title = "错误提示",
                        message = "此课程已经存在了"
                    }));
                }
                else
                {
                    Cource cource = new Cource
                    {
                        Name         = name.Trim(),
                        AddTime      = DateTime.Now,
                        CourceStatus = CourceStatus.Normal,
                        Credit       = mark,
                        Introduction = description.Trim(),
                        ModuleId     = moduleId
                    };
                    _context.Cources.Add(cource);
                    _context.SaveChanges();
                    return(Json(new
                    {
                        isOk = false,
                        title = "消息提示",
                        message = "添加成功!"
                    }));
                }
            }
            else
            {
                return(Json(new
                {
                    isOk = false,
                    error = _analysis.ModelStateDictionaryError(ModelState),
                    title = "错误提示",
                    message = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
예제 #11
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 = "参数错误"
                }));
            }
        }
예제 #12
0
        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 = "参数错误!传入了错误的信息! "
                }));
            }
        }