示例#1
0
 public ActionResult Test(StudentAnswersModel answers)
 {
     try
     {
         foreach (var answer in answers.ChosenAnswerIds)
         {
             var operation = _operationContextFactory.Create();
             var entity    = operation.DataContext.Query.OfEntities <StudentAnswer>().FirstOrDefault(e => e.TestResult.Id == answers.TestResultId && e.AnswerVariant.Id == answer);
             var Id        = entity == null ? 0 : entity.Id;
             _answerSaver.CreateOrUpdate(new StudentAnswerModel
             {
                 Id             = Id,
                 ChosenAnswerId = answer,
                 TestResultId   = answers.TestResultId
             });
             var testResult = operation.DataContext.Query.OfEntities <TestResult>().FirstOrDefault(e => e.Id == answers.TestResultId);
             testResult.Score = CalculateMarkForTheTest(testResult);
             operation.Complete();
         }
         return(Json(true));
     }
     catch (GraphLabsDbUpdateException e)
     {
         return(Json(false));
     }
 }
示例#2
0
        public List <StudentAnswersModel> GetStudentsAnswers(string studentListPath)
        {
            StudentsAnswersWithErrors.Clear();
            StudentListPath = studentListPath;
            results         = File.ReadAllLines(StudentListPath, Encoding.GetEncoding("iso-8859-9"));
            foreach (string listString in results)
            {
                string line = listString.Replace(" ", "");
                if (line == "")
                {
                    continue;
                }
                StudentAnswersModel studentAnswers = new StudentAnswersModel();
                StudentModel        model;
                int  regNo       = 0;
                bool isDuplicate = false;
                bool isRightName = true;
                if (Int32.TryParse(listString.Substring(24, 9), out regNo))
                {
                    model = GlobalConfig.Connection.GetStudent_ByRegNo(regNo);

                    if (model != null)
                    {
                        if (model.FirstName != NamesFixer(listString.Substring(0, 12)))
                        {
                            isRightName = false;
                            model       = null;
                        }
                    }
                    if (model != null)
                    {
                        var duplicate = StudentsAnswers.Find(s => s.Student.RegNo == model.RegNo);
                        if (duplicate != null)
                        {
                            model               = null;
                            isDuplicate         = true;
                            duplicate.ErrorType = "Duplicated Value, Fix RegNo";
                            StudentsAnswersWithErrors.Add(duplicate);
                            StudentsAnswers.Remove(duplicate);
                        }
                    }
                }
                else
                {
                    model = null;
                }
                if (model == null)
                {
                    if (isDuplicate)
                    {
                        studentAnswers.ErrorType = "Duplicated Value, Fix RegNo";
                    }
                    else if (!isRightName)
                    {
                        studentAnswers.ErrorType = "Wrong Name, Check Student List";
                    }
                    else
                    {
                        studentAnswers.ErrorType = "Student not found in DB";
                    }

                    studentAnswers.Student.FirstName = listString.Substring(0, 12);
                    studentAnswers.Student.LastName  = listString.Substring(12, 12);
                    studentAnswers.Student.RegNo     = regNo;
                    try
                    {
                        StudentDataModel t = new StudentDataModel
                        {
                            Group = listString.Substring(33, 1)
                        };
                        studentAnswers.Group.Name = listString.Substring(33, 1);
                        foreach (AnswerKeyModel answerKey in AnswerKeys)
                        {
                            if (answerKey.Group.Name == studentAnswers.Group.Name)
                            {
                                studentAnswers.AnswersList = listString.Substring(34, answerKey.QuestionCount);
                                break;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        studentAnswers.AnswersList = listString.Substring(34, listString.Length - 34);
                        studentAnswers.ErrorType   = "No Group";
                    }
                    StudentsAnswersWithErrors.Add(studentAnswers);
                }
                else
                {
                    try
                    {
                        studentAnswers.Student = model;
                        StudentDataModel t = new StudentDataModel
                        {
                            Group = listString.Substring(33, 1)
                        };
                        studentAnswers.Group.Name = listString.Substring(33, 1);
                        foreach (AnswerKeyModel answerKey in AnswerKeys)
                        {
                            if (answerKey.Group.Name == studentAnswers.Group.Name)
                            {
                                studentAnswers.AnswersList = listString.Substring(34, answerKey.QuestionCount);
                                break;
                            }
                        }
                        StudentsAnswers.Add(studentAnswers);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                        studentAnswers.AnswersList = listString.Substring(34, listString.Length - 34);
                        studentAnswers.ErrorType   = "No Group";
                        StudentsAnswersWithErrors.Add(studentAnswers);
                    }
                }
            }
            if (StudentsAnswersWithErrors.Count > 0)
            {
                return(null);
            }
            return(StudentsAnswers);
        }