Example #1
0
 public SurveyQuestionController(ISurveyService surveyService, ISurveyQuestionService surveyQuestionService, ISecurityService securityService, IMapper mapper)
 {
     _surveyService         = surveyService;
     _surveyQuestionService = surveyQuestionService;
     _securityService       = securityService;
     _mapper = mapper;
 }
 public SurveyController()
 {
     this.Client.BaseAddress = new Uri("http://localhost:9080/PIDEV-web/");
     this.Client.DefaultRequestHeaders.Accept.
     Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
     surveyservice         = new SurveyService();
     surquestservice       = new SurveyQuestionService();
     surveyquestempservice = new SurveyQuestEmpService();
 }
Example #3
0
        private async Task GatherResults(ISurveyQuestionService service, SurveyQuestion question)
        {
            string[] answers   = question.Answers.Split('|');
            var      responses = await service.GetResponsesForSurveyAsync(question.Id);

            foreach (var r in responses)
            {
                Results.Add(new OneResultViewModel {
                    Name   = r.Name,
                    Answer = answers [r.ResponseIndex]
                });
            }
        }
        public App()
        {
            Service = new AzureSurveyService();

            // The root page of your application
            //var content = new ContentPage {
            //	Title = "ThoughtsAndPrayers",
            //	Content = new StackLayout {
            //		VerticalOptions = LayoutOptions.Center,
            //		Children = {
            //			new Label {
            //				HorizontalTextAlignment = TextAlignment.Center,
            //				Text = "Welcome to Xamarin Forms!"
            //			}
            //		}
            //	}
            //};



            //TUESDAY - FREEZE
            NavigationPage np = new NavigationPage(new LoginPage())
            {
                BarBackgroundColor = MyColors.MyLightPurple
            };

            this.MainPage = np;



            //TUESDAY - Experiment - No
            //NavigationPage np = new NavigationPage (new TheTabbedPage ()) { BarBackgroundColor = Color.White };
            //this.MainPage = np;


            //TUESDAY - Experiment - Broken
            //LoginPage loginPage = new LoginPage ();
            //this.MainPage = loginPage;
        }
Example #5
0
 public ResultsViewModel(ISurveyQuestionService service, SurveyQuestion selectedQuestion)
 {
     Question = selectedQuestion;
     Results  = new ObservableCollection <OneResultViewModel> ();
     GatherResults(service, selectedQuestion).IgnoreResult();
 }
Example #6
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="surveyService">Service to retrieve data from</param>
        /// <param name="dependencyService">Service Locator</param>
        public MainViewModel(ISurveyQuestionService surveyService, IDependencyService dependencyService)
        {
            this.surveyService     = surveyService;
            this.dependencyService = dependencyService;

            // Setup our collection of questions. This is an async collection populated by our
            // survey service. The single constructor parameter is an async function to load the data.
            questions = new RefreshingCollection <SurveyQuestion>(surveyService.GetQuestionsAsync)
            {
                // What to do if the refresh fails..
                RefreshFailed = async(s, ex) =>
                {
                    IsLoadingData = false;
                    await Task.Delay(1000);  // get out of the binding.

                    await dependencyService.Get <IMessageVisualizerService>()
                    .ShowMessage("Error", "Failed to get questions: " + ex.Message, "OK");
                },

                // Called before a refresh occurs to save off the current selection.
                BeforeRefresh = s =>
                {
                    IsLoadingData = true;
                    return(SelectedQuestion);
                },

                // Called after a refresh completes successfully; restores the selection.
                AfterRefresh = (s, sq) =>
                {
                    IsLoadingData = false;
                    if (sq == null)
                    {
                        sq = questions.FirstOrDefault();
                    }
                    if (sq != null)
                    {
                        var newSelection = questions.SingleOrDefault(q => q.Id == ((SurveyQuestion)sq).Id);
                        SelectedQuestion = newSelection;
                    }
                }
            };

            // Setup the collection of answers; this is refreshed each time the
            // selected question changes.
            answers = new RefreshingCollection <AnswerViewModel>(async() =>
            {
                IsLoadingData = true;

                try
                {
                    var id            = SelectedQuestion.Id;
                    string [] choices = SelectedQuestion.Answers.Split('|');

                    if (HasName)
                    {
                        response = await surveyService.GetResponseForSurveyAsync(id, Name);
                    }
                    else
                    {
                        response = null;
                    }

                    int answerIndex = response == null ? -1 : response.ResponseIndex;

                    return(Enumerable.Range(0, choices.Length)
                           .Select(i => new AnswerViewModel(choices [i], i)
                    {
                        IsSelected = answerIndex == i
                    }));
                }
                catch (Exception ex)
                {
                    await dependencyService.Get <IMessageVisualizerService>()
                    .ShowMessage("Error", "Failed to get answers/responses: " + ex.Message, "OK");
                    return(null);
                }
                finally
                {
                    IsLoadingData = false;
                }
            });
        }