Esempio n. 1
0
 public List<Genre> ReadAll()
 {
     using (var ctx = new MovieShopContext())
     {
         return ctx.Genres.ToList();
     }
 }
Esempio n. 2
0
 public Customer Find(int ID)
 {
     using (var ctx = new MovieShopContext())
     {
         return Find(ID, ctx);
     }
 }
Esempio n. 3
0
 public List<Customer> FindAll()
 {
     using (var ctx = new MovieShopContext())
     {
         return ctx.Customers.ToList();
     }
 }
Esempio n. 4
0
 public Customer FindByEmail(string email)
 {
     using (var ctx = new MovieShopContext())
     {
         return FindByEmail(email, ctx);
     }
 }
Esempio n. 5
0
 public void Add(Customer customer)
 {
     using (var ctx = new MovieShopContext())
     {
         ctx.Customers.Add(customer);
         ctx.SaveChanges();
     }
 }
Esempio n. 6
0
 public void Delete(int ID)
 {
     using (var ctx = new MovieShopContext())
     {
         ctx.Customers.Remove(Find(ID, ctx));
         ctx.SaveChanges();
     }
 }
Esempio n. 7
0
 public void Edit(Order order)
 {
     using (var ctx = new MovieShopContext())
     {
         var dbOrder = Find(order.ID, ctx);
         dbOrder.Date = order.Date;
         ctx.SaveChanges();
     }
 }
Esempio n. 8
0
 public void Add(Genre genre)
 {
     using (var ctx = new MovieShopContext())
     {
         //Create the queries
         ctx.Genres.Add(genre);
         //Execute the queries
         ctx.SaveChanges();
     }
 }
Esempio n. 9
0
 //Addding Order, making sure to attach customer, such no new customer would be made and use existing customer instead
 public void Add(Order order)
 {
     using (var ctx = new MovieShopContext())
     {
         ctx.Customers.Attach(order.Customer);
         order.OrderLines.ForEach(x => ctx.Movies.Attach(x.Movie));
         ctx.Orders.Add(order);
         ctx.SaveChanges();
     }
 }
Esempio n. 10
0
        public void Delete(int customerId)
        {
            Customer customer = FindCustomer(customerId);

            {
                using (var ctx = new MovieShopContext())
                {
                    ctx.Customers.Attach(customer);
                    ctx.Customers.Remove(customer);
                    ctx.SaveChanges();
                }
            }
        }
Esempio n. 11
0
        public void Edit(Customer customer)
        {
            using (var ctx = new MovieShopContext())
            {
                var dbCustomer = Find(customer.ID, ctx);
                dbCustomer.FirstName = customer.FirstName;
                dbCustomer.LastName = customer.LastName;
                dbCustomer.Email = customer.Email;
                dbCustomer.Address = customer.Address;

                ctx.SaveChanges();
            }
        }
Esempio n. 12
0
        public void Update(Genre genre)
        {
            using (var ctx = new MovieShopContext())
            {
                foreach (var movieDB in ctx.Genres.ToList())
                {
                    if (genre.Id == movieDB.Id)
                    {
                        movieDB.Name = genre.Name;
                        ctx.SaveChanges();

                    }
                }
            }
        }
Esempio n. 13
0
        public void Delete(int movieId)
        {
            Movie movie = FindMovie(movieId);
            try {
            using (var ctx = new MovieShopContext())
            {
                ctx.Movies.Attach(movie);
                ctx.Movies.Remove(movie);
                ctx.SaveChanges();
            }
            }
            catch (DbUpdateConcurrencyException)
            {

            }
        }
Esempio n. 14
0
        public void Delete(int genreId)
        {
            Genre genre = FindGenre(genreId);
            try
            {
                using (var ctx = new MovieShopContext())
                {
                    ctx.Genres.Attach(genre);
                    ctx.Genres.Remove(genre);
                    ctx.SaveChanges();
                }
            }
            catch (DbUpdateConcurrencyException)
            {

            }
        }
Esempio n. 15
0
        public void Update(Customer customer)
        {
            using (var ctx = new MovieShopContext())
            {
                foreach (var movieDB in ctx.Customers.ToList())
                {
                    if (customer.Id == movieDB.Id)
                    {
                        movieDB.Name = customer.Name;
                        movieDB.Email = customer.Email;
                        movieDB.Password = customer.Password;
                        ctx.SaveChanges();

                    }
                }
            }
        }
Esempio n. 16
0
 private Customer FindByEmail(string email, MovieShopContext context)
 {
     return context.Customers.FirstOrDefault(c => c.Email == email);
 }
Esempio n. 17
0
 private Customer Find(int ID, MovieShopContext context)
 {
     return context.Customers.FirstOrDefault(c => c.ID == ID);
 }
Esempio n. 18
0
 private Order Find(int ID, MovieShopContext ctx)
 {
     return ctx.Orders.FirstOrDefault(c => c.ID == ID);
 }
Esempio n. 19
0
        public void Update(Movie movie)
        {
            using (var ctx = new MovieShopContext())
            {
                foreach (var movieDB in ctx.Movies.ToList())
                {
                    if (movie.Id == movieDB.Id)
                    {
                        movieDB.Title = movie.Title;
                        movieDB.ReleaseDate = movie.ReleaseDate;
                        movieDB.Price = movie.Price;
                        movieDB.TrailerURL = movie.TrailerURL;
                        movieDB.PictureURL = movie.PictureURL;
                        movieDB.Rating = movie.Rating;
                        movieDB.PlotDescription = movie.PlotDescription;
                        //movieDB.Genres = movie.Genres;
                        ctx.SaveChanges();

                    }
                }
            }
        }
Esempio n. 20
0
        public List<Movie> ReadAll()
        {
            try {
                using (var ctx = new MovieShopContext())
                {
                    return ctx.Movies.Include("Genres").ToList();

                }
            }
            catch (Exception e) {
                    return null;
            }
        }