コード例 #1
0
        private void CreateMovie(Movie movie)
        {
            status.Content = "Creating Movie...";

            var call = svc.PostAsync(movie);
            if (call == null)
            {
                status.Content = "Post not yet implemented";
                return;
            }
            call.ContinueWith(
                task =>
                {
                    var result = task.Result;
                    synch.Post(
                        state =>
                        {
                            if (result != null && result.Error != null)
                            {
                                status.Content = "Error: " + result.Error;
                            }
                            else if (result != null && result.Movie != null)
                            {
                                AddToGrid(result.Movie);
                                status.Content = "Created Movie ID " + result.Movie.ID;
                            }
                            else
                            {
                                status.Content = "Error: Missing results";
                            }
                        },
                        null);
                    });
        }
コード例 #2
0
        // For the Post return a MovieResponse and populate the Movie property
        // if it's a successful call, otherwise populate the
        // Error property from Result.ReasonPhrase.
        public Task<MovieResponse> PostAsync(Movie movie)
        {
            var client = new HttpClient();

            // returning null to compile. replace with proper return
            // value when you implement this method;
            return null;
        }
コード例 #3
0
 void AddToGrid(Movie movie)
 {
     IEnumerable<Movie> movies = this.DataContext as IEnumerable<Movie>;
     if (movies != null)
     {
         var newMovies = movies.ToList();
         newMovies.Add(movie);
         this.DataContext = newMovies;
     }
 }
コード例 #4
0
ファイル: Movie.cs プロジェクト: ahaydara/html5_learning
 public Movie(Movie other)
 {
     this.ID = other.ID;
     this.Title = other.Title;
     this.Rating = other.Rating;
     this.YearReleased = other.YearReleased;
     this.Description = other.Description;
     this.Director = other.Director;
     this.Country = other.Country;
 }
コード例 #5
0
 public Task<MovieResponse> PutAsync(Movie movie)
 {
     var client = new HttpClient();
     var task = client.PutAsJsonAsync<Movie>(baseUrl + movie.ID, movie);
     return task.ContinueWith<MovieResponse>(
         innerTask =>
         {
             if (!task.Result.IsSuccessStatusCode)
             {
                 return new MovieResponse { Error = task.Result.ReasonPhrase };
             }
             return new MovieResponse();
         });
 }
コード例 #6
0
 public Task<MovieResponse> PostAsync(Movie movie)
 {
     var client = new HttpClient();
     var task = client.PostAsJsonAsync<Movie>(baseUrl, movie);
     return task.ContinueWith<MovieResponse>(
         innerTask =>
         {
             if (task.Result.IsSuccessStatusCode)
             {
                 var json = innerTask.Result.Content.ReadAsStringAsync().Result;
                 var newMovie = JsonConvert.DeserializeObject<Movie>(json);
                 return new MovieResponse
                 {
                     Movie = newMovie
                 };
             }
             else
             {
                 return new MovieResponse { Error = task.Result.ReasonPhrase };
             }
         });
 }
コード例 #7
0
        private void CreateMovie(Movie movie)
        {
            status.Content = "Creating Movie...";

            svc.PostAsync(movie).ContinueWith(
                task =>
                {
                    var result = task.Result;
                    synch.Post(
                        state =>
                        {
                            if (result.Error != null)
                            {
                                status.Content = "Error: " + result.Error;
                            }
                            else
                            {
                                AddToGrid(result.Movie);
                                status.Content = "Created Movie ID " + result.Movie.ID;
                            }
                        },
                        null);
                    });
        }
コード例 #8
0
        private void UpdateMovie(Movie movie)
        {
            status.Content = "Updating Movie...";

            var synch = SynchronizationContext.Current;

            var call = svc.PutAsync(movie);
            if (call == null)
            {
                status.Content = "Put not yet implemented";
                return;
            }
            call.ContinueWith(
                task =>
                {
                    var result = task.Result;
                    synch.Post(
                        state =>
                        {
                            if (result != null && result.Error != null)
                            {
                                status.Content = "Error: " + result.Error;
                            }
                            else
                            {
                                UpdateInGrid(movie);
                                status.Content = "Updated Movie ID " + movie.ID;
                            }
                        },
                        null);
                });
        }
コード例 #9
0
 void UpdateInGrid(Movie movie)
 {
     IEnumerable<Movie> movies = this.DataContext as IEnumerable<Movie>;
     if (movies != null)
     {
         var newMovies = movies.Where(x=>x.ID != movie.ID).ToList();
         newMovies.Add(movie);
         this.DataContext = newMovies;
     }
 }
コード例 #10
0
        private void UpdateMovie(Movie movie)
        {
            status.Content = "Updating Movie...";

            var synch = SynchronizationContext.Current;

            svc.PutAsync(movie).ContinueWith(
                task =>
                {
                    var result = task.Result;
                    synch.Post(
                        state =>
                        {
                            if (result.Error != null)
                            {
                                status.Content = "Error: " + result.Error;
                            }
                            else
                            {
                                UpdateInGrid(movie);
                                status.Content = "Updated Movie ID " + movie.ID;
                            }
                        },
                        null);
                });
        }