示例#1
0
        public ActionResult Submit(MultipleChoice multipleChoice)
        {
            List <MultipleChoice> result     = (List <MultipleChoice>)Session["Result"];
            CaseAnalysis          resultCase = (CaseAnalysis)Session["ResultCase"];

            if (result == null)
            {
                result = new List <MultipleChoice>();
                result.Add(multipleChoice);
                Session["Result"] = result;
            }
            else
            {
                result.Add(multipleChoice);
            }

            if (resultCase == null)
            {
                resultCase        = new CaseAnalysis();
                resultCase.Topics = new List <MultipleChoice>();
                resultCase.Topics.Add(multipleChoice);
                Session["ResultCase"] = resultCase;
            }


            if (multipleChoice.CaseId != 0)
            {
                return(ListAnalysis());
            }
            return(List());
        }
示例#2
0
        /// <summary>
        /// 获得下一个单选
        /// </summary>
        /// <param name="multipleChoices"></param>
        /// <returns></returns>
        public MultipleChoice GetNextMultipleChoice(CaseAnalysis resultCase)
        {
            CaseAnalysis ca = db.CaseAnalysiss.Find(resultCase.Id);

            db.Entry(ca).Collection(x => x.Topics).Load();//手动读取List

            CaseAnalysis andlysis1 = db.CaseAnalysiss.Find(1);

            db.Entry(andlysis1).Collection(x => x.Topics).Load();//手动读取List

            if (resultCase.Topics.Count == ca.Topics.Count)
            {
                //判断是否答完
                List <CaseAnalysis> andlysis = db.CaseAnalysiss.OrderBy(e => e.Id).ToList();

                List <int> CaseIds = (List <int>)Session["CaseAnalysises"];
                if (CaseIds.Count >= andlysis.Count)
                {
                    MultipleChoice end = new MultipleChoice();
                    ViewBag.end = 1;
                    return(end);
                }
                return(null);
            }

            return(ca.Topics[resultCase.Topics.Count]);
            //Random rm = new Random();
            //MultipleChoice mc = ca.Topics[rm.Next(ca.Topics.Count)];//随机数最大值不能超过list的总数

            //if (resultCase.Topics.Contains(mc))
            //{
            //    return GetNextMultipleChoice(resultCase);
            //}
            //return mc;
        }
示例#3
0
        /// <summary>
        /// 获得下一个案例
        /// </summary>
        /// <returns></returns>
        public CaseAnalysis GetNextCaseAnalysis()
        {
            List <CaseAnalysis> andlysis = db.CaseAnalysiss.OrderBy(e => e.Cases).ToList();
            Random       rm = new Random();
            CaseAnalysis ga = andlysis[rm.Next(andlysis.Count)]; //随机数最大值不能超过list的总数

            db.Entry(ga).Collection(x => x.Topics).Load();       //手动读取List
            return(ga);
        }
        public ActionResult Details(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CaseAnalysis andlysis = db.CaseAnalysiss.Find(id);

            db.Entry(andlysis).Collection(x => x.Topics).Load();//手动读取List

            if (id == null)
            {
                return(HttpNotFound());
            }
            return(View(andlysis));
        }
示例#5
0
        public override ExprNode Validate(ExprValidationContext validationContext)
        {
            CaseAnalysis analysis = AnalyzeCase();

            _whenThenNodeList = new List <UniformPair <ExprEvaluator> >();
            foreach (UniformPair <ExprNode> pair in analysis.WhenThenNodeList)
            {
                if (!_isCase2)
                {
                    if (pair.First.ExprEvaluator.ReturnType.GetBoxedType() != typeof(bool?))
                    {
                        throw new ExprValidationException("Case node 'when' expressions must return a boolean value");
                    }
                }
                _whenThenNodeList.Add(new UniformPair <ExprEvaluator>(pair.First.ExprEvaluator, pair.Second.ExprEvaluator));
            }
            if (analysis.OptionalCompareExprNode != null)
            {
                _optionalCompareExprNode = analysis.OptionalCompareExprNode.ExprEvaluator;
            }
            if (analysis.OptionalElseExprNode != null)
            {
                _optionalElseExprNode = analysis.OptionalElseExprNode.ExprEvaluator;
            }

            if (_isCase2)
            {
                ValidateCaseTwo();
            }

            // Determine type of each result (then-node and else node) child node expression
            IList <Type> childTypes = new List <Type>();
            IList <IDictionary <String, Object> > childMapTypes = new List <IDictionary <String, Object> >();

            foreach (UniformPair <ExprEvaluator> pair in _whenThenNodeList)
            {
                if (pair.Second is ExprEvaluatorTypableReturn)
                {
                    var typableReturn = (ExprEvaluatorTypableReturn)pair.Second;
                    var rowProps      = typableReturn.RowProperties;
                    if (rowProps != null)
                    {
                        childMapTypes.Add(rowProps);
                        continue;
                    }
                }
                childTypes.Add(pair.Second.ReturnType);
            }
            if (_optionalElseExprNode != null)
            {
                if (_optionalElseExprNode is ExprEvaluatorTypableReturn)
                {
                    var typableReturn = (ExprEvaluatorTypableReturn)_optionalElseExprNode;
                    var rowProps      = typableReturn.RowProperties;
                    if (rowProps != null)
                    {
                        childMapTypes.Add(rowProps);
                    }
                    else
                    {
                        childTypes.Add(_optionalElseExprNode.ReturnType);
                    }
                }
                else
                {
                    childTypes.Add(_optionalElseExprNode.ReturnType);
                }
            }

            if (!childMapTypes.IsEmpty() && !childTypes.IsEmpty())
            {
                String message = "Case node 'when' expressions require that all results either return a single value or a Map-type (new-operator) value";
                String check;
                int    count = -1;
                foreach (UniformPair <ExprEvaluator> pair in _whenThenNodeList)
                {
                    count++;
                    if (pair.Second.ReturnType != typeof(DataMap) && pair.Second.ReturnType != null)
                    {
                        check = ", check when-condition number " + count;
                        throw new ExprValidationException(message + check);
                    }
                }
                if (_optionalElseExprNode != null)
                {
                    if (_optionalElseExprNode.ReturnType != typeof(DataMap) && _optionalElseExprNode.ReturnType != null)
                    {
                        check = ", check the else-condition";
                        throw new ExprValidationException(message + check);
                    }
                }
                throw new ExprValidationException(message);
            }

            if (childMapTypes.IsEmpty())
            {
                // Determine common denominator type
                try
                {
                    _resultType = TypeHelper.GetCommonCoercionType(childTypes);
                    if (_resultType.IsNumeric())
                    {
                        _isNumericResult = true;
                    }
                }
                catch (CoercionException ex)
                {
                    throw new ExprValidationException("Implicit conversion not allowed: " + ex.Message);
                }
            }
            else
            {
                _mapResultType = childMapTypes[0];
                for (int i = 1; i < childMapTypes.Count; i++)
                {
                    DataMap other         = childMapTypes[i];
                    String  messageEquals = MapEventType.IsDeepEqualsProperties("Case-when number " + i, _mapResultType, other);
                    if (messageEquals != null)
                    {
                        throw new ExprValidationException("Incompatible case-when return types by new-operator in case-when number " + i + ": " + messageEquals);
                    }
                }
            }

            return(null);
        }
示例#6
0
        public ActionResult ListAnalysis()
        {
            CaseAnalysis resultCase = (CaseAnalysis)Session["ResultCase"];

            List <int> CaseIds = (List <int>)Session["CaseAnalysises"];

            if (CaseIds == null)
            {
                CaseIds = new List <int>();
            }
            MultipleChoice mc = null;

            if (resultCase != null)
            {
                mc = GetNextMultipleChoice(resultCase);
                if (mc == null)
                {
                    Session["ResultCase"] = null;
                    return(ListAnalysis());
                }
                mc.CaseId = resultCase.Id;
                resultCase.Topics.Add(mc);
            }
            else
            {
                CaseAnalysis result = GetNextCaseAnalysis();

                CaseAnalysis aa = new CaseAnalysis();
                aa.Topics = new List <MultipleChoice>();
                aa.Id     = result.Id;
                aa.Cases  = result.Cases;
                mc        = GetNextMultipleChoice(aa);

                if (CaseIds.Contains(result.Id))
                {
                    return(ListAnalysis());
                }
                else
                {
                    aa.Topics.Add(mc);
                    CaseIds.Add(result.Id);
                    mc.CaseId = result.Id;
                    Session["CaseAnalysises"] = CaseIds;
                }
                resultCase = aa;
            }



            //显示分类和答题数
            List <MultipleChoice> results = (List <MultipleChoice>)Session["Result"];
            List <MultipleChoice> success = new List <MultipleChoice>();

            if (results != null)
            {
                foreach (MultipleChoice maac in results)
                {
                    if (maac.Answer == maac.Result)
                    {
                        success.Add(maac);
                    }
                }
            }
            string amount = "答题总数:" + (results != null ? results.Count : 0).ToString() + "题";
            string score  = "答题总分:" + (success != null ? success.Count * 2 : 0).ToString() + "分" + "(答对一题目得2分)";

            ViewBag.amount = amount;
            ViewBag.score  = score;


            //这里处理是第一是还是其它题
            if (resultCase.Topics.Count == 1)
            {
                ViewBag.First = true;
            }
            else
            {
                ViewBag.First = false;
            }

            Session["ResultCase"] = resultCase;
            CaseAnalysis resultCase1 = (CaseAnalysis)Session["ResultCase"];

            ViewBag.anli = resultCase1.Cases;
            return(View("List", mc));
        }