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

            {
                using (var ctx = new MovieShopContext())
                {
                    ctx.Customers.Attach(customer);
                    ctx.Customers.Remove(customer);
                    ctx.SaveChanges();
                }
            }
        }
        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();
            }
        }
Exemple #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();

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

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

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

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

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

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