public List <AnswerEntities> FileReading()
        {
            var entities = new List <AnswerEntities>();

            Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Answers5.csv");
            using (var reader = new StreamReader(@"Answers5.csv"))
            {
                if (!reader.EndOfStream)
                {
                    reader.ReadLine();
                }
                while (!reader.EndOfStream)
                {
                    var line      = reader.ReadLine();
                    var values    = line.Split(';');
                    var newEntity = new AnswerEntities()
                    {
                        PartitionKey = values[0],
                        RowKey       = values[1],
                        Name         = values[2],
                        Email        = values[3],
                        Answer1      = values[4],
                        Answer2      = values[5],
                        Answer3      = values[6],
                        Answer4      = values[7],
                        IsProcessed  = false
                    };

                    entities.Add(newEntity);
                }
            }
            return(entities);
        }
Ejemplo n.º 2
0
        public ProcessTestCompleteView CompleteTest()
        {
            CompleteDateTime = DateTime.UtcNow;
            ValidAnswers     = AnswerEntities.Count(a => a.AnswerEntity.Mark > 0);
            NumberAnswers    = AnswerEntities.Count();

            return(AsCompleteView());
        }
Ejemplo n.º 3
0
        public bool CreateAnswer(AnswerEntities entity)
        {
            Answer newItem = new Answer()
            {
                IdAnswer   = entity.IdAnswer,
                IdQuestion = entity.IdQuestion,
                IdChoices  = entity.IdChoices,
                IdAnsPaper = entity.IdAnsPaper
            };

            _unit.AnswerGenericType.Insert(newItem);
            return(true);
        }
Ejemplo n.º 4
0
        public bool UpdateAnswer(Guid id, AnswerEntities entity)
        {
            bool success    = false;
            var  updateItem = _unit.AnswerGenericType.GetByID(id);

            if (updateItem != null)
            {
                updateItem.IdQuestion = entity.IdQuestion;
                updateItem.IdAnsPaper = entity.IdAnsPaper;
                updateItem.IdChoices  = entity.IdChoices;

                _unit.AnswerGenericType.Update(updateItem);
                _unit.Save();
                success = true;
            }
            return(success);
        }
Ejemplo n.º 5
0
        public QuestionEntity TakeQuestion()
        {
            var answed = AnswerEntities.Select(a => a.AnswerEntity.QuestionId).ToList();

            if (TestEntity.FactoryMethod == TestFactoryMethod.Fixed)
            {
                return(TestEntity.ValidQuestionEntities.OrderBy(q => q.Position).FirstOrDefault(q => answed.Contains(q.QuestionId) == false)?.QuestionEntity);
            }
            else if (TestEntity.FactoryMethod == TestFactoryMethod.Randomize)
            {
                return(TestEntity.ValidQuestionEntities.FirstOrDefault(q => answed.Contains(q.QuestionId) == false)?.QuestionEntity);
            }
            else
            {
                throw new NotImplementedException();
            }
            return(null);
        }
Ejemplo n.º 6
0
        // insert

        public JsonResult <APIResultEntities <bool> > Post(AnswerEntities entity)
        {
            APIResultEntities <bool> rs = new APIResultEntities <bool>();

            try
            {
                _iAnswerServices.CreateAnswer(entity);
                rs.Data           = true;
                rs.ErrCode        = ErrorCodeEntites.Success;
                rs.ErrDescription = string.Format(Constants.MSG_INSERT_SUCCESS, Constants.Answer);
            }
            catch (Exception ex)
            {
                rs.Data           = false;
                rs.ErrCode        = ErrorCodeEntites.Fail;
                rs.ErrDescription = ex.ToString();
                throw new Exception(ex.ToString());
            }
            return(Json(rs));
        }
Ejemplo n.º 7
0
        private ExamPaper CreateDataSet(DataSet dsQuestion)
        {
            ExamPaper examPaper = new ExamPaper();
            List <QuestionEntities> questionEntitiesList = new List <QuestionEntities>();
            List <int> IdList = new List <int>();
            List <AnsweredQuestions> answeredQuestionsList = new List <AnsweredQuestions>();

            for (int i = 0; i < dsQuestion.Tables[0].Rows.Count; i++)
            {
                QuestionEntities questionEntities = new QuestionEntities();
                questionEntities.Id           = Convert.ToInt32(dsQuestion.Tables[0].Rows[i]["Id"].ToString());
                questionEntities.QuestionText = Convert.ToString(dsQuestion.Tables[0].Rows[i]["QuestionText"]);
                questionEntities.Marks        = Convert.ToDecimal(dsQuestion.Tables[0].Rows[i]["Marks"]);

                // IdList.Add(questionEntities.Id);

                DataTable dtAns = dsQuestion.Tables[1].AsEnumerable()
                                  .Where(r => r.Field <int>("QuestionId") == int.Parse(dsQuestion.Tables[0].Rows[i]["Id"].ToString())).CopyToDataTable();

                List <AnswerEntities> answerEntities = new List <AnswerEntities>();
                for (int j = 0; j < dtAns.Rows.Count; j++)
                {
                    AnswerEntities answerEntities1 = new AnswerEntities();
                    answerEntities1.ID            = Convert.ToInt32(dtAns.Rows[j]["Id"].ToString());
                    answerEntities1.AnswerText    = Convert.ToString(dtAns.Rows[j]["ChoiceText"]);
                    answerEntities1.QuestionID    = Convert.ToInt32(dtAns.Rows[j]["QuestionId"].ToString());
                    answerEntities1.IsRightAnswer = Convert.ToString(dtAns.Rows[j]["IsAnswer"].ToString());
                    answerEntities1.IsUserAnswer  = Convert.ToInt32(dtAns.Rows[j]["IsUserAnswer"].ToString());
                    answerEntities1.ChoiceID      = Convert.ToInt32(dtAns.Rows[j]["ChoiceId"].ToString());

                    if (dtAns.Rows[j]["IsUserAnswer"].ToString() == "1")
                    {
                        examPaper.UserAnswer = answerEntities1.ChoiceID.ToString();
                    }
                    //examPaper.RadioValue = dtAns.Rows[j]["IsUserAnswer"].ToString();



                    answerEntities.Add(answerEntities1);
                }

                questionEntities.AnswerEntities = answerEntities;
                questionEntitiesList.Add(questionEntities);
            }

            examPaper.QuestionEntities = questionEntitiesList;

            for (int i = 0; i < dsQuestion.Tables[3].Rows.Count; i++)
            {
                IdList.Add(int.Parse(dsQuestion.Tables[3].Rows[i]["Id"].ToString()));
            }

            examPaper.QuestionList = IdList;

            examPaper.QuestionCount = IdList.Count;

            List <int> qCnt = new List <int>();

            for (int k = 0; k < dsQuestion.Tables[2].Rows.Count; k++)
            {
                qCnt.Add(int.Parse(dsQuestion.Tables[2].Rows[k][0].ToString()));
            }

            examPaper.AnsweredQuestionList = qCnt;


            for (int l = 0; l < dsQuestion.Tables[4].Rows.Count; l++)
            {
                AnsweredQuestions aq = new AnsweredQuestions();

                aq.RowNo       = Convert.ToInt32(dsQuestion.Tables[4].Rows[l]["RowNo"].ToString());
                aq.QuestionId  = Convert.ToInt32(dsQuestion.Tables[4].Rows[l]["QuestionId"].ToString());
                aq.HasAnswered = Convert.ToInt32(dsQuestion.Tables[4].Rows[l]["HasAnswered"].ToString());

                answeredQuestionsList.Add(aq);
            }

            examPaper.AnsweredQuestions = answeredQuestionsList;

            return(examPaper);
        }