示例#1
0
        public static async Task <OMBdByTitleViewModel> GetMovieByTitle(string title)
        {
            if (title == null)
            {
                return(null);
            }

            var url = ENDPOINT_URL + "?t=" + title + API_KEY;

            try
            {
                using (var webClient = new WebClient())
                {
                    var result = await Task.Run(() => webClient.DownloadString(new Uri(url)));

                    if (result == null)
                    {
                        return(null);
                    }
                    OMBdModel OMBdmovie = JsonConvert.DeserializeObject <OMBdModel>(result);

                    if (OMBdmovie.Type == "movie")
                    {
                        OMBdByTitleViewModel viewModel = new OMBdByTitleViewModel(OMBdmovie);
                        return(viewModel);
                    }
                    else
                    {
                        return(MovieNotFound());
                    }
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
 // CTOR
 public OMBdByTitleViewModel(OMBdModel model)
 {
     Title    = model.Title;
     Year     = model.Year;
     Rated    = model.Rated;
     Released = model.Released;
     Runtime  = model.Runtime;
     Genre    = model.Genre;
     Director = model.Director;
     Writer   = model.Writer;
     Actors   = model.Actors;
     Plot     = model.Plot;
     Language = model.Language;
     Country  = model.Country;
     Awards   = model.Awards;
     if (IsValidUri(model.Poster))
     {
         Poster = new Uri(model.Poster);
     }
     Ratings    = model.Ratings;
     BoxOffice  = model.BoxOffice;
     Production = model.Production;
     Website    = model.Website;
 }