Exemplo n.º 1
0
        public void NewInstance_DateSession_Should_Return_OK()
        {
            var result = new DateSession();

            Assert.IsNotNull(result.Bundles);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get sessions of movie in Galaxy vendor
        /// </summary>
        /// <param name="movieId">ID of the movie</param>
        /// <returns></returns>
        public async Task <List <SessionMovie> > GetSessionOfMovie(string movieId)
        {
            List <SessionMovie> result = new List <SessionMovie>();

            var reqResult = await _httpHandler.GetAsync(string.Format(URL_SESSION_OF_MOVIE, movieId));

            string content = await reqResult.Content.ReadAsStringAsync();

            JArray jArr = (JArray)JsonConvert.DeserializeObject(content);

            foreach (JObject item in jArr)
            {
                var tmpResult = new SessionMovie();
                tmpResult.CinemaName    = item["name"] != null ? item["name"].ToString() : string.Empty;
                tmpResult.CinemaPhone   = item["phone"] != null ? item["phone"].ToString() : string.Empty;
                tmpResult.CinemaAddress = item["address"] != null ? item["address"].ToString() : string.Empty;
                tmpResult.Longitude     = item["longitude"] != null ? (double)item["longitude"] : 0;
                tmpResult.Latitude      = item["latitude"] != null ? (double)item["latitude"] : 0;

                // Dates
                if (item["dates"] != null)
                {
                    foreach (var date in item["dates"].Children().ToList())
                    {
                        DateSession dateSession = new DateSession();
                        dateSession.ShowDate = date["showDate"] != null?DateTime.ParseExact(date["showDate"].ToString(), "dd/MM/yyyy", CultureInfo.InvariantCulture) : DateTime.MinValue;

                        dateSession.DayOfWeekLabel = date["dayOfWeekLabel"] != null ? date["dayOfWeekLabel"].ToString() : string.Empty;

                        // Bundles
                        if (date["bundles"] != null)
                        {
                            foreach (var bundle in date["bundles"].Children().ToList())
                            {
                                Bundle b = new Bundle();
                                b.Caption = bundle["caption"] != null ? bundle["caption"].ToString() : string.Empty;
                                b.Version = bundle["version"] != null ? bundle["version"].ToString() : string.Empty;

                                // Session
                                if (bundle["sessions"] != null)
                                {
                                    foreach (var session in bundle["sessions"].Children().ToList())
                                    {
                                        Session s = new Session();
                                        s.CinemaId       = session["cinemaId"] != null ? session["cinemaId"].ToString() : string.Empty;
                                        s.SeatsAvailable = session["seatsAvailable"] != null ? (int)session["cinemaId"] : 0;
                                        s.ScreenNumber   = session["screenNumber"] != null ? session["screenNumber"].ToString() : string.Empty;
                                        s.ScreenName     = session["screenName"] != null ? session["screenName"].ToString() : string.Empty;
                                        s.ShowTime       = session["showTime"] != null ? session["showTime"].ToString() : string.Empty;

                                        b.Sessions.Add(s);
                                    }
                                }
                                // End Sesion
                                dateSession.Bundles.Add(b);
                            }
                        }
                        // End Bundles

                        tmpResult.Dates.Add(dateSession);
                    }
                }
                // End Dates

                result.Add(tmpResult);
            }

            return(result);
        }