Esempio n. 1
0
        public IEnumerable<Reservation> Get(int movie_id, int show_id)
        {
            CinemaContext context = new CinemaContext();
            MoviesController moviesController = new MoviesController(context);
            ShowsController showsController = new ShowsController(context);

            Movie movie = moviesController.Get(movie_id);
            if (movie != null)
            {
                Show show = showsController.Get(movie_id, show_id);
                if (show != null)
                {
                    return show.Reservations.Select(reservation =>
                    {
                        reservation.ParentShowId = show.Id;
                        return reservation;
                    });
                }
                else
                {
                    throw new Exception("invalid show id");
                }
            }
            else
            {
                throw new Exception("invalid movie id");
            }
        }
Esempio n. 2
0
        public async Task<object> AddNew(int movie_id, int show_id)
        {
            Reservation reservation;
            using (CinemaContext context = new CinemaContext())
            {
                ShowsController shows = new ShowsController(context);
                Show show = shows.Get(movie_id, show_id);

                string json = await this.Request.Content.ReadAsStringAsync();
                reservation = JsonConvert.DeserializeObject<Reservation>(json);

                if (reservation.TicketCount < 1)
                {
                    return new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        Content = new JsonHttpContent(new { Message = "Sie müssen mindestens eine Karte kaufen." })
                    };
                }

                if (show.FreeSeats - reservation.TicketCount < 0)
                {
                    return new HttpResponseMessage(HttpStatusCode.BadRequest)
                    {
                        Content = new JsonHttpContent(new { Message = "Für diese Vorstellung sind nicht mehr genug Plätze vorhanden." })
                    };
                }

                if (reservation.TicketCount > 10)
                {
                    return new HttpResponseMessage(HttpStatusCode.BadRequest)                    
                    {
                        Content = new JsonHttpContent(new { Message = "Es können nicht mehr als 10 Tickets online gebucht werden. Bitte rufen Sie uns an, wenn Sie Karten in dieser Menge bestellen möchten." })
                    };
                }

                reservation.ParentShowId = show.Id;
                show.Reservations.Add(reservation);

                context.SaveChanges();
            }

            // send notification to all clients
            GlobalHost.ConnectionManager.GetHubContext<ReservationHub>().Clients.All.newReservation(reservation);

            return reservation;
        }
Esempio n. 3
0
        protected void Application_Start()
        {
            Database.SetInitializer(new MigrateDatabaseToLatestVersion<CinemaContext, Configuration>());
            using (CinemaContext context = new CinemaContext())
            {
                var tmp = context.Movies.FirstOrDefault();
                if (tmp != null)
                {
                    tmp.Equals(null);
                }
            }

            RouteTable.Routes.MapHubs("/push", new HubConfiguration());

            GlobalConfiguration.Configuration.Formatters.Clear();
            GlobalConfiguration.Configuration.Formatters.Add(new JsonMediaTypeFormatter());

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
Esempio n. 4
0
 public MoviesController(CinemaContext context)
 {
     this.Context = context;
 }
Esempio n. 5
0
        public string CreateTestData()
        {
            using (CinemaContext context = new CinemaContext())
            {
                List<Movie> movies = new List<Movie>()
                {
                        new Movie
                        {
                            Id = 1,
                            CoverUrl = "http://images.kino.de/flbilder/max13/mbiz13/mbiz16/z1316507/b148x210.jpg",
                            MinimumAge = 12,
                            Name = "Fast & Furious 6"
                        },
                        new Movie
                        {
                            Id = 2,
                            CoverUrl = "http://images.kino.de/flbilder/max13/auto13/auto23/13230405/b148x210.jpg",
                            MinimumAge = 12,
                            Name = "Man of Steel"
                        },
                        new Movie
                        {
                            Id = 3,
                            CoverUrl = "http://images.kino.de/flbilder/max13/auto13/auto15/13150144/b148x210.jpg",
                            MinimumAge = 16,
                            Name = "World War Z"
                        },
                        new Movie
                        {
                            Id = 4,
                            CoverUrl = "http://images.kino.de/flbilder/max13/auto13/auto20/13200420/b148x210.jpg",
                            MinimumAge = 12,
                            Name = "Hangover 3"
                        },
                        new Movie
                        {
                            Id = 5,
                            CoverUrl = "http://images.kino.de/flbilder/max13/auto13/auto10/13100365/b148x210.jpg",
                            MinimumAge = 18,
                            Name = "Evil Dead"
                        },
                };

                foreach (var movie in movies)
                {
                    List<Show> shows = new List<Show>()
                    {
                        new Show()
                        {
                            MaxSeats = 50,
                            StartTime = DateTime.Now,
                        },
                        new Show()
                        {
                            MaxSeats = 50,
                            StartTime = DateTime.Now + TimeSpan.FromHours(2),
                        },
                        new Show()
                        {
                            MaxSeats = 50,
                            StartTime = DateTime.Now + TimeSpan.FromHours(4),
                        },
                        new Show()
                        {
                            MaxSeats = 50,
                            StartTime = DateTime.Now + TimeSpan.FromHours(6),
                        },
                    };

                    var list = new List<Show>();
                    list.AddRange(shows);
                    movie.Shows = list;

                    context.Movies.Add(movie);
                }

                context.SaveChanges();
            }

            return "ok";
        }
Esempio n. 6
0
 public string Test()
 {
     using(CinemaContext context = new CinemaContext())
     {
         Debugger.Break();
     }
     return "done";
 }
Esempio n. 7
0
 public ShowsController(CinemaContext context)
 {
     Context = context;
 }