public ActionResult <List <FeedbackOutputModel> > GetAllFeedbacks() { Mapper mapper = new Mapper(); AuthorDataAccess feedbacks = new AuthorDataAccess(); return(Ok(mapper.ConvertFeedbackDTOToFeedbackModelList(feedbacks.GetAllFeedbacks()))); }
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)))); } } }
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))); }
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("Успешно изменено!")); }
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)); }
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))))); }
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 <List <TagOutputModel> > GetAllTags() { Mapper mapper = new Mapper(); AuthorDataAccess tags = new AuthorDataAccess(); return(Ok(mapper.ConvertTagDTOToTagModelList(tags.GetAllTags()))); }
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)); }
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(); * }*/ }
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 PutProcessedInFeedback(int feedbackId) { AuthorDataAccess feedbacks = new AuthorDataAccess(); var feedback = feedbacks.GetFeedbackById(feedbackId); if (feedback == null) { return(BadRequest("Фитбека не существует")); } return(Ok(feedbacks.UpdateProcessedInFeedback(feedbackId))); }
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)); }
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)); }
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 <int> DeleteQuestionById(int questionId) { AuthorDataAccess questions = new AuthorDataAccess(); var question = questions.GetQuestionById(questionId); if (question == null) { return(BadRequest("Вопроса не существует")); } questions.DeleteQuestionById(questionId); return(Ok(questionId)); }
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))); }
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))); }
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(); }
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 <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)); }
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(); }
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)); }
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)); }
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> 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))); }
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); } } } }
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))); }
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)); }