Esempio n. 1
0
        public IActionResult Index()
        {
            LoginUserModel user      = _analysis.GetLoginUserModel(HttpContext);
            Principal      principal = _context.Principals.Find(user.UserId);

            if (principal != null)
            {
                ViewBag.reExam =
                    _context.ApplicationForReExaminations.Count(a => a.ApplicationStatus == ApplicationStatus.Submit);
                ViewBag.join =
                    _context.ApplicationJoinTheExaminations.Count(a => a.ApplicationStatus == ApplicationStatus.Submit);

                ViewBag.moduleCount     = _context.Modules.Count();
                ViewBag.instituteCount  = _context.Institute.Count();
                ViewBag.professionCount = _context.Professions.Count();

                ViewBag.adminCount    = _context.Principals.Count();
                ViewBag.underCount    = _context.Student.Count(s => s.StudentType == StudentType.UnderGraduate);
                ViewBag.postCount     = _context.Student.Count(s => s.StudentType == StudentType.PostGraduate);
                ViewBag.courseCount   = _context.Cources.Count();
                ViewBag.resourceCount = _context.Resources.Count();
                return(View(principal));
            }
            else
            {
                RedirectToAction("Wrong", "Error", new { data = "请从新登录系统!" });
            }

            return(View());
        }
Esempio n. 2
0
        public LogPricipalOperation GetDefaultLogPricipalOperation(PrincpalOperationCode code, String target, String content)
        {
            StringBuilder builder = new StringBuilder("p4:");

            builder.Append(_accessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString());
            builder.Append("/p6");
            builder.Append(_accessor.HttpContext.Connection.RemoteIpAddress.MapToIPv6().ToString());
            return(new LogPricipalOperation
            {
                AddTime = DateTime.Now,
                OperationIp = builder.ToString(),
                PrincpalOperationCode = code,
                PrincipalId = _analysis.GetLoginUserModel(_accessor.HttpContext).UserId,
                PrincpalOperationStatus = PrincpalOperationStatus.Fail,
                PrincpalOperationName = target,
                PrincpalOperationContent = content
            });
        }
Esempio n. 3
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;
            }
        }
Esempio n. 4
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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Esempio n. 5
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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }
Esempio n. 6
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 = "参数错误,传递了不符合规定的参数"
                }));
            }
        }