public List<Customer> ReadAll()
 {
     using (var ctx = new MovieStoreContext())
     {
         return ctx.Customers.ToList();
     }
 }
 public List<Movie> ReadAll()
 {
     using (var ctx = new MovieStoreContext())
     {
         return ctx.Movies.Include(x => x.Genre).ToList();
     }
 }
 public OrderLine GetOrderLine(int id)
 {
     using (var ctx = new MovieStoreContext())
     {
         return ctx.OrderLines.Include(x => x.Movie).Include(x => x.Order).Where(x => x.OrderId == id).FirstOrDefault();
     }
 }
        public Movie GetMovie(int id)
        {
            using (var ctx = new MovieStoreContext())
            {

                return ctx.Movies.Include(x => x.Genre).Where(x => x.Id == id).FirstOrDefault();
            }
        }
        public List<OrderLine> ReadAll(int id)
        {
            using (var ctx = new MovieStoreContext())
            {

                return ctx.OrderLines.Include(x => x.Order).Include(x => x.Movie).ToList();
            }
        }
        public Customer GetCustomer(int id)
        {
            using (var ctx = new MovieStoreContext())
            {

                return ctx.Customers.Where(x => x.Id == id).FirstOrDefault();
            }
        }
        public Genre GetGenre(int id)
        {
            using (var ctx = new MovieStoreContext())
            {

                return ctx.Genres.Where(x => x.Id == id).FirstOrDefault();
            }
        }
        public List<Genre> ReadAll()
        {
            using (var ctx = new MovieStoreContext())
            {

                return ctx.Genres.ToList();
            }
        }
 public void Add(Movie movie)
 {
     using (var ctx = new MovieStoreContext())
     {
         ctx.Movies.Add(movie);
         ctx.SaveChanges();
     }
 }
        public void Add(Customer customer)
        {
            using (var ctx = new MovieStoreContext())
            {

                ctx.Customers.Add(customer);
                ctx.SaveChanges();
            }
        }
        public void Add(OrderLine orderLine)
        {
            using (var ctx = new MovieStoreContext())
            {

                ctx.OrderLines.Add(orderLine);
                ctx.SaveChanges();
            }
        }
        public void Add(Genre genre)
        {
            using (var ctx = new MovieStoreContext())
            {

                ctx.Genres.Add(genre);
                ctx.SaveChanges();
            }
        }
 public void UpdateGenre(Genre genre)
 {
     using (var ctx = new MovieStoreContext())
     {
         Genre m = ctx.Genres.Where(x => x.Id == genre.Id).First();
         m.Id = genre.Id;
         m.Name = genre.Name;
         ctx.SaveChanges();
     }
 }
        public void DeleteCustomer(int id)
        {
            using (var ctx = new MovieStoreContext())
            {

                Customer m = ctx.Customers.Where(x => x.Id == id).First();
                if (m != null)
                    ctx.Customers.Remove(m);
                ctx.SaveChanges();
            }
        }
        public void DeleteGenre(int id)
        {
            using (var ctx = new MovieStoreContext())
            {

                Genre m = ctx.Genres.Where(x => x.Id == id).First();
                if (m != null)
                    ctx.Genres.Remove(m);
                ctx.SaveChanges();
            }
        }
 public void UpdateOrderLine(OrderLine orderLine)
 {
     using (var ctx = new MovieStoreContext())
     {
         OrderLine m = ctx.OrderLines.Where(x => x.OrderId == orderLine.OrderId).First();
         m.Amount = orderLine.Amount;
         m.OrderId = orderLine.OrderId;
         m.MovieId = orderLine.MovieId;
         m.Movie = orderLine.Movie;
         m.Order = orderLine.Order;
         ctx.SaveChanges();
     }
 }
 public void UpdateCustomer(Customer customer)
 {
     using (var ctx = new MovieStoreContext())
     {
         Customer m = ctx.Customers.Where(x => x.Id == customer.Id).First();
         m.FirstName = customer.FirstName;
         m.LastName = customer.LastName;
         m.Address = customer.Address;
         m.Email = customer.Email;
         m.orders = customer.orders;
         ctx.SaveChanges();
     }
 }
 public void UpdateMovie(Movie movie)
 {
     using (var ctx = new MovieStoreContext())
     {
         Movie m = ctx.Movies.Where(x => x.Id == movie.Id).First();
         m.ImageUrl = movie.ImageUrl;
         m.Title = movie.Title;
         m.Price = movie.Price;
         m.Year = movie.Year;
         m.TralierUrl = movie.TralierUrl;
         m.Genre = movie.Genre;
         m.GenreId = movie.GenreId;
         ctx.SaveChanges();
     }
 }