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"; }
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; }