Example #1
0
 public List<Genre> ReadAll()
 {
     using (var ctx = new MovieShopContext())
     {
         return ctx.Genres.ToList();
     }
 }
Example #2
0
 public Customer Find(int ID)
 {
     using (var ctx = new MovieShopContext())
     {
         return Find(ID, ctx);
     }
 }
Example #3
0
 public List<Customer> FindAll()
 {
     using (var ctx = new MovieShopContext())
     {
         return ctx.Customers.ToList();
     }
 }
Example #4
0
 public Customer FindByEmail(string email)
 {
     using (var ctx = new MovieShopContext())
     {
         return FindByEmail(email, ctx);
     }
 }
Example #5
0
 public void Add(Customer customer)
 {
     using (var ctx = new MovieShopContext())
     {
         ctx.Customers.Add(customer);
         ctx.SaveChanges();
     }
 }
Example #6
0
 public void Delete(int ID)
 {
     using (var ctx = new MovieShopContext())
     {
         ctx.Customers.Remove(Find(ID, ctx));
         ctx.SaveChanges();
     }
 }
Example #7
0
 public void Edit(Order order)
 {
     using (var ctx = new MovieShopContext())
     {
         var dbOrder = Find(order.ID, ctx);
         dbOrder.Date = order.Date;
         ctx.SaveChanges();
     }
 }
Example #8
0
 public void Add(Genre genre)
 {
     using (var ctx = new MovieShopContext())
     {
         //Create the queries
         ctx.Genres.Add(genre);
         //Execute the queries
         ctx.SaveChanges();
     }
 }
Example #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();
     }
 }
Example #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();
                }
            }
        }
Example #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();
            }
        }
Example #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();

                    }
                }
            }
        }
Example #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)
            {

            }
        }
Example #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)
            {

            }
        }
Example #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();

                    }
                }
            }
        }
Example #16
0
 private Customer FindByEmail(string email, MovieShopContext context)
 {
     return context.Customers.FirstOrDefault(c => c.Email == email);
 }
Example #17
0
 private Customer Find(int ID, MovieShopContext context)
 {
     return context.Customers.FirstOrDefault(c => c.ID == ID);
 }
Example #18
0
 private Order Find(int ID, MovieShopContext ctx)
 {
     return ctx.Orders.FirstOrDefault(c => c.ID == ID);
 }
Example #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();

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

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