Exemplo n.º 1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ExamId,UserId,Score,WriteDate")] ExamResults examResult)
        {
            if (id != examResult.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(examResult);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ExamResultExists(examResult.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ExamId"] = new SelectList(_context.Exams, "ExamId", "ExamName", examResult.ExamId);
            ViewData["UserId"] = new SelectList(_context.Users, "UserId", "Password", examResult.UserId);
            return(View(examResult));
        }
Exemplo n.º 2
0
        public ActionResult ExamResults()
        {
            List <ExamResults> listresults = new List <ExamResults>();

            ExamResults Result1 = new ExamResults()
            {
                CourseID   = "ISM6225",
                CourseName = "Distributed Information System",
                Mark       = "A-"
            };

            listresults.Add(Result1);

            ExamResults Result2 = new ExamResults()
            {
                CourseID   = "ISM6155",
                CourseName = "Enterprise Information System",
                Mark       = "A+"
            };

            listresults.Add(Result2);

            ExamResults Result3 = new ExamResults()
            {
                CourseID   = "ISM6218",
                CourseName = "Advanced Database Management",
                Mark       = "A"
            };

            listresults.Add(Result3);

            return(View(listresults));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PutExamResults([FromRoute] int id, [FromBody] ExamResults examResults)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != examResults.Id)
            {
                return(BadRequest());
            }

            _context.Entry(examResults).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!ExamResultsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 4
0
        public void TestExcelExporting(string path, string groupName, int mark, string subject, string studentFullName)
        {
            ExamResults examResults = new ExamResults()
            {
                ExamDate         = DateTime.Now,
                GroupName        = groupName,
                Mark             = mark,
                SubjectName      = subject,
                SessionStartDate = DateTime.Now,
                SessionEndDate   = DateTime.Now,
                StudentFullName  = studentFullName
            };

            var examContext = _context.GetExamResultsDataLayer();

            _context.SetFilePath(path);

            examContext.CreateSheet();

            examContext.Insert(examResults);

            Assert.IsTrue(File.Exists(path));

            File.Delete(path);
        }
Exemplo n.º 5
0
        public ExamResults SubmitExam(int examId)
        {
            var currentUser = _securityManager.GetOrCreateUserAccount();
            var exam        = _questionDataAccess.GetExam(examId, true);

            if (currentUser.UserAccountID != exam.UserAccount.UserAccountID)
            {
                throw new DataException("The user is not authorised to view this exam");
            }

            var results = new ExamResults
            {
                ExamID            = examId,
                QuestionResults   = exam.Quiz.Questions.Select(q => this.MarkQuestion(q, exam.Answers)),
                NumberOfQuestions = exam.Quiz.Questions.Count()
            };

            results.NumberOfCorrectAnswers = results.QuestionResults.Count(q => q.WasCorrect);

            exam.EndDate = _timeManager.GetNow();
            exam.Score   = results.NumberOfCorrectAnswers;
            _questionDataAccess.UpdateExam(exam);

            return(results);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> PostExamResults([FromBody] ExamResults examResults)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.ExamResults.Add(examResults);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetExamResults", new { id = examResults.Id }, examResults));
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Create([Bind("Id,ExamId,UserId,Score,WriteDate")] ExamResults examResult)
        {
            if (ModelState.IsValid)
            {
                _context.Add(examResult);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ExamId"] = new SelectList(_context.Exams, "ExamId", "ExamName", examResult.ExamId);
            ViewData["UserId"] = new SelectList(_context.Users, "UserId", "Password", examResult.UserId);
            return(View(examResult));
        }
        /// <summary>
        /// 更新缓存
        /// </summary>
        /// <param name="exr">答题内容</param>
        /// <param name="expires"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public string Update(ExamResults exr, int expires, string uid)
        {
            QuestionsCache_Item qci = GetCache(uid);

            if (qci != null)
            {
                if (!string.IsNullOrWhiteSpace(uid))
                {
                    qci.UID = uid;
                }
                if (expires > 0)
                {
                    qci.Expires = expires;
                }
                if (exr != null)
                {
                    qci.Result = exr;
                }
            }
            else
            {
                qci = new QuestionsCache_Item();
                if (expires > 0)
                {
                    qci.Expires = expires;
                }
                if (exr != null)
                {
                    qci.Result = exr;
                }
                qci.UID = uid;
                this.list.Add(qci);
            }
            //如果交卷
            if (exr.Exr_IsSubmit && !exr.Exr_IsCalc)
            {
                qci.Calculate();
            }
            return(qci.UID);
        }
Exemplo n.º 9
0
        private static void SeedExamResults(PitalicaDbContext _pitalicaDbContext)
        {
            var examResults = new List <ExamResults>();

            /*for (int i = 0; i < 4; i++)
             * {*/
            var examResults1 = new ExamResults
            {
                ExamId = 1,
                UserId = 2 + 1,
                Score  = "10"
            };

            /*
             * var examResults2 = new ExamResults
             * {
             *  ExamId = i,
             *  UserId = i + 2,
             *  Score = "20"
             *
             * };
             *
             * var examResults3 = new ExamResults
             * {
             *  ExamId = i,
             *  UserId = i + 3,
             *  Score = "30"
             *
             * };*/

            examResults.Add(examResults1);
            //examResults.Add(examResults2);
            //examResults.Add(examResults3);
            //}

            _pitalicaDbContext.ExamResults.AddRange(examResults);

            _pitalicaDbContext.SaveChanges();
        }
 public void Update(ExamResults examResult)
 {
     _examResultsDAL.Update(examResult);
 }
 public void Add(ExamResults examResult)
 {
     _examResultsDAL.Add(examResult);
 }
Exemplo n.º 12
0
        /// <summary>
        /// 显示做题结果
        /// </summary>
        /// <param name="busId"></param>
        /// <param name="resultId"></param>
        /// <param name="stuId"></param>
        /// <returns></returns>
        public dynamic GetPracticeResult(int busId, int resultId, string stuId)
        {
            ExamResults Results = new ExamResults();

            Results.List = new List <Question>();
            Results.List = SqlMapper.QueryForList <Question>("GetPracticeResult", new { busId, resultId, stuId }).OrderBy(x => x.QuestionType_ID).ThenBy(x => x.ID).ToList();
            W_DoExamResult theResult = Orm.Single <W_DoExamResult>(x => x.ID == resultId);

            Results.TotalTime = theResult != null ? (theResult.EndTime - theResult.BeginTime).TotalSeconds : 0.00;
            if (Results.List.Count > 0)
            {
                List <ResultSummary>  list     = new List <ResultSummary>();
                List <W_QuestionNote> NoteList = Orm.Select <W_QuestionNote>(x => x.StuID == stuId).ToList();//题目笔记列表
                foreach (Question q in Results.List)
                {
                    ResultSummary temp = list.FirstOrDefault(x => x.TypeID == q.QuestionType_ID);
                    if (temp == null)
                    {
                        temp             = new ResultSummary();
                        temp.TypeID      = q.QuestionType_ID;
                        temp.TypeName    = q.QuestionType_Name;
                        temp.TotalCounts = 1;
                        if (!string.IsNullOrEmpty(q.MyAnswer))
                        {
                            temp.AlreadyCounts = 1;
                            if (q.Judge == 1)
                            {
                                temp.CorrectCounts = 1;
                            }
                            else
                            {
                                temp.ErrorCounts = 1;
                            }
                        }
                        temp.YetCounts   = temp.TotalCounts - temp.AlreadyCounts;
                        temp.CorrectRate = ((float)temp.CorrectCounts / temp.TotalCounts * 100).ToString("f2");
                        list.Add(temp);
                    }
                    else
                    {
                        temp.TypeID       = q.QuestionType_ID;
                        temp.TypeName     = q.QuestionType_Name;
                        temp.TotalCounts += 1;
                        if (!string.IsNullOrEmpty(q.MyAnswer))
                        {
                            temp.AlreadyCounts += 1;
                            if (q.Judge == 1)
                            {
                                temp.CorrectCounts += 1;
                            }
                            else
                            {
                                temp.ErrorCounts += 1;
                            }
                        }
                        temp.YetCounts   = temp.TotalCounts - temp.AlreadyCounts;
                        temp.CorrectRate = ((float)temp.CorrectCounts / temp.TotalCounts * 100).ToString("f2");
                    }
                    q.NoteList = NoteList != null?NoteList.Where(x => x.Question_ID == q.ID).ToList() : null;
                }
                Results.Result = list;
            }
            return(Results);
        }
Exemplo n.º 13
0
        /// <summary>
        /// 初始化常用数据
        /// </summary>
        /// <returns>如果有错误,返回-1,如果考试结束或不存在,则返回0;正常返回1</returns>
        private int initData()
        {
            //如果为空,则返回-1,表示错误
            if (result == "")
            {
                return(-1);
            }
            resXml.LoadXml(result, false);
            XmlNode xn = resXml.SelectSingleNode("results");
            //试卷id,考试id
            int tpid;

            int.TryParse(xn.Attributes["tpid"].Value, out tpid);
            int examid;

            int.TryParse(xn.Attributes["examid"].Value, out examid);
            //考试结束时间
            long lover;

            long.TryParse(xn.Attributes["overtime"].Value, out lover);
            lover = lover * 10000;
            DateTime dtStart  = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            TimeSpan toNow    = new TimeSpan(lover);
            DateTime overTime = dtStart.Add(toNow); //得到转换后的时间
            //学生Id,学生名称
            int stid;

            int.TryParse(xn.Attributes["stid"].Value, out stid);
            string stname = xn.Attributes["stname"].Value.ToString();
            //学生性别,分组,身份证号
            int stsex;

            int.TryParse(xn.Attributes["stsex"].Value, out stsex);
            int stsid;

            int.TryParse(xn.Attributes["stsid"].Value, out stsid);
            string stcardid = xn.Attributes["stcardid"].Value.ToString();
            //学科Id,学科名称
            int sbjid;

            int.TryParse(xn.Attributes["sbjid"].Value, out sbjid);
            string sbjname = xn.Attributes["sbjname"].Value.ToString();
            //UID与考试主题
            string uid   = xn.Attributes["uid"].Value.ToString();
            string theme = xn.Attributes["theme"].Value.ToString();
            //提交方式,1为自动提交,2为交卷
            int patter = Convert.ToInt32(xn.Attributes["patter"].Value);

            //
            Song.Entities.Examination exam = Business.Do <IExamination>().ExamSingle(examid);
            //如果考试不存在
            if (exam == null)
            {
                return(0);
            }
            //如果考试已经结束
            int span = (int)exam.Exam_Span;

            //if (DateTime.Now > ((DateTime)exam.Exam_Date).AddMinutes(span + 5)) return 0;
            try
            {
                Song.Entities.ExamResults exr = new ExamResults();
                exr.Exr_IsSubmit    = patter == 2;
                exr.Exam_ID         = examid;
                exr.Exam_Name       = exam.Exam_Name;
                exr.Tp_Id           = tpid;
                exr.Ac_ID           = stid;
                exr.Ac_Name         = stname;
                exr.Sts_ID          = stsid;
                exr.Ac_Sex          = stsex;
                exr.Ac_IDCardNumber = stcardid;
                exr.Sbj_ID          = sbjid;
                exr.Sbj_Name        = sbjname;
                exr.Exr_IP          = WeiSha.Common.Browser.IP;
                exr.Exr_Mac         = WeiSha.Common.Request.UniqueID(); //原本是网卡的mac地址,此处不再记录
                exr.Exr_Results     = result;
                exr.Exam_UID        = uid;
                exr.Exam_Title      = theme;
                exr.Exr_IsSubmit    = patter == 2;
                if (exr.Exr_IsSubmit)
                {
                    exr.Exr_SubmitTime = DateTime.Now;
                }
                exr.Exr_OverTime = overTime;
                exr.Exr_CrtTime  = DateTime.Now;
                exr.Exr_LastTime = DateTime.Now;
                //Business.Do<IExamination>().ResultSubmit(exr);
                string cacheUid = string.Format("ExamResults:{0}-{1}-{2}", examid, tpid, stid);    //缓存的uid
                Business.Do <IQuestions>().CacheUpdate(exr, -1, cacheUid);
                return(1);
            }
            catch
            {
                return(0);
            }
        }