예제 #1
0
 public static void InitDb(CinemaBoxDb db)
 {
     if (!db.MovieShows.Any())
     {
         var movieShows = Enumerable.Range(1, 10).Select(i =>
                                                         new MovieShow
         {
             BeginTime = DateTime.Now,
             Name      = $"Киносеанс с фильмом № {i}",
         }).ToArray();
         db.MovieShows.AddRange(movieShows);
         db.SaveChanges();
         if (!db.Orders.Any())
         {
             var orders = Enumerable.Range(1, 20).Select(i =>
                                                         new Order
             {
                 DateTime  = DateTime.Now.AddHours(-2),
                 Count     = rnd.Next(1, 5),
                 MovieShow = movieShows[rnd.Next(movieShows.Length)],
             }).ToArray();
             db.Orders.AddRange(orders);
             db.SaveChanges();
         }
     }
 }
 public int Add(MovieShow item)
 {
     _db.Set <MovieShow>().Add(item);
     _db.SaveChanges();
     return(item.Id);
 }
 public int Add(Order item)
 {
     _db.Set <Order>().Add(item);
     _db.SaveChanges();
     return(item.Id);
 }