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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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); } }
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(); } }
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; } }
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; } }
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); } }
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); } }
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); } }
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); } }
public void LoadById() { 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) { //Set the properties on this customer this.FirstName = customer.FirstName; this.LastName = customer.LastName; this.Address = customer.Address; this.City = customer.City; this.Phone = customer.Phone; this.State = customer.State; this.UserId = customer.UserId; this.ZIP = customer.ZIP; } else { throw new Exception("No customer to load with this Id"); } } else { throw new Exception("Customer Id not Valid"); } } } catch (Exception ex) { throw ex; } }
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; } }
public int Update() { try { using (DVDEntities dc = new DVDEntities()) { //Make sure that the ID is set and valid if (this.Id >= 0) { tblOrderItem orderItem = dc.tblOrderItems.FirstOrDefault(oi => oi.Id == this.Id); //Make sure that a orderItem was retrieved if (orderItem != null) { //Update the proterties on the orderItem orderItem.MovieId = this.MovieId; orderItem.OrderId = this.OrderId; orderItem.Quantity = this.Quantity; //return the number of rows effected return(dc.SaveChanges()); } else { throw new Exception("No orderItem to load with this Id"); } } else { throw new Exception("OrderItem Id not Valid"); } } } catch (Exception ex) { throw ex; } }
public int Insert() { try { using (DVDEntities dc = new DVDEntities()) { tblGenre genre = new tblGenre { Description = this.Description, Id = dc.tblGenres.Any() ? dc.tblGenres.Max(g => g.Id) + 1 : 1 }; this.Id = genre.Id; dc.tblGenres.Add(genre); //Return the rows effected return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public void Insert() { using (DVDEntities dc = new DVDEntities()) { //Create a orderItem tblOrderItem orderItem = new tblOrderItem { Id = -99, MovieId = 1, OrderId = 1, Quantity = -99 }; //Insert the row dc.tblOrderItems.Add(orderItem); //Commit the changes int rowsInserted = dc.SaveChanges(); //Make sure that one row was inserted Assert.IsTrue(rowsInserted == 1); } }
public int Insert() { try { using (DVDEntities dc = new DVDEntities()) { tblRating rating = new tblRating { Description = this.Description, Id = dc.tblRatings.Any() ? dc.tblRatings.Max(r => r.Id) + 1 : 1 }; this.Id = rating.Id; dc.tblRatings.Add(rating); //Return the rows effected return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public int Insert() { try { using (DVDEntities dc = new DVDEntities()) { tblFormat format = new tblFormat { Description = this.Description, Id = dc.tblFormats.Any() ? dc.tblFormats.Max(f => f.Id) + 1 : 1 }; this.Id = format.Id; dc.tblFormats.Add(format); //Return the rows effected return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public void Insert() { try { using (DVDEntities dc = new DVDEntities()) { tblUser newuser = new tblUser(); Id = dc.tblUsers.Any() ? dc.tblUsers.Max(p => p.Id) + 1 : 1; UserPass = GetHash(); //Set the class details to the datarow Map(newuser); dc.tblUsers.Add(newuser); dc.SaveChanges(); } } catch (Exception ex) { throw ex; } }
public void LoadById() { 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) { //Set the properties on this order this.CustomerId = order.CustomerId; this.UserId = order.UserId; this.OrderDate = order.OrderDate; this.ShipDate = order.ShipDate; this.PaymentReceipt = order.PaymentReceipt; } else { throw new Exception("No order to load with this Id"); } } else { throw new Exception("Order Id not Valid"); } } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (DVDEntities dc = new DVDEntities()) { //Make sure that the ID is set and valid if (this.Id >= 0) { tblDirector director = dc.tblDirectors.FirstOrDefault(d => d.Id == this.Id); //Make sure that a director was retrieved if (director != null) { //Update the proterties on the director director.FirstName = this.FirstName; director.LastName = this.LastName; //return the number of rows effected return(dc.SaveChanges()); } else { throw new Exception("No director to load with this Id"); } } else { throw new Exception("Director Id not Valid"); } } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (DVDEntities dc = new DVDEntities()) { //Make sure that the ID is set and valid if (this.Id >= 0) { tblRating rating = dc.tblRatings.FirstOrDefault(r => r.Id == this.Id); //Make sure that a rating was retrieved if (rating != null) { //Update the proterties on the rating rating.Description = this.Description; //return the number of rows effected return(dc.SaveChanges()); } else { throw new Exception("No rating to load with this Id"); } } else { throw new Exception("Rating Id not Valid"); } } } catch (Exception ex) { throw ex; } }
public int Update() { try { using (DVDEntities dc = new DVDEntities()) { //Make sure that the ID is set and valid if (this.Id >= 0) { tblFormat format = dc.tblFormats.FirstOrDefault(f => f.Id == this.Id); //Make sure that a format was retrieved if (format != null) { //Update the proterties on the format format.Description = this.Description; //return the number of rows effected return(dc.SaveChanges()); } else { throw new Exception("No format to load with this Id"); } } else { throw new Exception("Format Id not Valid"); } } } catch (Exception ex) { throw ex; } }
public int Insert() { try { using (DVDEntities dc = new DVDEntities()) { tblDirector director = new tblDirector { FirstName = this.FirstName, LastName = this.LastName, Id = dc.tblDirectors.Any() ? dc.tblDirectors.Max(d => d.Id) + 1 : 1 }; this.Id = director.Id; dc.tblDirectors.Add(director); //Return the rows effected return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public int Delete() { 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 dc.tblMovies.Remove(movie); //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; } }
public void Load() { try { using (DVDEntities dc = new DVDEntities()) { //Get the genrs from the database var customers = dc.tblCustomers; //For each customer foreach (tblCustomer c in customers) { //Make a new customer and set its properties Customer customer = new Customer { Id = c.Id, FirstName = c.FirstName, LastName = c.LastName, Address = c.Address, City = c.City, Phone = c.Phone, State = c.State, UserId = c.UserId, ZIP = c.ZIP }; //Add it to the customer list this.Add(customer); } } } catch (Exception ex) { throw ex; } }
public int Delete() { 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 dc.tblCustomers.Remove(customer); //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; } }