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;
        }
 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
 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 };
             }
         });
 }
        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);
                    });
        }
        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);
                });
        }
 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);
                });
        }