예제 #1
0
        public ActionResult <List <FeedbackOutputModel> > GetAllFeedbacks()
        {
            Mapper           mapper    = new Mapper();
            AuthorDataAccess feedbacks = new AuthorDataAccess();

            return(Ok(mapper.ConvertFeedbackDTOToFeedbackModelList(feedbacks.GetAllFeedbacks())));
        }
예제 #2
0
        public ActionResult <List <TestOutputModel> > GetTestsFoundByTag([FromBody] SearchTestByTagInputModel model)
        {
            bool               caseSwitch           = model.SwitchValue;
            Mapper             mapper               = new Mapper();
            AuthorDataAccess   search               = new AuthorDataAccess();
            FindBy4AndMoreTags searchBy4AndMoreTags = new FindBy4AndMoreTags();
            StringConverter    converter            = new StringConverter();

            if (caseSwitch)
            {
                if (converter.CreateArrayFromString(model.Tag).Length < 3)
                {
                    return(Json(mapper.ConvertTestDTOToTestModelList(search.GetTestsFoundByTagAnd(converter.CreateArrayFromString(model.Tag)))));
                }
                else
                {
                    return(Json(mapper.ConvertTestQuestionTagDTOToTestOutputListModel(searchBy4AndMoreTags.FindAnd(model.Tag))));
                }
            }
            else
            {
                if (converter.CreateArrayFromString(model.Tag).Length < 3)
                {
                    return(Json(mapper.ConvertTestDTOToTestModelList(search.GetTestsFoundByTagOr(converter.CreateArrayFromString(model.Tag)))));
                }
                else
                {
                    return(Json(mapper.ConvertTestQuestionTagDTOToTestOutputListModel(searchBy4AndMoreTags.FindOr(model.Tag))));
                }
            }
        }
예제 #3
0
        public ActionResult <int> PutTestById([FromBody] TestInputModel testModel)
        {
            Mapper           mapper = new Mapper();
            AuthorDataAccess tests  = new AuthorDataAccess();

            if (string.IsNullOrWhiteSpace(testModel.Name))
            {
                return(BadRequest("Введите название теста"));
            }
            if (string.IsNullOrWhiteSpace(testModel.DurationTime))
            {
                return(BadRequest("Введите время прохождения теста"));
            }
            if (testModel.QuestionNumber == null)
            {
                return(BadRequest("Введите количество вопросов в тесте"));
            }
            if (testModel.SuccessScore == null)
            {
                return(BadRequest("Введите минимальный балл для прохождения теста"));
            }
            TestDTO testDto = mapper.ConvertTestInputModelToTestDTO(testModel);

            return(Ok(tests.UpdateTestById(testDto)));
        }
예제 #4
0
        public ActionResult PutAnswerById(AnswerInputModel answerModel)
        {
            Mapper           mapper    = new Mapper();
            AnswerDTO        answerdto = mapper.ConvertAnswerInputModelToAnswerDTO(answerModel);
            AuthorDataAccess answers   = new AuthorDataAccess();
            var answer = answers.GetAnswerById(answerModel.ID);

            if (answer == null)
            {
                return(BadRequest("Ответа не существует"));
            }
            var question = answers.GetQuestionById(answerModel.QuestionID);

            if (question == null)
            {
                return(BadRequest("Вопроса не существует"));
            }
            if (string.IsNullOrWhiteSpace(answerModel.Value))
            {
                return(BadRequest("Введите ответ"));
            }
            if (answerModel.Correct == null)
            {
                return(BadRequest("Введите корректный ответ или нет"));
            }
            answers.UpdateAnswerById(answerdto);
            return(Ok("Успешно изменено!"));
        }
예제 #5
0
        public IActionResult PostFeedbackForTest([FromBody] FeedbackInputModel feedback)
        {
            AuthorDataAccess au = new AuthorDataAccess();
            AdminDataAccess  ad = new AdminDataAccess();

            var q = au.GetQuestionById(feedback.QuestionId);
            var u = ad.GetUserByID(feedback.UserId);

            if (string.IsNullOrWhiteSpace(feedback.Message))
            {
                return(BadRequest("Введите сообщение"));
            }

            if (q == null)
            {
                return(BadRequest("Вопроса не существует"));
            }

            if (u == null)
            {
                return(BadRequest("Юзера не существует"));
            }

            Mapper            mapper  = new Mapper();
            StudentDataAccess student = new StudentDataAccess();
            int id = student.CreateFeedback(mapper.ConvertFeedbackInputModelToFeedbackDTO(feedback));

            return(Ok(id));
        }
예제 #6
0
        public ActionResult <List <FeedbackOutputModel> > GetFeedbacksByPeriod(DateTimeInputModel period)
        {
            Mapper           mapper    = new Mapper();
            AuthorDataAccess feedbacks = new AuthorDataAccess();

            return(Ok(mapper.ConvertFeedbackDTOToFeedbackModelList(feedbacks.GetFeedbacksByPeriod(period.StringConverToDateTime(period.PeriodStart), period.StringConverToDateTime(period.PeriodEnd)))));
        }
예제 #7
0
        public ActionResult <int> PostQuestion(QuestionInputModel questionModel)
        {
            Mapper           mapper      = new Mapper();
            QuestionDTO      questionDto = mapper.ConvertQuestionInputModelToQuestionDTO(questionModel);
            AuthorDataAccess questions   = new AuthorDataAccess();
            var test = questions.GetTestById(questionModel.TestID);

            if (test == null)
            {
                return(BadRequest("Теста не существует"));
            }
            if (string.IsNullOrWhiteSpace(questionModel.Value))
            {
                return(BadRequest("Введите вопрос"));
            }
            if (questionModel.TypeID == null)
            {
                return(BadRequest("Введите тип вопроса"));
            }
            if (questionModel.AnswersCount == null)
            {
                return(BadRequest("Введите количество ответов на вопрос"));
            }
            if (questionModel.Weight == null)
            {
                return(BadRequest("Введите вес вопроса"));
            }
            return(Ok(questions.AddQuestion(questionDto)));
        }
예제 #8
0
        public ActionResult <List <TagOutputModel> > GetAllTags()
        {
            Mapper           mapper = new Mapper();
            AuthorDataAccess tags   = new AuthorDataAccess();

            return(Ok(mapper.ConvertTagDTOToTagModelList(tags.GetAllTags())));
        }
예제 #9
0
        public ActionResult <QuestionOutputModel> GetQuestionById([FromBody] int questionId)
        {
            Mapper              mapper     = new Mapper();
            AuthorDataAccess    question   = new AuthorDataAccess();
            QuestionOutputModel model      = mapper.ConvertQuestionDTOToQuestionOutputModel(question.GetQuestionById(questionId));
            QuestionStatistics  statistics = new QuestionStatistics(questionId);

            model.PercentageOfCorrectlyAnswered = statistics.GetPercentageOfCorrectlyAnswered(questionId);
            return(Ok(model));
        }
예제 #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("1.Выведите список должников.");
            using (var readerDataAccess = new ReaderDataAccess())
            {
                var debtors = (List <Reader>)readerDataAccess.Select();
                foreach (var debtor in debtors)
                {
                    Console.WriteLine($"\t{debtor.Id}. {debtor.FullName}");
                }
            }



            Console.WriteLine("\n2.Выведите список авторов книги №3 (по порядку из таблицы ‘Book’).");
            using (var authorDataAccess = new AuthorDataAccess())
            {
                var authors = (List <Author>)authorDataAccess.Select();
                foreach (var author in authors)
                {
                    Console.WriteLine($"\t{author.Id}. {author.FullName}");
                }
            }



            Console.WriteLine("\n3.Выведите список книг, которые доступны в данный момент.");
            using (var bookDataAccess = new BookDataAccess())
            {
                var books = (List <Book>)bookDataAccess.SelectFreeBooks();
                foreach (var book in books)
                {
                    Console.WriteLine($"\t{book.Id}. {book.Name}");
                }
            }



            Console.WriteLine("\n4.Вывести список книг, которые на руках у пользователя №2.");
            using (var bookDataAccess = new BookDataAccess())
            {
                var books = (List <Book>)bookDataAccess.Select();
                foreach (var book in books)
                {
                    Console.WriteLine($"\t{book.Id}. {book.Name}");
                }
            }

            //5) Обнулите задолженности всех должников.

            /*using (var readerDataAccess = new ReaderDataAccess())
             * {
             *  readerDataAccess.DeleteDebts();
             * }*/
        }
예제 #11
0
        public ActionResult <int> DeleteTestById(int testId)
        {
            AuthorDataAccess tests = new AuthorDataAccess();
            var test = tests.GetTestById(testId);

            if (test == null)
            {
                return(BadRequest("Теста не существует"));
            }
            return(Ok(tests.DeleteTestById(testId)));
        }
예제 #12
0
        public ActionResult PutProcessedInFeedback(int feedbackId)
        {
            AuthorDataAccess feedbacks = new AuthorDataAccess();
            var feedback = feedbacks.GetFeedbackById(feedbackId);

            if (feedback == null)
            {
                return(BadRequest("Фитбека не существует"));
            }
            return(Ok(feedbacks.UpdateProcessedInFeedback(feedbackId)));
        }
예제 #13
0
        public ActionResult <int> DeleteAnswerById(int answerId)
        {
            AuthorDataAccess answers = new AuthorDataAccess();
            var answer = answers.GetAnswerById(answerId);

            if (answer == null)
            {
                return(BadRequest("Ответа не существует"));
            }
            answers.DeleteAnswerById(answerId);
            return(Ok(answerId));
        }
예제 #14
0
        public ActionResult <int> DeleteTagById(int tagId)
        {
            AuthorDataAccess tags = new AuthorDataAccess();
            var tag = tags.GetTagById(tagId);

            if (tag == null)
            {
                return(BadRequest("Тега не существует"));
            }
            tags.DeleteTagById(tagId);
            return(Ok(tagId));
        }
예제 #15
0
        public ActionResult <List <FeedbackOutputModel> > GetFeedbacksByTestId(int testId)
        {
            Mapper           mapper    = new Mapper();
            AuthorDataAccess feedbacks = new AuthorDataAccess();
            var test = feedbacks.GetTestById(testId);

            if (test == null)
            {
                return(BadRequest("Теста не существует"));
            }
            return(Ok(mapper.ConvertFeedbackDTOToFeedbackModelList(feedbacks.GetFeedbacksByTestId(testId))));
        }
예제 #16
0
        public ActionResult <List <TagOutputModel> > GetTagsWhichAreNotInTest(int testId)
        {
            Mapper           mapper = new Mapper();
            AuthorDataAccess tags   = new AuthorDataAccess();
            var test = tags.GetTestById(testId);

            if (test == null)
            {
                return(BadRequest("Теста не существует"));
            }
            return(Ok(mapper.ConvertTagDTOToTagModelList(tags.GetTagsWhichAreNotInTest(testId))));
        }
예제 #17
0
        public ActionResult <int> DeleteQuestionById(int questionId)
        {
            AuthorDataAccess questions = new AuthorDataAccess();
            var question = questions.GetQuestionById(questionId);

            if (question == null)
            {
                return(BadRequest("Вопроса не существует"));
            }
            questions.DeleteQuestionById(questionId);
            return(Ok(questionId));
        }
예제 #18
0
        public ActionResult PutNewRightAnswer([FromBody] AnswerWithoutIDInputModel answer)
        {
            QuestionCRUD question = new QuestionCRUD();

            if (!question.GetAll().Any(x => x.ID == answer.QuestionID))
            {
                return(BadRequest("Вопроса с таким ID не существует"));
            }
            AuthorDataAccess author = new AuthorDataAccess();

            return(Ok(author.UpdateRightAnswer(answer.QuestionID, answer.Value)));
        }
예제 #19
0
        public ActionResult <int> PostTag([FromBody] TagInputModel tagModel)
        {
            if (string.IsNullOrWhiteSpace(tagModel.Name))
            {
                return(BadRequest("Введите название тега"));
            }
            Mapper           mapper = new Mapper();
            TagDTO           tagDto = mapper.ConvertTagInputModelToTagDTO(tagModel);
            AuthorDataAccess tag    = new AuthorDataAccess();

            return(Ok(tag.AddTag(tagDto)));
        }
예제 #20
0
        static void Main(string[] args)
        {
            var userDataAccess   = new UserDataAccess();
            var bookDataAccess   = new BookDataAccess();
            var authorDataAccess = new AuthorDataAccess();

            var debtorUsers = userDataAccess.SelectDebtorUsers();
            var books       = bookDataAccess.SelectAll();
            var authors     = authorDataAccess.SelectAll();

            var bookNumberThree = bookDataAccess.SelectById(3);
            var userNumberTwo   = userDataAccess.SelectById(2);

            foreach (var user in debtorUsers)
            {
                Console.WriteLine(user.ToString());
            }

            foreach (var authorId in bookNumberThree.Authors)
            {
                foreach (var author in authors)
                {
                    if (authorId == author.Id)
                    {
                        Console.WriteLine(author.ToString());
                        break;
                    }
                }
            }

            foreach (var book in books)
            {
                if (book.Status)
                {
                    Console.WriteLine(book.ToString());
                }
            }

            foreach (var bookId in userNumberTwo.Books)
            {
                foreach (var book in books)
                {
                    if (bookId == book.Id)
                    {
                        Console.WriteLine(book.ToString());
                        break;
                    }
                }
            }

            userDataAccess.UpdateDebtorUsers();
        }
예제 #21
0
        public ActionResult <List <AllTestsByStudentIdOutputModel> > GetGetAllStudentsByTestId(int testId)
        {
            TeacherDataAccess teacher = new TeacherDataAccess();
            Mapper            mapper  = new Mapper();
            AuthorDataAccess  tests   = new AuthorDataAccess();
            var test = tests.GetTestById(testId);

            if (test == null)
            {
                return(BadRequest("Теста не существует"));
            }
            return(Ok(mapper.ConvertAllStudentTestsDTOToAllTestsByStudentIdOutputModel(teacher.GetStudentsByTestId(testId))));
        }
예제 #22
0
        public ActionResult <FeedbackQuestionOutputModel> GetFeedbackByIdWithAllInfo(int feedbackId)
        {
            Mapper           mapper    = new Mapper();
            AuthorDataAccess feedbacks = new AuthorDataAccess();
            var feedback = feedbacks.GetFeedbackWithQuestion(feedbackId);

            if (feedback == null)
            {
                return(BadRequest("Фитбека не существует"));
            }
            FeedbackQuestionOutputModel model = mapper.ConvertFeedbackQuestionDTOToFeedbackQuestionOutputModel(feedback);

            model.Answers = mapper.ConvertAnswerDTOToAnswerModelList(feedbacks.GetAllAnswersByFeedbackId(feedbackId));
            return(Ok(model));
        }
예제 #23
0
        static void Main(string[] args)
        {
            InitConfiguration();

            var userDataAccess = new UserDataAccess();
            var firstData      = userDataAccess.SelectDebtors();

            foreach (var value in firstData)
            {
                if (value.IsRegistered == true)
                {
                    Console.WriteLine($"Должник: {value.FirstName} {value.LastName}");
                }
            }

            int authorId         = 3;
            var authorDataAccess = new AuthorDataAccess();
            var secondData       = authorDataAccess.SelectAuthorsByBook(authorId);

            Console.WriteLine("Автор(-ы): ");

            foreach (var value in secondData)
            {
                Console.WriteLine($"{value.FirstName} {value.LastName}");
            }

            var bookDataAccess = new BookDataAccess();
            var thirdData      = bookDataAccess.SelectAvailableBooks();

            Console.WriteLine($"Доступные книги: ");

            foreach (var value in thirdData)
            {
                Console.WriteLine($"{value.Name}");
            }

            int userId    = 2;
            var forthData = bookDataAccess.SelectBooksByUser(userId);

            Console.WriteLine($"У пользователя с Id {userId} книга(-и) ");

            foreach (var value in forthData)
            {
                Console.WriteLine($"{value.Name}");
            }

            //userDataAccess.DeleteAllDebtors();
        }
예제 #24
0
        public ActionResult <int> PutTagById([FromBody] TagInputModel tagModel)
        {
            Mapper           mapper = new Mapper();
            TagDTO           tagDto = mapper.ConvertTagInputModelToTagDTO(tagModel);
            AuthorDataAccess tags   = new AuthorDataAccess();
            var tag = tags.GetTagById(tagModel.ID);

            if (tag == null)
            {
                return(BadRequest("Тега не существует"));
            }
            if (string.IsNullOrWhiteSpace(tagModel.Name))
            {
                return(BadRequest("Введите название тега"));
            }
            tags.UpdateTagById(tagDto);
            return(Ok(tagModel.ID));
        }
예제 #25
0
        public ActionResult <List <TestOutputModel> > GetAllTests()
        {
            Mapper           mapper = new Mapper();
            AuthorDataAccess tests  = new AuthorDataAccess();

            List <TestOutputModel> listOfModels = mapper.ConvertTestDTOToTestModelList(tests.GetAllTests());

            foreach (var i in listOfModels)
            {
                TestStatistics    statistics = new TestStatistics(i.ID);
                PassedFailedModel pfs        = statistics.GetPassedFailedStats(i.ID);
                i.AverageResult = statistics.GetAverageResults(i.ID);
                i.Passed        = pfs.Passed;
                i.Failed        = pfs.Failed;
                i.SuccessRate   = pfs.SuccessRate;
            }
            return(Ok(listOfModels));
        }
예제 #26
0
        public ActionResult <TestOutputModel> GetTestAllInfoById(int testId)
        {
            Mapper           mapper       = new Mapper();
            AuthorDataAccess tests        = new AuthorDataAccess();
            var            test           = tests.GetTestById(testId);
            TestStatistics testStatistics = new TestStatistics(testId);

            if (test == null)
            {
                return(BadRequest("Теста не существует"));
            }
            TestOutputModel   model = mapper.ConvertTestDTOToTestOutputModel(tests.GetTestById(testId));
            PassedFailedModel pfs   = testStatistics.GetPassedFailedStats(testId);

            model.Questions     = mapper.ConvertQuestionDTOToQuestionModelList(tests.GetQuestionsByTestID(testId));
            model.Tags          = mapper.ConvertTagDTOToTagModelList(tests.GetTagsInTest(testId));
            model.AverageResult = testStatistics.GetAverageResults(testId);
            model.Passed        = pfs.Passed;
            model.Failed        = pfs.Failed;
            model.SuccessRate   = pfs.SuccessRate;
            foreach (QuestionOutputModel qModel in model.Questions)
            {
                qModel.Answers = mapper.ConvertAnswerDTOToAnswerModelList(tests.GetAnswerByQuestionId(qModel.ID));
                QuestionStatistics statistics = new QuestionStatistics(qModel.ID);
                qModel.PercentageOfCorrectlyAnswered = statistics.GetPercentageOfCorrectlyAnswered(qModel.ID);
                Dictionary <int, double> answersPercent = new Dictionary <int, double>();
                answersPercent = statistics.GetPercentageOfPeopleChoosingAnswer(qModel.ID);
                foreach (var answer in qModel.Answers)
                {
                    foreach (var i in answersPercent)
                    {
                        if (answer.ID == i.Key)
                        {
                            answer.PercentageOfPeopleChoosingAnswer = i.Value;
                        }
                        else
                        {
                            answer.PercentageOfPeopleChoosingAnswer = 0;
                        }
                    }
                }
            }
            return(Ok(model));
        }
예제 #27
0
        public ActionResult <int> PostTagInTest(TestTagInputModel testTagModel)
        {
            Mapper           mapper     = new Mapper();
            TestTagDTO       testTagDto = mapper.ConvertTestTagInputModelToTestTagDTO(testTagModel);
            AuthorDataAccess tags       = new AuthorDataAccess();
            var test = tags.GetTestById(testTagModel.TestID);

            if (test == null)
            {
                return(BadRequest("Теста не существует"));
            }
            var tag = tags.GetTagById(testTagModel.TagID);

            if (tag == null)
            {
                return(BadRequest("Тега не существует"));
            }
            return(Ok(tags.TestTagCreate(testTagDto)));
        }
예제 #28
0
        private void CreateQuestionAnswersLists(InfoForStatisticsModel info)
        {
            AuthorDataAccess tests = new AuthorDataAccess();

            foreach (var question in info.Questions)
            {
                question.Value.AnswersId = new List <int>();
                question.Value.CorrectId = new List <int>();
                var answers = tests.GetAnswerByQuestionId(question.Key);
                foreach (var answer in answers)
                {
                    question.Value.AnswersId.Add(answer.ID);
                    if (answer.Correct == true)
                    {
                        question.Value.CorrectId.Add(answer.ID);
                    }
                }
            }
        }
예제 #29
0
        public ActionResult <int> PostAnswer(AnswerInputModel answerModel)
        {
            Mapper           mapper    = new Mapper();
            AnswerDTO        answerDto = mapper.ConvertAnswerInputModelToAnswerDTO(answerModel);
            AuthorDataAccess answer    = new AuthorDataAccess();
            var question = answer.GetQuestionById(answerModel.QuestionID);

            if (question == null)
            {
                return(BadRequest("Вопроса не существует"));
            }
            if (string.IsNullOrWhiteSpace(answerModel.Value))
            {
                return(BadRequest("Введите ответ"));
            }
            if (answerModel.Correct == null)
            {
                return(BadRequest("Введите корректный ответ или нет"));
            }
            return(Ok(answer.AddAnswer(answerDto)));
        }
예제 #30
0
        public IActionResult PostTestForGroup([FromBody] TestGroupInputModel test)
        {
            AdminDataAccess adm   = new AdminDataAccess();
            var             group = adm.GetGroupById(test.groupId.Value);

            if (group == null)
            {
                return(BadRequest("Группа не существует"));
            }
            AuthorDataAccess author = new AuthorDataAccess();
            var t = author.GetTestById(test.testId.Value);

            if (t == null)
            {
                return(BadRequest("Тест не существует"));
            }
            if (test.testId == null)
            {
                return(BadRequest("Не выбран тест"));
            }
            if (test.groupId == null)
            {
                return(BadRequest("Не выбрана группа"));
            }
            if (string.IsNullOrWhiteSpace(test.startDate))
            {
                return(BadRequest("Отсутствует дата начала теста"));
            }
            if (string.IsNullOrWhiteSpace(test.endDate))
            {
                return(BadRequest("Отсутствует дата окончания теста"));
            }
            Mapper            mapper  = new Mapper();
            TeacherDataAccess teacher = new TeacherDataAccess();
            int id = teacher.SetTestForGroup(mapper.ConvertTestGroupInputModelToTestGroupDTO(test));

            return(Ok(id));
        }