コード例 #1
0
        public void testDeleteComment()
        {
            Console.WriteLine("Delete comment...");

            //NE PAS OUBLIER DE SET L'ID !!!
            _comment.Id = 24;
            //--------------------------

            _bllManager.DeleteComment(_comment);
            Console.WriteLine("Apres Delete comment...");

            FullFilmDTO film = _bllManager.GetFullFilmDetailsByIdFilm(11);

            Console.WriteLine("Film : \n" + film.ToStringAll());

            CommentDTO commentFromBd = _bllManager.getCommentFromId(_comment.Id);

            if (commentFromBd == null)
            {
                Console.WriteLine("commentaire bien supprimé");
            }
            else
            {
                Console.WriteLine("commentaire pas supprimé : " + commentFromBd);
            }

            Assert.Pass();
        }
コード例 #2
0
        public IActionResult Details(int id)
        {
            Trace.WriteLine("ID = " + id);

            request = ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFullFilmDetailsByIdFilm.Replace("{idFilm}", id.ToString());
            Trace.WriteLine(request);
            response = client.GetAsync(request).Result;
            Trace.WriteLine("Api Reponse: " + response.Content.ReadAsStringAsync().Result);

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception("http fail full film");
            }

            FullFilmDTO film = JsonSerializer.Deserialize <ResponsePagine <FullFilmDTO> >(response.Content.ReadAsStringAsync().Result, options).Value;

            Trace.WriteLine(film.Title);

            //poster path
            HttpResponseMessage r = client.GetAsync(ConfigurationManager.AppSettings["movieAPI"] + film.Id + ConfigurationManager.AppSettings["appendKey"]).Result;

            if (!r.IsSuccessStatusCode)
            {
                throw new Exception("http fail poster path");
            }

            string s       = r.Content.ReadAsStringAsync().Result;
            var    data    = (JObject)JsonConvert.DeserializeObject(s);
            string newPath = data["poster_path"].Value <string>();

            film.PosterPath = ConfigurationManager.AppSettings["pathToPoster"] + newPath + ConfigurationManager.AppSettings["appendKey"];


            return(View(film));
        }
コード例 #3
0
        public IActionResult GetFullFilmDetailsByIdFilm(int idFilm)
        {
            ResponseSingleObject <FullFilmDTO> responseSingleObject = new ResponseSingleObject <FullFilmDTO>()
            {
                Status   = StatusCodes.Status500InternalServerError,
                Errors   = null,
                Message  = null,
                Succeded = false,
                Value    = null
            };

            try
            {
                FullFilmDTO fullFilmDto = _bllManager.GetFullFilmDetailsByIdFilm(idFilm);
                if (fullFilmDto == null)
                {
                    responseSingleObject.Status = StatusCodes.Status404NotFound;
                    responseSingleObject.Errors = "aucun film trouve pour l id(" + idFilm + ")";
                }
                else
                {
                    responseSingleObject.Status = StatusCodes.Status200OK;
                    responseSingleObject.Value  = fullFilmDto;
                }
            }
            catch (Exception e)
            {
                responseSingleObject.Errors =
                    "GetFullFilmDetailsByIdFilm pour le film dont l id =(" + idFilm + ") EXCEPTION : " + e.ToString();
            }

            return(StatusCode(responseSingleObject.Status, responseSingleObject));
        }
コード例 #4
0
        public CommentView(int newId)
        {
            Trace.WriteLine("[CommentView]Debut");
            DataContext = this;
            InitializeComponent();

            _id = newId;

            options = new JsonSerializerOptions
            {
                PropertyNameCaseInsensitive = true
            };


            client2.BaseAddress = new Uri(ConfigurationManager.AppSettings["baseUrl"]);
            client2.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("application/json"));
            //recuperer le film
            //Charger le film

            HttpResponseMessage reponse2 = client2.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFullFilmDetailsByIdFilm.Replace("{idFilm}", Id.ToString())).Result;

            if (!reponse2.IsSuccessStatusCode)
            {
                Trace.WriteLine("[Error][ShellModel][getIcon]Api reponse on GetListGenreByIdFilm");
                App.Current.Shutdown();
            }

            _fullFilm = System.Text.Json.JsonSerializer.Deserialize <ResponseSingleObject <FullFilmDTO> >(reponse2.Content.ReadAsStringAsync().Result, options).Value;


            //List De comment test
            List <ListBoxComment> newList = new List <ListBoxComment>();

            _fullFilm.Comments.OrderBy(comment => comment.Date);
            foreach (CommentDTO c in _fullFilm.Comments)
            {
                newList.Add(new ListBoxComment()
                {
                    Comment = c.Content, Rate = c.Rate.ToString(), Date = c.Date.ToString(), Username = c.Username
                });
            }
            ListComment = newList;

            //Titre
            Titre = _fullFilm.Title;
            //Duree
            Duree = _fullFilm.Runtime.ToString();
            //List Actors
            ListActeur = _fullFilm.Actors;
        }
コード例 #5
0
        [TestCase(10)] //rien !
        public void testGetFullFilmDetailsByIdFilm(int idFilm)
        {
            BllManager  bllManager = new BllManager();
            FullFilmDTO film       = bllManager.GetFullFilmDetailsByIdFilm(idFilm);

            if (film != null)
            {
                Console.WriteLine("Film pour l'id(" + idFilm + ") : \n" + film.ToStringAll());
            }
            else
            {
                Console.WriteLine("Pas de Film trouvé pour l'id : " + idFilm);
            }

            Assert.Pass();
        }
コード例 #6
0
        public void testInsertComment()
        {
            Console.WriteLine("insert comment...");
            _bllManager.InsertComment(_comment);
            Console.WriteLine("insert comment ok : affichage à partir de la lecture de la bd :");

            FullFilmDTO film      = _bllManager.GetFullFilmDetailsByIdFilm(_comment.Film.Id);
            int         idComment = 0;

            foreach (CommentDTO filmComment in film.Comments)
            {
                idComment = filmComment.Id;
            }

            Console.WriteLine("Film : \n" + film.ToStringAll());

            _comment = _bllManager.getCommentFromId(idComment);
            Console.WriteLine("Comment : \n" + _comment.ToStringWithFilm());

            Assert.Pass();
        }
コード例 #7
0
        private void BouttonAjouter_Click(object sender, RoutedEventArgs e)
        {
            if (TextBoxCommentaire.Text.Length != 0 && TextBoxNom.Text.Length != 0 && TextBoxNote.Text.Length != 0)
            {
                CommentDTO newComment = new CommentDTO(TextBoxCommentaire.Text, int.Parse(TextBoxNote.Text), TextBoxNom.Text, DateTime.Now, _fullFilm);

                var jsonText = JsonConvert.SerializeObject(newComment);

                //api
                var content = new StringContent(jsonText, Encoding.UTF8, "application/json");

                var message = client2.PostAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Comments.CommentBase + "/" + ApiRoute.Comments.InsertComment, content);

                Trace.WriteLine(message.Result.Content.ReadAsStringAsync().Result);

                HttpResponseMessage reponse2 = client2.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFullFilmDetailsByIdFilm.Replace("{idFilm}", Id.ToString())).Result;
                if (!reponse2.IsSuccessStatusCode)
                {
                    Trace.WriteLine("[Error][ShellModel][getIcon]Api reponse on GetListGenreByIdFilm");
                    App.Current.Shutdown();
                }

                _fullFilm = System.Text.Json.JsonSerializer.Deserialize <ResponseSingleObject <FullFilmDTO> >(reponse2.Content.ReadAsStringAsync().Result, options).Value;

                //List De comment test
                List <ListBoxComment> newList = new List <ListBoxComment>();
                _fullFilm.Comments.OrderBy(comment => comment.Date);
                foreach (CommentDTO c in _fullFilm.Comments)
                {
                    newList.Add(new ListBoxComment()
                    {
                        Comment = c.Content, Rate = c.Rate.ToString(), Date = c.Date.ToString(), Username = c.Username
                    });
                }
                ListComment = newList;
            }
        }
コード例 #8
0
        public void LoadCurrentPage(string searchText)
        {
            _currentFilmNumber = 0;
            _nextFilmNumber    = 0;
            Trace.WriteLine("\n\nSearchText: " + searchText);
            if (searchText == null || searchText.Length == 0)
            {
                //Charge les 5 premier films
                //Recuperer le nombre de film dans le db
                Trace.WriteLine("[LoadCurrentPage]Api Call: " + ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetNumberFilmsFromTo);
                HttpResponseMessage r = client.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetNumberFilmsFromTo).Result;

                Trace.WriteLine("[LoadCurrentPage]Api Response: " + r.Content.ReadAsStringAsync().Result);

                if (!r.IsSuccessStatusCode)
                {
                    Trace.WriteLine("[Error][ShellModel]Api reponse on count");
                    App.Current.Shutdown();
                }

                _filmCount = JsonSerializer.Deserialize <ResponseSingleObject <int> >(r.Content.ReadAsStringAsync().Result, options).Value;

                Trace.WriteLine("[LoadCurrentPage]Film count: " + _filmCount);

                if (_filmCount == 0)
                {
                    _currentFilmNumber = 0;
                    _nextFilmNumber    = 0;
                    _listFilmDTO       = new List <FilmDTO>();
                    _listFullFilmDTO   = new List <FullFilmDTO>();
                    return;
                }

                if (_currentFilmNumber + 5 > _filmCount)
                {
                    _nextFilmNumber = _filmCount - _currentFilmNumber;
                }
                else
                {
                    _nextFilmNumber = _currentFilmNumber + 5;
                }

                //Recuperer les premiers films
                Trace.WriteLine("[LoadCurrentPage]Api Call: " + ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFilmsFromTo.Replace("{from}", _currentFilmNumber.ToString()).Replace("{to}", _nextFilmNumber.ToString()));
                HttpResponseMessage r2 = client.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFilmsFromTo.Replace("{from}", _currentFilmNumber.ToString()).Replace("{to}", _nextFilmNumber.ToString())).Result;
                Trace.WriteLine("[LoadCurrentPage]Api Response: " + r2.Content.ReadAsStringAsync().Result);

                if (!r2.IsSuccessStatusCode)
                {
                    Trace.WriteLine("[Error][LoadCurrentPage]Api reponse on _listFilmDTO");
                }

                _listFilmDTO = JsonSerializer.Deserialize <ResponsePagine <List <FilmDTO> > >(r2.Content.ReadAsStringAsync().Result, options).Value;

                //Remplir les 5 fullFilmDTO
                for (int i = 0; i < 5; i++)
                {
                    FilmDTO             f  = _listFilmDTO.ElementAt(i);
                    HttpResponseMessage r3 = client.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFullFilmDetailsByIdFilm.Replace("{idFilm}", f.Id.ToString())).Result;
                    if (!r3.IsSuccessStatusCode)
                    {
                        Trace.WriteLine("[Error][LoadCurrentPage]Load 5 Film");
                        App.Current.Shutdown();
                    }

                    FullFilmDTO fullFilm = JsonSerializer.Deserialize <ResponseSingleObject <FullFilmDTO> >(r3.Content.ReadAsStringAsync().Result, options).Value;
                    _listFullFilmDTO.Add(fullFilm);
                }
            }
            else
            {
                //Charge les 5 premier films avec titre
                //Recuperer le nombre de film dans le db

                string request = ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetNumberFilmsByPartialTitle.Replace("{titre}", searchText);
                Trace.WriteLine("Api Call: " + request);
                HttpResponseMessage r = client.GetAsync(request).Result;

                Trace.WriteLine("[LoadCurrentPage]Api Response: " + r.Content.ReadAsStringAsync().Result);

                if (!r.IsSuccessStatusCode)
                {
                    Trace.WriteLine("[Error][ShellModel]Api reponse on count");
                    App.Current.Shutdown();
                }

                _filmCount = JsonSerializer.Deserialize <ResponseSingleObject <int> >(r.Content.ReadAsStringAsync().Result, options).Value;

                if (_filmCount == 0)
                {
                    _currentFilmNumber = 0;
                    _nextFilmNumber    = 0;
                    _listFilmDTO       = new List <FilmDTO>();
                    _listFullFilmDTO   = new List <FullFilmDTO>();
                    return;
                }

                Trace.WriteLine("[LoadCurrentPage]Film count: " + _filmCount);

                if (_currentFilmNumber + 5 > _filmCount)
                {
                    _nextFilmNumber = _filmCount - _currentFilmNumber;
                }
                else
                {
                    _nextFilmNumber = _currentFilmNumber + 5;
                }

                //Recuperer les premiers films

                string request2 = ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.FindFilmsByPartialTitle.Replace("{from}", _currentFilmNumber.ToString()).Replace("{to}", _nextFilmNumber.ToString()).Replace("{titre}", searchText);
                Trace.WriteLine("[LoadCurrentPage]Api Call: " + request2);
                HttpResponseMessage r2 = client.GetAsync(request2).Result;
                Trace.WriteLine("[LoadCurrentPage]Api Response: " + r2.Content.ReadAsStringAsync().Result);

                if (!r2.IsSuccessStatusCode)
                {
                    Trace.WriteLine("[Error][LoadCurrentPage]Api reponse on _listFilmDTO");
                    App.Current.Shutdown();
                }

                _listFilmDTO = JsonSerializer.Deserialize <ResponsePagine <List <FilmDTO> > >(r2.Content.ReadAsStringAsync().Result, options).Value;

                if (_listFilmDTO == null)
                {
                    _listFilmDTO = new List <FilmDTO>();
                }

                //Remplir les 5 fullFilmDTO
                for (int i = 0; i < 5; i++)
                {
                    if (_listFilmDTO.Count <= i)
                    {
                        //Si il n'y a pas de film
                        break;
                    }
                    FilmDTO             f  = _listFilmDTO.ElementAt(i);
                    HttpResponseMessage r3 = client.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFullFilmDetailsByIdFilm.Replace("{idFilm}", f.Id.ToString())).Result;
                    if (!r3.IsSuccessStatusCode)
                    {
                        Trace.WriteLine("[Error][LoadCurrentPage]Load 5 Film");
                        App.Current.Shutdown();
                    }

                    FullFilmDTO fullFilm = JsonSerializer.Deserialize <ResponseSingleObject <FullFilmDTO> >(r3.Content.ReadAsStringAsync().Result, options).Value;
                    _listFullFilmDTO.Add(fullFilm);
                }
            }
        }
コード例 #9
0
        public void loadPreviousMovies(string searchText)
        {
            if (searchText == null || searchText.Length == 0)
            {
                if (_currentFilmNumber - 5 <= 0)
                {
                    return;
                }

                if (_currentFilmNumber - 5 <= 0)
                {
                    _currentFilmNumber -= 5;
                    _nextFilmNumber     = _filmCount - _currentFilmNumber;
                }
                else
                {
                    _currentFilmNumber -= 5;
                    _nextFilmNumber     = _currentFilmNumber - 5;
                }



                _listFullFilmDTO = new List <FullFilmDTO>();
                _listFilmDTO     = new List <FilmDTO>();

                //Recuperer les 5 premiers films
                Trace.WriteLine("Api Call: " + ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFilmsFromTo.Replace("{from}", _currentFilmNumber.ToString()).Replace("{to}", (_nextFilmNumber).ToString()));
                HttpResponseMessage reponse = client.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFilmsFromTo.Replace("{from}", _currentFilmNumber.ToString()).Replace("{to}", (_nextFilmNumber).ToString())).Result;

                if (!reponse.IsSuccessStatusCode)
                {
                    Trace.WriteLine("[Error][ShellModel]Api reponse on _listFilmDTO");
                    return;
                }

                _listFilmDTO = JsonSerializer.Deserialize <ResponsePagine <List <FilmDTO> > >(reponse.Content.ReadAsStringAsync().Result, options).Value;



                //Remplir les 5 fullFilmDTO
                for (int i = 0; i < 5; i++)
                {
                    if (_listFilmDTO.Count <= i)
                    {
                        //Si il n'y a pas de film
                        break;
                    }
                    FilmDTO             f        = _listFilmDTO.ElementAt(i);
                    HttpResponseMessage reponse2 = client.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFullFilmDetailsByIdFilm.Replace("{idFilm}", f.Id.ToString())).Result;
                    if (!reponse2.IsSuccessStatusCode)
                    {
                        Trace.WriteLine("[Error][ShellModel][getIcon]Api reponse on GetListGenreByIdFilm");
                        App.Current.Shutdown();
                    }

                    FullFilmDTO fullFilm = JsonSerializer.Deserialize <ResponseSingleObject <FullFilmDTO> >(reponse2.Content.ReadAsStringAsync().Result, options).Value;
                    _listFullFilmDTO.Add(fullFilm);
                }
            }
            else
            {
                if (_currentFilmNumber - 5 <= 0)
                {
                    return;
                }

                if (_currentFilmNumber - 5 <= 0)
                {
                    _currentFilmNumber -= 5;
                    _nextFilmNumber     = _filmCount - _currentFilmNumber;
                }
                else
                {
                    _currentFilmNumber -= 5;
                    _nextFilmNumber     = _currentFilmNumber - 5;
                }



                _listFullFilmDTO = new List <FullFilmDTO>();
                _listFilmDTO     = new List <FilmDTO>();

                string request2 = ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.FindFilmsByPartialTitle.Replace("{from}", _currentFilmNumber.ToString()).Replace("{to}", _nextFilmNumber.ToString()).Replace("{titre}", searchText);
                Trace.WriteLine("[LoadCurrentPage]Api Call: " + request2);
                HttpResponseMessage r2 = client.GetAsync(request2).Result;
                Trace.WriteLine("[LoadCurrentPage]Api Response: " + r2.Content.ReadAsStringAsync().Result);

                if (!r2.IsSuccessStatusCode)
                {
                    Trace.WriteLine("[Error][LoadCurrentPage]Api reponse on _listFilmDTO");
                    App.Current.Shutdown();
                }

                _listFilmDTO = JsonSerializer.Deserialize <ResponsePagine <List <FilmDTO> > >(r2.Content.ReadAsStringAsync().Result, options).Value;

                if (_listFilmDTO == null)
                {
                    _listFilmDTO = new List <FilmDTO>();
                }

                //Remplir les 5 fullFilmDTO
                for (int i = 0; i < 5; i++)
                {
                    if (_listFilmDTO.Count <= i)
                    {
                        //Si il n'y a pas de film
                        break;
                    }
                    FilmDTO             f  = _listFilmDTO.ElementAt(i);
                    HttpResponseMessage r3 = client.GetAsync(ConfigurationManager.AppSettings["baseUrl"] + ApiRoute.Films.FilmBase + "/" + ApiRoute.Films.GetFullFilmDetailsByIdFilm.Replace("{idFilm}", f.Id.ToString())).Result;
                    if (!r3.IsSuccessStatusCode)
                    {
                        Trace.WriteLine("[Error][LoadCurrentPage]Load 5 Film");
                        App.Current.Shutdown();
                    }

                    FullFilmDTO fullFilm = JsonSerializer.Deserialize <ResponseSingleObject <FullFilmDTO> >(r3.Content.ReadAsStringAsync().Result, options).Value;
                    _listFullFilmDTO.Add(fullFilm);
                }
            }
        }