public int CheckQuestion(MTest_MainInfo Current_Test_MainInfo, MReaderChoice_MainInfo ReaderChoice_MainInfo)
        {
            int CorrectAnswerCount = 0;

            if (Current_Test_MainInfo.Questions_ChoosingAnswerFromList.Any())
            {
                foreach (MQuestion_ChoosingAnswerFromList CurrentQuestions_ChoosingAnswerFromList in Current_Test_MainInfo.Questions_ChoosingAnswerFromList)
                {
                    IEnumerable <int> CorrectAnswerId =
                        CurrentQuestions_ChoosingAnswerFromList.AnswerVariants
                        .Where(c => c.IsCorrectAnswer)
                        .Select(c => c.Id)
                        .OrderBy(c => c);

                    IEnumerable <int> ReaderAnswerId =
                        ReaderChoice_MainInfo.ReaderChoices_ChoosingAnswerFromList
                        .Where(c => c.Question_ChoosingAnswerFromList_Id == CurrentQuestions_ChoosingAnswerFromList.Id)
                        .Select(c => c.AnswerVariant_ChoosingAnswerFromList_Id)
                        .OrderBy(c => c);

                    if (CorrectAnswerId.SequenceEqual(ReaderAnswerId))
                    {
                        CorrectAnswerCount++;
                    }
                }
            }

            return
                (CorrectAnswerCount);
        }
Пример #2
0
        public int CheckQuestion(MTest_MainInfo Current_Test_MainInfo, MReaderChoice_MainInfo ReaderChoice_MainInfo)
        {
            int CorrectAnswerCount = 0;

            if (ReaderChoice_MainInfo.ReaderChoices_SetOrder != null)
            {
                foreach (MQuestion_SetOrder CurrentQuestions_SetOrder in Current_Test_MainInfo.Questions_SetOrder)
                {
                    IEnumerable <int> CorrectAnswerId =
                        CurrentQuestions_SetOrder.AnswerVariants
                        .Select(c => c.CorrectOrderKey);

                    IEnumerable <int> ReaderAnswerId =
                        ReaderChoice_MainInfo.ReaderChoices_SetOrder
                        .Where(c => c.Question_SetOrderDb_Id == CurrentQuestions_SetOrder.Id)
                        .Select(c => c.AnswerVariant_SetOrderDb_Id);

                    if (CorrectAnswerId.SequenceEqual(ReaderAnswerId))
                    {
                        CorrectAnswerCount++;
                    }
                }
            }

            return
                (CorrectAnswerCount);
        }
Пример #3
0
        public MResultRequest <MTest_MainInfo> Add(string User_TestAuthor_Id, MTest_MainInfo Test_MainInfo)
        {
            try
            {
                MTest_MainInfoDb Test_MainInfoDb =
                    _mapper.Map <MTest_MainInfoDb>(Test_MainInfo);

                Test_MainInfoDb.User_TestAuthorDb_Id = User_TestAuthor_Id;

                _context.Set <MTest_MainInfoDb>().Add(Test_MainInfoDb);

                _context.SaveChanges();

                return
                    (MResultRequest <MTest_MainInfo>
                     .Ok(_mapper.Map <MTest_MainInfo>(Test_MainInfoDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return
                    ((MResultRequest <MTest_MainInfo>) MResultRequest <MTest_MainInfo> .Fail <MTest_MainInfo>($"Cannot save model. {e.Message}"));
            }
            catch (DbUpdateException e)
            {
                return
                    ((MResultRequest <MTest_MainInfo>) MResultRequest <MTest_MainInfo> .Fail <MTest_MainInfo>($"Cannot save model. Duplicate field. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return
                    ((MResultRequest <MTest_MainInfo>) MResultRequest <MTest_MainInfo> .Fail <MTest_MainInfo>($"Invalid model. {e.Message}"));
            }
        }
Пример #4
0
        public IHttpActionResult UpdateTest([FromBody] MTest_MainInfo Test_MainInfo)
        {
            var result = _validator.Validate(Test_MainInfo);

            if (!result.IsValid)
            {
                return
                    (BadRequest(ModelState));
            }

            var Rez =
                _service_Test.Update("5012f850-9c59-4fd9-9e50-4d93ecac03fb", Test_MainInfo);

            return(Ok(Test_MainInfo.Name));
        }
Пример #5
0
        public IHttpActionResult AddNewTest([FromBody] MTest_MainInfo Test_MainInfo)
        {
            var result = _validator.Validate(Test_MainInfo);

            if (!result.IsValid)
            {
                return
                    (BadRequest(result.Errors.Select(_ => _.ErrorMessage).Aggregate((a, b) => $"{a} {b}")));
            }

            var Rez =
                _service_Test.Add("5012f850-9c59-4fd9-9e50-4d93ecac03fb", Test_MainInfo);

            return
                (Ok(Rez.Data.Id));
        }
Пример #6
0
        public void InsertNewDataFromTest(string Name)
        {
            Validator_Test_MainInfo VTest_MainInfo = new Validator_Test_MainInfo();

            MTest_MainInfo Test_MainInfo = new MTest_MainInfo()
            {
                Name = Name
            };

            var Result = VTest_MainInfo.Validate(Test_MainInfo);

            if (Result.IsValid == false)
            {
                foreach (var fail in Result.Errors)
                {
                    Assert.Warn($"{fail.PropertyName} : {fail.ErrorMessage}");
                }
            }
        }
Пример #7
0
        // ------------ CheckCorrectAnswer

        public MResultRequest <string> CheckTestAsync(string User_TestReaderr_Id, MReaderChoice_MainInfo ReaderChoice_MainInfo)
        {
            try
            {
                MTest_MainInfo Current_Test_MainInfo =
                    GetById(ReaderChoice_MainInfo.Test_MainInfoDb_Id).Data;

                int NumberOfCorrectAnswer = 0;

                NumberOfCorrectAnswer +=
                    _service_Question_ChoosingAnswerFromList.CheckQuestion(Current_Test_MainInfo, ReaderChoice_MainInfo);

                NumberOfCorrectAnswer +=
                    _service_Question_SetOrder.CheckQuestion(Current_Test_MainInfo, ReaderChoice_MainInfo);

                int NumberOfAttempt = 1;

                if (_context.Set <MReaderChoice_MainInfoDb>().Any(c => c.Test_MainInfoDb_Id == ReaderChoice_MainInfo.Test_MainInfoDb_Id && c.User_TestReaderDb_Id == User_TestReaderr_Id))
                {
                    NumberOfAttempt =
                        _context.Set <MReaderChoice_MainInfoDb>()
                        .Where(c => c.Test_MainInfoDb_Id == ReaderChoice_MainInfo.Test_MainInfoDb_Id && c.User_TestReaderDb_Id == User_TestReaderr_Id)
                        .Select(c => c.NumberOfAttempt)
                        .Max() + 1;
                }

                ReaderChoice_MainInfo.User_TestReaderDb_Id = User_TestReaderr_Id;

                ReaderChoice_MainInfo.NumberOfAttempt = NumberOfAttempt;

                ReaderChoice_MainInfo.ResultTest =
                    $@"{NumberOfCorrectAnswer} из {((Current_Test_MainInfo.Questions_ChoosingAnswerFromList.Any()) ? Current_Test_MainInfo.Questions_ChoosingAnswerFromList.Count : 0)}";

                return
                    (MResultRequest <string> .Ok(ReaderChoice_MainInfo.ResultTest));
            }
            catch (Exception e)
            {
                return
                    ((MResultRequest <string>) MResultRequest <string> .Fail <string>(e.Message));
            }
        }
Пример #8
0
        public IHttpActionResult ResultTestStructure(int TestId)
        {
            MTest_MainInfo Test_MainInfo =
                _service_Test.GetById(TestId).Data;

            MReaderChoice_MainInfo ReaderChoice_MainInfo =
                new MReaderChoice_MainInfo()
            {
                Test_MainInfoDb_Id = Test_MainInfo.Id,
                ReaderChoices_ChoosingAnswerFromList = new List <MReaderChoice_ChoosingAnswerFromList>()
            };

            foreach (var x in Test_MainInfo.Questions_ChoosingAnswerFromList)
            {
                ReaderChoice_MainInfo.ReaderChoices_ChoosingAnswerFromList.Add(
                    new MReaderChoice_ChoosingAnswerFromList()
                {
                    Question_ChoosingAnswerFromList_Id = x.Id
                });
            }

            return
                (Json(ReaderChoice_MainInfo));
        }
Пример #9
0
        public void Update()
        {
            MTest_MainInfo TestData =
                new MTest_MainInfo()
            {
                Id   = 1,
                Name = "XXXXXXXXXXXXXXXXXXXXXXXX",
                Questions_ChoosingAnswerFromList =
                    new List <MQuestion_ChoosingAnswerFromList>()
                {
                    new MQuestion_ChoosingAnswerFromList()
                    {
                        QuestionText   = "Question_ChoosingAnswerFromListDb_Text_1",
                        SortKey        = 1,
                        AnswerVariants =
                            new List <MAnswerVariant_ChoosingAnswerFromList>()
                        {
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_1",
                                SortKey         = 1,
                                IsCorrectAnswer = false
                            },
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_2",
                                SortKey         = 2,
                                IsCorrectAnswer = false
                            },
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_3",
                                SortKey         = 3,
                                IsCorrectAnswer = true
                            }
                        }
                    }
                },
                Questions_SetOrder =
                    new List <MQuestion_SetOrder>()
                {
                    new MQuestion_SetOrder()
                    {
                        QuestionText   = "QuestionText_1",
                        SortKey        = 3,
                        AnswerVariants =
                            new List <MAnswerVariant_SetOrder>()
                        {
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_1",
                                SortKey         = 1,
                                CorrectOrderKey = 1
                            },
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_2",
                                SortKey         = 2,
                                CorrectOrderKey = 2
                            },
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_3",
                                SortKey         = 3,
                                CorrectOrderKey = 3
                            }
                        }
                    }
                }
            };

            var Test_MainInfo =
                _service_Test.Update(User_TestAuthor_Id, TestData);

            Assert.Warn($@"{Test_MainInfo.Data.Name}");
        }
Пример #10
0
        public void Check()
        {
            MTest_MainInfo TestData =
                new MTest_MainInfo()
            {
                Name = "Test_Name_1",
                Questions_ChoosingAnswerFromList =
                    new List <MQuestion_ChoosingAnswerFromList>()
                {
                    new MQuestion_ChoosingAnswerFromList()
                    {
                        QuestionText   = "Question_ChoosingAnswerFromListDb_Text_2",
                        SortKey        = 1,
                        AnswerVariants =
                            new List <MAnswerVariant_ChoosingAnswerFromList>()
                        {
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_1",
                                SortKey         = 1,
                                IsCorrectAnswer = false
                            },
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_2",
                                SortKey         = 2,
                                IsCorrectAnswer = false
                            },
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_3",
                                SortKey         = 3,
                                IsCorrectAnswer = true
                            }
                        }
                    }
                },
                Questions_SetOrder =
                    new List <MQuestion_SetOrder>()
                {
                    new MQuestion_SetOrder()
                    {
                        QuestionText   = "QuestionText_1",
                        SortKey        = 3,
                        AnswerVariants =
                            new List <MAnswerVariant_SetOrder>()
                        {
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_1",
                                SortKey         = 1,
                                CorrectOrderKey = 1
                            },
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_2",
                                SortKey         = 2,
                                CorrectOrderKey = 2
                            },
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_3",
                                SortKey         = 3,
                                CorrectOrderKey = 3
                            }
                        }
                    }
                }
            };

            var MainInfo =
                _service_Test.GetById(1);

            //Result<MTest_MainInfo> Test_MainInfo =
            //    _service_Test.CheckTest(MainInfo.Data, TestData);

            //var X = Test_MainInfo.Data.Questions_ChoosingAnswerFromList;

            var Row = "";

            //foreach (var Y in X)
            //{
            //    Row = Y.QuestionText;
            //}
            Assert.Warn($@"{Row}");
        }
Пример #11
0
        public async Task UpdateAsync()
        {
            MTest_MainInfo TestData =
                new MTest_MainInfo()
            {
                Id   = 1,
                Name = "Test_Name_2",
                Questions_ChoosingAnswerFromList =
                    new List <MQuestion_ChoosingAnswerFromList>()
                {
                    new MQuestion_ChoosingAnswerFromList()
                    {
                        QuestionText   = "Question_ChoosingAnswerFromListDb_Text_1",
                        SortKey        = 1,
                        AnswerVariants =
                            new List <MAnswerVariant_ChoosingAnswerFromList>()
                        {
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_1",
                                SortKey         = 1,
                                IsCorrectAnswer = false
                            },
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_2",
                                SortKey         = 2,
                                IsCorrectAnswer = false
                            },
                            new MAnswerVariant_ChoosingAnswerFromList()
                            {
                                AnswerText      = "AnswerText_3",
                                SortKey         = 3,
                                IsCorrectAnswer = true
                            }
                        }
                    }
                },
                Questions_SetOrder =
                    new List <MQuestion_SetOrder>()
                {
                    new MQuestion_SetOrder()
                    {
                        QuestionText   = "QuestionText_1",
                        SortKey        = 3,
                        AnswerVariants =
                            new List <MAnswerVariant_SetOrder>()
                        {
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_1",
                                SortKey         = 1,
                                CorrectOrderKey = 1
                            },
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_2",
                                SortKey         = 2,
                                CorrectOrderKey = 2
                            },
                            new MAnswerVariant_SetOrder()
                            {
                                AnswerText      = "AnswerText_3",
                                SortKey         = 3,
                                CorrectOrderKey = 3
                            }
                        }
                    }
                }
            };


            // var Test_MainInfo = await _service_Test.UpdateAsync(TestData);

            //Assert.Warn($@"{Test_MainInfo.Data.Name}");
        }
Пример #12
0
        public async Task <MResultRequest <MTest_MainInfo> > UpdateAsync(string User_TestAuthor_Id, MTest_MainInfo Test_MainInfo)
        {
            try
            {
                MTest_MainInfoDb Test_MainInfoDb =
                    _mapper.Map <MTest_MainInfoDb>(Test_MainInfo);

                Test_MainInfoDb.User_TestAuthorDb_Id = User_TestAuthor_Id;

                _context.Set <MTest_MainInfoDb>().Remove(
                    _context.Set <MTest_MainInfoDb>().Find(Test_MainInfo.Id));

                _context.Set <MTest_MainInfoDb>().Add(Test_MainInfoDb);

                await _context.SaveChangesAsync();

                return
                    (MResultRequest <MTest_MainInfo>
                     .Ok(_mapper.Map <MTest_MainInfo>(Test_MainInfoDb)));
            }
            catch (DbUpdateConcurrencyException e)
            {
                return
                    ((MResultRequest <MTest_MainInfo>) MResultRequest <MTest_MainInfo> .Fail <MTest_MainInfo>($"Cannot update model. {e.Message}"));
            }
            catch (DbUpdateException e)
            {
                return
                    ((MResultRequest <MTest_MainInfo>) MResultRequest <MTest_MainInfo> .Fail <MTest_MainInfo>($"Cannot update model. {e.Message}"));
            }
            catch (DbEntityValidationException e)
            {
                return
                    ((MResultRequest <MTest_MainInfo>) MResultRequest <MTest_MainInfo> .Fail <MTest_MainInfo>($"Cannot update model. {e.Message}"));
            }
        }