Пример #1
0
        public AddJokeView() : base(UITableViewStyle.Grouped, null)
        {
            var title = new EntryElement("Title", "Enter the joke title", String.Empty);
            var name  = new EntryElement("Name", "Enter your name", String.Empty);
            var desc  = new SimpleMultilineEntryElement(String.Empty, String.Empty)
            {
                Editable = true
            };

            this.Pushing = true;

            Root = new RootElement("Submit Joke")
            {
                new Section("")
                {
                    title,
                },
                new Section("")
                {
                    name
                },
                new Section("Enter your joke below")
                {
                    desc
                },
            };

            this.NavigationItem.SetRightBarButtonItem(
                new UIBarButtonItem(UIBarButtonSystemItem.Save, (sender, args) => {
                string jokeTitle = title.Value;
                string jokeDesc  = desc.Value;
                string AddedBy   = name.Value;

                //validate

                if (jokeTitle == String.Empty || jokeDesc == String.Empty || AddedBy == String.Empty)
                {
                    new UIAlertView("Invalid Entry", "All fields are required.", null, "ok", null).Show();
                }
                else
                {
                    Downloader downloader = new Downloader();
                    DisplayProgress("Submitting Joke");

                    Task.Factory.StartNew(() => {
                        Joke newJoke     = new Joke();
                        newJoke.Title    = jokeTitle;
                        newJoke.JokeDesc = jokeDesc;
                        newJoke.Tags     = jokeTitle;
                        newJoke.AddedBy  = AddedBy;

                        success = downloader.AddJoke(newJoke);
                    }).ContinueWith(task3 => {
                        HideProgress();
                        View.BackgroundColor = UIColor.White;

                        if (success > 0)
                        {
                            new UIAlertView("Joke Submitted", "Thank you! Your joke will be posted after review.", null, "ok", null).Show();
                            this.NavigationController.PopViewControllerAnimated(true);
                        }
                        else
                        {
                            new UIAlertView("Joke Not Submitted", "Uh oh something went wrong.  Please try again.", null, "ok", null).Show();
                        }
                    },
                                    TaskScheduler.FromCurrentSynchronizationContext());
                }
            }), true);
        }