Exemple #1
0
        public async void jokeLinesFromFile(List <string> jokeLines)
        {
            foreach (var line in jokeLines)
            {
                string[] splittedLine = line.Split('*');
                string   text         = splittedLine[0];
                string   type         = splittedLine[1];
                string   gender       = splittedLine[2];

                JokeLine newJokeLine = new JokeLine();
                newJokeLine.Text = text;

                JokeLineType jokeLineType;
                if (Enum.TryParse(type, out jokeLineType))
                {
                    newJokeLine.JokeLineType = jokeLineType;
                }
                else
                {
                    throw new Exception("A jokeLineType in the textfile is not correct. maybe somewhere its club instead of Club");
                }

                AttractedGender jokeLineGender;
                if (Enum.TryParse(gender, out jokeLineGender))
                {
                    newJokeLine.AttractedGender = jokeLineGender;
                }
                else
                {
                    throw new Exception("A jokeLineGender in the textfile is not correct. maybe somewhere its club instead of Club");
                }

                await Database.SaveJokeLineAsync(newJokeLine);
            }
        }
Exemple #2
0
        private async void Save_Clicked(object sender, EventArgs e)
        {
            JokeLine jokeLineItem = (JokeLine)BindingContext;

            jokeLineItem.JokeLineType = (JokeLineType)Enum.Parse(typeof(JokeLineType), (string)JokeLineTypePicker.SelectedItem);

            await App.Database.SaveJokeLineAsync(jokeLineItem);

            await Navigation.PopAsync();
        }
        private async void RemoveButton_Clicked(object sender, EventArgs e)
        {
            if (currentJokeLine == null)
            {
                return;
            }

            LblCurrentJoke.Text = "Druk op de Smiley!";

            await App.Database.DeleteJokeLineAsync(currentJokeLine);

            currentJokeLine = null;
        }
        private async void EditButton_Clicked(object sender, EventArgs e)
        {
            if (currentJokeLine == null)
            {
                return;
            }

            await Navigation.PushAsync(new JokeLineCreatorPage()
            {
                BindingContext = currentJokeLine
            });

            LblCurrentJoke.Text = "Druk op de Smiley!";
            currentJokeLine     = null;
        }
        private async Task TappedImage()
        {
            string jokeLineType = "";

            if (JokeLineTypePicker != null && JokeLineTypePicker.SelectedItem != null)
            {
                jokeLineType = (string)JokeLineTypePicker.SelectedItem;
            }

            JokeLine filteredJokeLine = await App.Database.GetJokeLineByFilter(jokeLineType);

            if (currentJokeLine != null && filteredJokeLine != null)
            {
                if (filteredJokeLine.Text.ToLower() == currentJokeLine.Text.ToLower())
                {
                    var allJokeLines = await App.Database.GetJokeLinesAsync();

                    var otherJokeLines = allJokeLines.Where(p => p.Text.ToLower() != filteredJokeLine.Text.ToLower()).ToList();

                    if (otherJokeLines != null && otherJokeLines.Count > 0)
                    {
                        if (otherJokeLines.Count() == 1)
                        {
                            filteredJokeLine = otherJokeLines[0];
                        }
                        else
                        {
                            filteredJokeLine = otherJokeLines[random.Next(0, otherJokeLines.Count)];
                        }
                    }
                }
            }

            if (filteredJokeLine != null)
            {
                LblCurrentJoke.Text = filteredJokeLine.Text;
                currentJokeLine     = filteredJokeLine;
            }
            else
            {
                LblCurrentJoke.Text = "Geen grappen gevonden!";
            }
        }