public Movie GetFromAPI(long id)
        {
            var movie = JsonFromURL <Movie> .ConvertToObject($"{host}/film/{id}{keyAPI}");

            //get and add poster
            var postrsIds = JsonFromURL <PostersByMovie> .ConvertToObject($"{host}/film/{id}/posters{keyAPI}");

            var posterUrl = $"{host}/film/poster/{postrsIds.Ids[0].Value}{keyAPI}&width=380&height=600&ratio=1";

            movie.PosterUrl = posterUrl;

            //banner
            //if (unitOfWork.Banners.Get(id) != null)
            //    movie.BannerUrl = unitOfWork.Banners.Get(id).Url;

            //get and add trailer
            var trailers = JsonFromURL <TrailersData> .ConvertToObject($"{host}/film/{id}/trailers{keyAPI}&size=1");

            var trailer = trailers.trailers.FirstOrDefault();

            movie.TrailerUrl = trailer.Url;

            //get and add images
            var imagesData = JsonFromURL <ImageData> .ConvertToObject($"{host}/film/{id}/images{keyAPI}");

            var images = new List <Image>();

            movie.Images = GetImages(id, imagesData, images);

            //get and add persons
            var personsByMovie = JsonFromURL <PersonesByMovie> .ConvertToObject($"{host}/film/{id}/persons{keyAPI}&size=max&detalization=FULL");

            var persons = GetPersons(id, personsByMovie);

            try
            {
                var director = persons.Find(p => p.ProfessionId == 1);
                movie.Director = $"{director.FirstName} {director.LastName}";
            }
            catch (Exception)
            {
            }



            StringBuilder actors = CreateActors(persons);

            movie.Actors = actors.ToString();

            StringBuilder counties = CreateCountries(movie);

            movie.Country = counties.ToString();

            StringBuilder genres = CreateGenres(movie);

            movie.Genre = genres.ToString();

            return(movie);
        }
        public Person ConvertToPerson(PersonModel personModel, long filmId)
        {
            if (filmId == personModel.FilmId && (personModel.ProfessionId == 1 || personModel.ProfessionId == 2))
            {
                Person person = JsonFromURL <Person> .ConvertToObject($"{host}/person/{personModel.PersonId}{keyAPI}");

                person.ProfessionId = personModel.ProfessionId;
                return(person);
            }
            return(null);
        }
        public void GetProffesionByIdAndAddToDb()
        {
            var professions = JsonFromURL <ProfessionsData> .ConvertToObject($"{host}/professions{keyAPI}&size=20");

            foreach (var item in professions.Professions)
            {
                unitOfWork.Professions.AddOrUpdate(item);
            }

            unitOfWork.Save();
        }
        public void GetAllGenresFromAPIAndAddToDb()
        {
            var genres = JsonFromURL <GenresData> .ConvertToObject($"{host}/genres{keyAPI}&size=90");

            foreach (var item in genres.Genres)
            {
                unitOfWork.Genres.AddOrUpdate(item);
            }

            unitOfWork.Save();
        }
        public void GetAllCountriesFromAPIAndAddToDb()
        {
            var countries = JsonFromURL <CountriesData> .ConvertToObject($"{host}/countries{keyAPI}&size=150");

            foreach (var item in countries.Countries)
            {
                unitOfWork.Countries.AddOrUpdate(item);
            }

            unitOfWork.Save();
        }
        public List <Movie> GetAllFromAPIByTheater(long id)
        {
            var moviesIds = JsonFromURL <MoviesByTheater> .ConvertToObject($"{host}/cinema/{id}/shows{keyAPI}&size=1000&detalization=FULL");

            var movies = new List <Movie>();

            foreach (var item in moviesIds.Movies)
            {
                var movie = GetFromAPI(item.Id);
                movies.Add(movie);
            }

            return(movies);
        }
        public void AddOrUpdate_GetAll_Delete_CinemaAPI()
        {
            var data = JsonFromURL <TestJsonModels> .ConvertToObject(@"http://kino-teatr.ua:8081/services/api/genres?apiKey=pol1kh111");

            Test test = new Test()
            {
                Id   = data.Models[0].Id,
                Name = data.Models[0].Name
            };

            testService.AddOrUpdateTest(test);

            Assert.AreEqual(testService.GetOne(test.Id).Name, test.Name);

            foreach (var item in testService.GetAll().ToList())
            {
                testService.Delete(item.Id);
            }
        }
Example #8
0
        public Theater GetFromAPI(long id)
        {
            var theater = JsonFromURL <Theater> .ConvertToObject($"{host}/cinema/{id}{keyAPI}");

            return(theater);
        }
 public SeanceData GetDataFromAPISeanceByMovieTheaterAndDate(long theaterId, long movieId, string date)
 {
     return(JsonFromURL <SeanceData> .ConvertToObject($"{host}/cinema/{theaterId}/film/{movieId}/shows{keyAPI}&size=10&date={date}&detalization=FULL"));
 }
        public List <Seance> GetAllFromAPISeanceByMovieAndTheater(long theaterId, long movieId)
        {
            var seanceData = JsonFromURL <SeanceData> .ConvertToObject($"{host}/cinema/{theaterId}/film/{movieId}/shows{keyAPI}&size=1000&detalization=FULL");

            return(seanceData.Seances);
        }
Example #11
0
        public void Get_Person_From_API_Add_And_Delete_To_DB_Test()
        {
            var person = JsonFromURL <Person> .ConvertToObject("http://kino-teatr.ua:8081/services/api/person/1155?apiKey=pol1kh111");

            Trace.WriteLine(person.LastName);
        }