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))); }
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)); }
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))); }
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)))); }
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)))); }
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)))); }
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))); }
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)); }
public ActionResult <int> DeleteTagFromTest(TestTagInputModel 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("Тега не существует")); } var testTag = tags.GetTestByTag(testTagModel.TestID, testTagModel.TagID); if (testTag == null) { return(BadRequest("У данного теста нет такого тега")); } tags.DeleteByTestIdTagId(testTagModel.TestID, testTagModel.TagID); return(Ok("Успешно удалено!")); }