コード例 #1
0
        public AddAnswerViewModel()
        {
            vml = new ViewModelLocator();
            qvm = vml.Questions;

            AddAnswerCommand = new RelayCommand(AddAnswer);
        }
コード例 #2
0
        //Get => api/Questions
        public ActionResult GetUnansweredQuestions()
        {
            try
            {
                string user = User.Claims.First(o => o.Type == "UserName").Value;

                var result = _questionsRepository.GetAllUnasweredQuestionsByUser(user);

                List <QuestionsViewModel> questions = new List <QuestionsViewModel>();
                foreach (var item in result)
                {
                    QuestionsViewModel question = new QuestionsViewModel()
                    {
                        Answer     = item.Answer,
                        Question   = item.Question,
                        QuestionId = item.QuestionId,
                        Time       = item.Time,
                        IsAnswered = item.IsAnswered
                    };
                    question.QuestionTo = item.QuestionTo.UserName;
                    if (item.QuestionFrom != null)
                    {
                        question.QuestionFrom = item.QuestionFrom.UserName;
                    }
                    questions.Add(question);
                }
                return(Ok(questions));
            }
            catch (Exception e)
            {
                _logger.LogError($"DateTime:{DateTime.Now} -- Error:{e.Message}\n{e.StackTrace}");
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to retrieve data"));
            }
        }
コード例 #3
0
        public override void Execute(object parameter)
        {
            if (test)
            {
                viewModel.CurrentQuestion++;
                test = false;
            }
            else
            {
                viewModel.CurrentQuestion--;
                test = true;
            }

            return;

            OnlineExamsViewModel onlineExamsViewModel = new OnlineExamsViewModel();
            ChooseExam           chooseExam           = new ChooseExam();

            QuestionsViewModel questionsViewModel = new QuestionsViewModel();

            questionsViewModel.Exams    = DataProvider.GetExams();
            questionsViewModel.Subjects = DataProvider.GetSubjects();

            chooseExam.DataContext = questionsViewModel;
            chooseExam.ShowDialog();

            if (chooseExam.DialogResult == true)
            {
                //questionsViewModel.CurrentQuestion = DataProvider.GetQuestions();
            }
        }
コード例 #4
0
        public void PostEdit()
        {
            var question = db.Questions.First();
            QuestionsViewModel questionModel = new QuestionsViewModel()
            {
                QuestionId    = question.QuestionId,
                Contents      = "test",
                Answer1       = "test",
                Answer2       = "test",
                Answer3       = "test",
                CorrectAnswer = "test",
            };

            var MyCheckBoxList = new List <CheckBoxViewModel>();

            foreach (var item in db.Categories)
            {
                MyCheckBoxList.Add(new CheckBoxViewModel {
                    Id = item.CategorieId, Name = item.Name, Checked = true
                });
            }

            questionModel.Categories = MyCheckBoxList;

            var result = controller.Edit(questionModel) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
コード例 #5
0
        public ActionResult Hoidap(Guid?id, int?p)
        {
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                var pageIndex = p ?? 1;

                var rs = _contactService.GetAllQuestionPost(pageIndex, 3);

                if (id != Guid.Empty && id != null)
                {
                    rs = _contactService.GetQuestions(id.Value);
                }

                // Redisplay list of questions

                var vm = new QuestionsViewModel()
                {
                    Questions  = rs,
                    PageIndex  = pageIndex,
                    TotalPages = rs.TotalPages,
                    TotalCount = rs.TotalCount
                };

                return(View(vm));
            }
        }
コード例 #6
0
        public ActionResult CreateConfirm()
        {
            Questions question = TempData["toSubmit_Qns"] as Questions;

            if (question != null)
            {
                QuestionsViewModel question_options = new QuestionsViewModel();
                if (question.option_type.Equals(Constants.QNS_IMAGE_OPTION_TYPE))
                {
                    question_options.option_1 = "<img src=\"" + Constants.IMG_PIC_UPLOAD_SRC + question.option_1
                                                + "\" alt=\"Option 1 Image\" width=\"100\" height=\"100\" />";
                    question_options.option_2 = "<img src=\"" + Constants.IMG_PIC_UPLOAD_SRC + question.option_2
                                                + "\" alt=\"Option 2 Image\" width=\"100\" height=\"100\" />";
                    question_options.option_3 = "<img src=\"" + Constants.IMG_PIC_UPLOAD_SRC + question.option_3
                                                + "\" alt=\"Option 3 Image\" width=\"100\" height=\"100\" />";
                    question_options.option_4 = "<img src=\"" + Constants.IMG_PIC_UPLOAD_SRC + question.option_4
                                                + "\" alt=\"Option 4 Image\" width=\"100\" height=\"100\" />";
                }
                else
                {
                    question_options.option_1 = question.option_1;
                    question_options.option_2 = question.option_2;
                    question_options.option_3 = question.option_3;
                    question_options.option_4 = question.option_4;
                }

                ViewBag.question_options = question_options;
                ViewBag.station_name     = stationGateway.GetStationName_ByStationID(question.station_id);
                return(View(question));
            }

            return(RedirectToAction("Create"));
        }
コード例 #7
0
        public ActionResult Create(QuestionsViewModel questionModel)
        {
            if (ModelState.IsValid)
            {
                Question question = new Question
                {
                    Contents      = questionModel.Contents,
                    Answer1       = questionModel.Answer1,
                    Answer2       = questionModel.Answer2,
                    Answer3       = questionModel.Answer3,
                    CorrectAnswer = questionModel.CorrectAnswer
                };
                db.Questions.Add(question);

                foreach (var item in questionModel.Categories)
                {
                    if (item.Checked)
                    {
                        db.QuestionToCategories.Add(new QuestionToCategories()
                        {
                            QuestionId  = question.QuestionId,
                            CategorieId = item.Id
                        });
                    }
                }

                db.SaveChanges();
                TempData["alert"] = "Stworzyłeś nowa pytanie!";
                return(RedirectToAction("Index"));
            }

            return(View(questionModel));
        }
        public int InsertQuestion(QuestionsViewModel QuestionsViewModel)
        {
            var       config   = new MapperConfiguration(cfg => { cfg.CreateMap <QuestionsViewModel, Questions>(); cfg.IgnoreUnmapped(); });
            IMapper   mapper   = config.CreateMapper();
            Questions question = mapper.Map <QuestionsViewModel, Questions>(QuestionsViewModel);

            return(questionRepository.InsertQuestion(question));
        }
コード例 #9
0
        public void EditQuestion(QuestionsViewModel editQuestionsViewModel)
        {
            var       config   = new MapperConfiguration(cfg => { cfg.CreateMap <QuestionsViewModel, Questions>(); cfg.IgnoreUnmapped(); });
            IMapper   mapper   = config.CreateMapper();
            Questions question = mapper.Map <QuestionsViewModel, Questions>(editQuestionsViewModel);

            questionRepository.EditQuestion(question);
        }
コード例 #10
0
        public IActionResult List(string id = "All", string id2 = "All")
        {
            List <Question>    fAQs  = context.Questions.OrderBy(f => f.Id).ToList();
            QuestionsViewModel model = new QuestionsViewModel();

            model.questions = fAQs;
            return(View(model));
        }
        public QuestionsViewModel GetQuestionsByTestId(int questionID)
        {
            Questions          question     = questionRepository.GetQuestionsByTestId(questionID);
            var                config       = new MapperConfiguration(cfg => { cfg.CreateMap <Questions, QuestionsViewModel>(); cfg.IgnoreUnmapped(); });
            IMapper            mapper       = config.CreateMapper();
            QuestionsViewModel OriginalData = mapper.Map <Questions, QuestionsViewModel>(question);

            return(OriginalData);
        }
コード例 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="QuestionsPage"/> class.
        /// </summary>
        public QuestionsPage()
        {
            InitializeComponent();

            BindingContext = viewModel = new QuestionsViewModel();

            //conn = DependencyService.Get<ISQLiteInterface>().GetAsyncConnection();
            //conn.CreateTableAsync<Question>();
        }
コード例 #13
0
        public Questions()
        {
            QuestionsViewModel context = new QuestionsViewModel();

            //Register to the event so the view model will be able to navigate to the monkeypage
            context.NavigateToPageEvent += NavigateToAsync;
            this.BindingContext          = context;
            InitializeComponent();
        }
 public ActionResult EditQuestion(QuestionsViewModel editedData)
 {
     //editedData.TestId = (int)TempData.Peek("MyData");
     if (ModelState.IsValid)
     {
         questionService.EditQuestion(editedData);
         return(RedirectToAction("DisplayQuestions", new { testId = editedData.TestId }));
     }
     return(View());
 }
コード例 #15
0
        private Page GetPage(Initializer initizlizer, string pageName, Initializer.SubjectTypes subjectType)
        {
            var page = new QuestionsPage {
                Title = pageName
            };
            var viewModel = new QuestionsViewModel(initizlizer.GetInitizlizedList(subjectType));

            page.BindingContext = viewModel;
            return(page);
        }
コード例 #16
0
        public QuestionsViewModelTests()
        {
            NetworkApi = new StubINetworkApi();
            Search     = new StubISearchViewModel();
            Subject    = new QuestionsViewModel(search: Search, networkApi: NetworkApi);

            Search.SelectedSite_Set(site => Site = site);
            Search.SelectedSite_Get(() => Site);
            Search.LoadSites_Get(() => LoadSites);
        }
コード例 #17
0
ファイル: DataViewModel.cs プロジェクト: wim07101993/Cranium
 public DataViewModel(
     IStringsProvider stringsProvider,
     HamburgerMenuViewModel hamburgerMenuViewModel, QuestionsViewModel questionsViewModel,
     QuestionTypesViewModel questionTypesViewModel, CategoriesViewModel categoriesViewModel)
     : base(stringsProvider)
 {
     HamburgerMenuViewModel = hamburgerMenuViewModel;
     QuestionsViewModel     = questionsViewModel;
     QuestionTypesViewModel = questionTypesViewModel;
     CategoriesViewModel    = categoriesViewModel;
 }
コード例 #18
0
        public async Task <FormsViewModel> Get(int formId)
        {
            var formCategoryAssignment = await _context.FormsCategoryAssignments
                                         .Where(c => c.FormId == formId)
                                         .Include(f => f.FormsInfo)
                                         .Include(c => c.Categories)
                                         .FirstOrDefaultAsync();

            var questions = await _context.QuestionsFormAssignments
                            .Where(qfa => qfa.FormId == formId)
                            .Include(q => q.Questions)
                            .ThenInclude(qt => qt.QuestionTypes)
                            .ToListAsync();

            var options = await _context.OptionsQuestionAssignmnents
                          .Where(oqa => oqa.FormId == formId)
                          .Include(o => o.Options)
                          .ToListAsync();

            //Save fetched data to FormsViewModel
            var form = new FormsViewModel
            {
                Questions        = new List <QuestionsViewModel>(),
                CategoryId       = formCategoryAssignment.CategoryId,
                CategoryName     = formCategoryAssignment.Categories.CategoryName,
                DestinationEmail = formCategoryAssignment.FormsInfo.DestinationEmail,
                FormName         = formCategoryAssignment.FormsInfo.FormName,
                IsAnonymous      = formCategoryAssignment.FormsInfo.IsAnonymous
            };

            foreach (var fetchedQuestion in questions)
            {
                var question = new QuestionsViewModel
                {
                    QuestionName         = fetchedQuestion.Questions.QuestionName,
                    QuestionOrderNum     = fetchedQuestion.QuestionOrderNum,
                    QuestionType         = fetchedQuestion.Questions.QuestionTypes.QuestionType,
                    QuestionTypeOrderNum = fetchedQuestion.QuestionTypeOrderNum,
                    Options = new List <OptionsViewModel>()
                };

                foreach (var fetchedOption in options.Where(o => o.QuestionOrderNum == question.QuestionOrderNum))
                {
                    var option = new OptionsViewModel
                    {
                        OptionName     = fetchedOption.Options.OptionName,
                        OptionOrderNum = fetchedOption.OptionOrderNum
                    };
                    question.Options.Add(option);
                }
                form.Questions.Add(question);
            }
            return(form);
        }
コード例 #19
0
        private void setupImageOptions_ViewBag()
        {
            QuestionsViewModel question_options = new QuestionsViewModel()
            {
                option_1 = Constants.IMG_NO_PREVIEW_SRC,
                option_2 = Constants.IMG_NO_PREVIEW_SRC,
                option_3 = Constants.IMG_NO_PREVIEW_SRC,
                option_4 = Constants.IMG_NO_PREVIEW_SRC
            };

            ViewBag.question_options = question_options;
        }
コード例 #20
0
        public IActionResult Index()
        {
            var repo      = new QuestionsRepository(_connectionString);
            var questions = repo.GetAllQuestions();

            QuestionsViewModel vm = new QuestionsViewModel
            {
                Questions = questions
            };

            return(View(vm));
        }
コード例 #21
0
        //Post => api/Questions/user
        public async Task <ActionResult> Post(QuestionsViewModel model, string user)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var questionTo = await _userManager.FindByNameAsync(user);

                    if (questionTo == null)
                    {
                        return(NotFound("Couldn't find this User"));
                    }

                    var question = new Questions()
                    {
                        Question   = model.Question,
                        QuestionTo = questionTo,
                        Time       = DateTime.Now,
                        IsAnswered = false,
                        Answer     = null,
                    };

                    if (model.QuestionFrom != null)
                    {
                        var questionFrom = await _userManager.FindByNameAsync(model.QuestionFrom);

                        question.QuestionFrom = questionFrom;
                    }

                    _questionsRepository.AddQuestion(question);

                    if (_questionsRepository.SaveAll())
                    {
                        return(Created("api/questions", new { message = "Question Sent" }));
                    }
                    else
                    {
                        _logger.LogWarning($"DateTime: {DateTime.Now} -- Error: Couldn't save the question into database");
                        return(BadRequest("Failed to save your question"));
                    }
                }
                else
                {
                    _logger.LogWarning($"DateTime: {DateTime.Now} -- Error: Question Format isn't right from Post");
                    return(BadRequest(ModelState));
                }
            }
            catch (Exception e)
            {
                _logger.LogError($"DateTime:{DateTime.Now} -- Error:{e.Message}\n{e.StackTrace}");
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed to retrieve data"));
            }
        }
コード例 #22
0
        public IActionResult Index()
        {
            // var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
            // optionsBuilder.UseSqlite("Data Source=./RealTime.db");
            // using (var _dbContext = new ApplicationDbContext(optionsBuilder.Options)) {
            var model = new QuestionsViewModel()
            {
                Questions = _dbContext.Questions.Include(q => q.Answers).ToList()
            };

            return(View(model));
            // }
        }
コード例 #23
0
        public QuestionsViewModel GetQuestionsByQuestionID(int questionID)
        {
            Questions          question   = questionRepository.GetQuestionsByQuestionID(questionID);
            QuestionsViewModel questionvm = null;

            if (question != null)
            {
                var     config = new MapperConfiguration(cfg => { cfg.CreateMap <Questions, QuestionsViewModel>(); cfg.IgnoreUnmapped(); });
                IMapper mapper = config.CreateMapper();
                questionvm = mapper.Map <Questions, QuestionsViewModel>(question);
            }
            return(questionvm);
        }
コード例 #24
0
        public async Task <IActionResult> Questions(QuestionsSearchPostViewModel search)
        {
            //prepare master question list
            List <StackOverflowQuestionWithDates> questions = new List <StackOverflowQuestionWithDates>();

            //prepare query strings for api call
            var userIdsForQuery = string.Empty;

            if (search.UserIds != null)
            {
                foreach (var userId in search.UserIds)
                {
                    userIdsForQuery += userId + ";";
                }
                userIdsForQuery = userIdsForQuery.TrimEnd(';');
            }

            //get and parse unanswered results
            var apiUrlUnanswered = (string.Format("users/{0}/questions/unanswered?pagesize={1}&order=desc&sort=activity&site=stackoverflow",
                                                  userIdsForQuery,
                                                  Constants.Constants.StackOverflowApiPageSize));

            questions = ParseAPIResults(await StackOverflowAPIService.CallApi(apiUrlUnanswered), questions);

            //get and parse no answer results
            var apiUrlNoAnswers = (string.Format("users/{0}/questions/no-answers?pagesize={1}&order=desc&sort=activity&site=stackoverflow",
                                                 userIdsForQuery,
                                                 Constants.Constants.StackOverflowApiPageSize));

            questions = ParseAPIResults(await StackOverflowAPIService.CallApi(apiUrlNoAnswers), questions);

            //get and parse unaccepted results
            var apiUrlUnaccepted = (string.Format("users/{0}/questions/unaccepted?pagesize={1}&order=desc&sort=activity&site=stackoverflow",
                                                  userIdsForQuery,
                                                  Constants.Constants.StackOverflowApiPageSize));

            questions = ParseAPIResults(await StackOverflowAPIService.CallApi(apiUrlUnaccepted), questions);

            //populate view model
            var filteredQuestions = questions
                                    .Where(o => o.is_answered != true)
                                    .Where(o => o.locked_date == 0)
                                    .Where(o => o.closed_date == 0)
                                    .ToList();
            var vm = new QuestionsViewModel()
            {
                Questions = filteredQuestions
            };

            return(View(vm));
        }
コード例 #25
0
        public ActionResult Questions(int GameID)
        {
            if (CheckLoggedIn())
            {
                return(RedirectToAction("Index", "Login"));
            }

            QuestionsViewModel model = new QuestionsViewModel();

            model.game           = gameHandler.GetGame(GameID);
            model.game.Questions = question_Handler.GetQuestions(GameID);

            return(View("Questions", model));
        }
コード例 #26
0
        public async Task <IActionResult> ExamQuestions(int examid, bool editing, QuestionsViewModel model)
        {
            if (model.AskedQuestion != null && CheckTeacher(examid))
            {
                await _repository.AddQuestion(new Question
                {
                    AskedQuestion = model.AskedQuestion,
                    ExamId        = examid
                });

                return(RedirectToAction("ExamQuestions", new { id = examid, isediting = editing }));
            }

            return(RedirectToAction("Exams"));
        }
コード例 #27
0
        public QuestionsPage(int position = 0) : base()
        {
            InitializeComponent();

            Xamarin.Forms.PlatformConfiguration.iOSSpecific.Page.SetUseSafeArea(this, true);
            BindingContext = new QuestionsViewModel(position);

            var cancel = new ToolbarItem
            {
                Text    = "添加",
                Command = new Command(async() =>
                {
                    if (UserTokenSettings.Current.HasExpiresIn())
                    {
                        MessagingService.Current.SendMessage(MessageKeys.NavigateLogin);
                    }
                    else
                    {
                        await NavigationService.PushAsync(Navigation, new QuestionsEditPage(new Questions(), new Action <Questions>(OnResult)));
                    }
                })
            };

            ToolbarItems.Add(cancel);

            if (Device.Android == Device.RuntimePlatform)
            {
                cancel.Icon = "toolbar_add.png";
            }


            this.QuestionsListView.ItemSelected += async delegate
            {
                var questions = QuestionsListView.SelectedItem as Questions;
                if (questions == null)
                {
                    return;
                }

                var questionsDetails = new QuestionsDetailsPage(questions);

                await NavigationService.PushAsync(Navigation, questionsDetails);

                this.QuestionsListView.SelectedItem = null;
            };
            ViewModel.GetClientQuestionsAsync();
        }
コード例 #28
0
        public async Task Test_DisplayQuestion_Calls_Navigate_With_The_Given_QuestionViewModel()
        {
            var application       = new ApplicationViewModel();
            var question          = new Question();
            var questionViewModel = new QuestionItemViewModel(question);

            Subject = new QuestionsViewModel(application, Search, NetworkApi);

            using (application.Navigate.RegisterHandler(ctx =>
            {
                Assert.Same(question, ctx.Input.Parameter);
                ctx.SetOutput(Unit.Default);
            }))
            {
                await Subject.DisplayQuestion.Execute(questionViewModel);
            }
        }
コード例 #29
0
 public AddQuestionViewModel()
 {
     vml = new ViewModelLocator();
     qvm = vml.Questions;
     AddQuestionCommand = new RelayCommand(AddQuestion);
 }