Example #1
0
        public int Insert()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    tblCustomer customer = new tblCustomer
                    {
                        FirstName = this.FirstName,
                        LastName  = this.LastName,
                        Address   = this.Address,
                        City      = this.City,
                        Phone     = this.Phone,
                        State     = this.State,
                        UserId    = this.UserId,
                        ZIP       = this.ZIP,
                        Id        = dc.tblCustomers.Any() ? dc.tblCustomers.Max(c => c.Id) + 1 : 1
                    };
                    this.Id = customer.Id;
                    dc.tblCustomers.Add(customer);

                    //Return the rows effected
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #2
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a customer
                tblCustomer customer = new tblCustomer
                {
                    Id        = -99,
                    FirstName = "Test",
                    Address   = "999 Test Ave",
                    LastName  = "Test",
                    City      = "Test",
                    Phone     = "(920)555-5555",
                    State     = "WI",
                    UserId    = -99,
                    ZIP       = "54934"
                };

                //Insert the row
                dc.tblCustomers.Add(customer);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
Example #3
0
        public int Insert()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    tblOrder order = new tblOrder
                    {
                        PaymentReceipt = this.PaymentReceipt,
                        ShipDate       = this.ShipDate,
                        OrderDate      = this.OrderDate,
                        CustomerId     = this.CustomerId,
                        UserId         = this.UserId,
                        Id             = dc.tblOrders.Any() ? dc.tblOrders.Max(o => o.Id) + 1 : 1
                    };
                    this.Id = order.Id;
                    dc.tblOrders.Add(order);

                    //Return the rows effected
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a order
                tblOrder order = new tblOrder
                {
                    Id             = -99,
                    OrderDate      = DateTime.Now,
                    PaymentReceipt = "test",
                    ShipDate       = DateTime.Now.AddDays(1),
                    UserId         = 1,
                    CustomerId     = 1
                };

                //Insert the row
                dc.tblOrders.Add(order);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
Example #5
0
        public int Insert()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    tblMovie movie = new tblMovie
                    {
                        Description = this.Description,
                        Cost        = this.Cost,
                        DirectorId  = this.DirectorId,
                        FormatId    = this.FormatId,
                        ImagePath   = this.ImagePath,
                        Quantity    = this.Quantity,
                        RatingId    = this.RatingId,
                        Title       = this.Title,
                        Id          = dc.tblMovies.Any() ? dc.tblMovies.Max(m => m.Id) + 1 : 1
                    };
                    this.Id = movie.Id;
                    dc.tblMovies.Add(movie);

                    //Return the rows effected
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #6
0
        public int Insert()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    tblOrderItem orderItem = new tblOrderItem
                    {
                        OrderId  = this.OrderId,
                        MovieId  = this.MovieId,
                        Quantity = this.Quantity,
                        Id       = dc.tblOrderItems.Any() ? dc.tblOrderItems.Max(oi => oi.Id) + 1 : 1
                    };
                    this.Id = orderItem.Id;
                    dc.tblOrderItems.Add(orderItem);

                    //Return the rows effected
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #7
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a movie
                tblMovie movie = new tblMovie
                {
                    Id          = -99,
                    Title       = "TestMovie",
                    Cost        = -99.99m,
                    Quantity    = -10,
                    Description = "A test movie",
                    FormatId    = -99,
                    DirectorId  = -99,
                    ImagePath   = "TextMovieImg",
                    RatingId    = -99
                };

                //Insert the row
                dc.tblMovies.Add(movie);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
Example #8
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblGenre genre = dc.tblGenres.FirstOrDefault(g => g.Id == -99);
                dc.tblGenres.Remove(genre);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
Example #9
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblOrder order = dc.tblOrders.FirstOrDefault(o => o.Id == -99);
                dc.tblOrders.Remove(order);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
Example #10
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblFormat format = dc.tblFormats.FirstOrDefault(f => f.Id == -99);
                dc.tblFormats.Remove(format);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
Example #11
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblMovie movie = dc.tblMovies.FirstOrDefault(m => m.Id == -99);
                dc.tblMovies.Remove(movie);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
Example #12
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblDirector director = dc.tblDirectors.FirstOrDefault(d => d.Id == -99);
                dc.tblDirectors.Remove(director);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
Example #13
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblRating rating = dc.tblRatings.FirstOrDefault(r => r.Id == -99);
                dc.tblRatings.Remove(rating);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
Example #14
0
 static public void Delete(int movieId, int genreId)
 {
     using (DVDEntities dc = new DVDEntities())
     {
         tblMovieGenre movieGenre = dc.tblMovieGenres.FirstOrDefault(mg => mg.MovieId == movieId && mg.GenreId == genreId);
         if (movieGenre != null)
         {
             dc.tblMovieGenres.Remove(movieGenre);
             dc.SaveChanges();
         }
     }
 }
Example #15
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblOrder order = dc.tblOrders.FirstOrDefault(o => o.Id == -99);
                order.PaymentReceipt = "UpdateOrder";

                //Save changed property
                dc.SaveChanges();

                tblOrder updatedOrder = dc.tblOrders.FirstOrDefault(o => o.PaymentReceipt == "UpdateOrder");
                Assert.AreEqual(order.Id, updatedOrder.Id);
            }
        }
Example #16
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblMovie movie = dc.tblMovies.FirstOrDefault(m => m.Id == -99);
                movie.Title = "TestingUpdate";

                //Save changed property
                dc.SaveChanges();

                tblMovie updatedMovie = dc.tblMovies.FirstOrDefault(m => m.Title == "TestingUpdate");
                Assert.AreEqual(movie.Id, updatedMovie.Id);
            }
        }
Example #17
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblFormat format = dc.tblFormats.FirstOrDefault(f => f.Id == -99);
                format.Description = "TestingUpdate";

                //Save changed property
                dc.SaveChanges();

                tblFormat updatedFormat = dc.tblFormats.FirstOrDefault(f => f.Description == "TestingUpdate");
                Assert.AreEqual(format.Id, updatedFormat.Id);
            }
        }
Example #18
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblGenre genre = dc.tblGenres.FirstOrDefault(g => g.Id == -99);
                genre.Description = "UpdateGenre";

                //Save changed property
                dc.SaveChanges();

                tblGenre updatedGenre = dc.tblGenres.FirstOrDefault(g => g.Description == "UpdateGenre");
                Assert.AreEqual(genre.Id, updatedGenre.Id);
            }
        }
Example #19
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblOrderItem orderItem = dc.tblOrderItems.FirstOrDefault(oi => oi.Id == -99);
                orderItem.Quantity = -98;

                //Save changed property
                dc.SaveChanges();

                tblOrderItem updatedOrderItem = dc.tblOrderItems.FirstOrDefault(oi => oi.Quantity == -98);
                Assert.AreEqual(orderItem.Id, updatedOrderItem.Id);
            }
        }
Example #20
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblDirector director = dc.tblDirectors.FirstOrDefault(d => d.Id == -99);
                director.LastName = "TestingUpdate";

                //Save changed property
                dc.SaveChanges();

                tblDirector updatedDirector = dc.tblDirectors.FirstOrDefault(d => d.LastName == "TestingUpdate");
                Assert.AreEqual(director.Id, updatedDirector.Id);
            }
        }
Example #21
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblCustomer customer = dc.tblCustomers.FirstOrDefault(c => c.Id == -99);
                customer.FirstName = "TestingUpdate";

                //Save changed property
                dc.SaveChanges();

                tblCustomer updatedCustomer = dc.tblCustomers.FirstOrDefault(c => c.FirstName == "TestingUpdate");
                Assert.AreEqual(customer.Id, updatedCustomer.Id);
            }
        }
Example #22
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblRating rating = dc.tblRatings.FirstOrDefault(r => r.Id == -99);
                rating.Description = "Updt";

                //Save changed property
                dc.SaveChanges();

                tblRating updatedRating = dc.tblRatings.FirstOrDefault(r => r.Description == "Updt");
                Assert.AreEqual(rating.Id, updatedRating.Id);
            }
        }
Example #23
0
        static public void Add(int movieId, int genreId)
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblMovieGenre mg = new tblMovieGenre
                {
                    Id      = dc.tblMovieGenres.Any() ? dc.tblMovieGenres.Max(m => m.Id) + 1 : 1,
                    MovieId = movieId,
                    GenreId = genreId
                };

                dc.tblMovieGenres.Add(mg);
                dc.SaveChanges();
            }
        }
Example #24
0
        public int Update()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    //Make sure that the ID is set and valid
                    if (this.Id >= 0)
                    {
                        tblMovie movie = dc.tblMovies.FirstOrDefault(m => m.Id == this.Id);

                        //Make sure that a movie was retrieved
                        if (movie != null)
                        {
                            //Update the proterties on the movie
                            movie.Description = this.Description;
                            movie.Cost        = this.Cost;
                            movie.DirectorId  = this.DirectorId;
                            movie.FormatId    = this.FormatId;
                            movie.ImagePath   = this.ImagePath;
                            movie.Quantity    = this.Quantity;
                            movie.RatingId    = this.RatingId;
                            movie.Title       = this.Title;


                            //return the number of rows effected
                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("No movie to load with this Id");
                        }
                    }
                    else
                    {
                        throw new Exception("Movie Id not Valid");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #25
0
        public int Update()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    //Make sure that the ID is set and valid
                    if (this.Id >= 0)
                    {
                        tblCustomer customer = dc.tblCustomers.FirstOrDefault(c => c.Id == this.Id);

                        //Make sure that a customer was retrieved
                        if (customer != null)
                        {
                            //Update the proterties on the customer
                            customer.FirstName = this.FirstName;
                            customer.LastName  = this.LastName;
                            customer.Address   = this.Address;
                            customer.City      = this.City;
                            customer.Phone     = this.Phone;
                            customer.State     = this.State;
                            customer.UserId    = this.UserId;
                            customer.ZIP       = this.ZIP;
                            //return the number of rows effected
                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("No customer to load with this Id");
                        }
                    }
                    else
                    {
                        throw new Exception("Customer Id not Valid");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #26
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a director
                tblDirector director = new tblDirector {
                    Id        = -99,
                    FirstName = "TestDirector",
                    LastName  = "TestDirector"
                };

                //Insert the row
                dc.tblDirectors.Add(director);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
Example #27
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a format
                tblFormat format = new tblFormat
                {
                    Id          = -99,
                    Description = "TestFormat"
                };

                //Insert the row
                dc.tblFormats.Add(format);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
Example #28
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a genre
                tblGenre genre = new tblGenre
                {
                    Id          = -99,
                    Description = "TestGenre"
                };

                //Insert the row
                dc.tblGenres.Add(genre);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
Example #29
0
        public void Insert()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                //Create a rating
                tblRating rating = new tblRating
                {
                    Id          = -99,
                    Description = "Test"
                };

                //Insert the row
                dc.tblRatings.Add(rating);

                //Commit the changes
                int rowsInserted = dc.SaveChanges();

                //Make sure that one row was inserted
                Assert.IsTrue(rowsInserted == 1);
            }
        }
Example #30
0
        public int Update()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    //Make sure that the ID is set and valid
                    if (this.Id >= 0)
                    {
                        tblOrder order = dc.tblOrders.FirstOrDefault(o => o.Id == this.Id);

                        //Make sure that a order was retrieved
                        if (order != null)
                        {
                            //Update the proterties on the order
                            order.PaymentReceipt = this.PaymentReceipt;
                            order.ShipDate       = this.ShipDate;
                            order.OrderDate      = this.OrderDate;
                            order.CustomerId     = this.CustomerId;
                            order.UserId         = this.UserId;
                            //return the number of rows effected
                            return(dc.SaveChanges());
                        }
                        else
                        {
                            throw new Exception("No order to load with this Id");
                        }
                    }
                    else
                    {
                        throw new Exception("Order Id not Valid");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }