public static int Insert(Director director) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblDirector tblDirector = new tblDirector(); tblDirector.FirstName = director.FirstName; tblDirector.LastName = director.LastName; //example of ternary operator tblDirector.Id = dc.tblDirectors.Any() ? dc.tblDirectors.Max(dt => dt.Id) + 1 : 1; //Change the ID of the inserted Student director.Id = tblDirector.Id; dc.tblDirectors.Add(tblDirector); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Insert(Customer customer) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblCustomer tblCustomer = new tblCustomer(); tblCustomer.FirstName = customer.FirstName; tblCustomer.LastName = customer.LastName; tblCustomer.Address = customer.Address; tblCustomer.City = customer.City; tblCustomer.State = customer.State; tblCustomer.ZIP = customer.ZIP; tblCustomer.UserID = customer.UserId; tblCustomer.Phone = customer.Phone; tblCustomer.Id = dc.tblCustomers.Any() ? dc.tblCustomers.Max(dt => dt.Id) + 1 : 1; customer.Id = tblCustomer.Id; dc.tblCustomers.Add(tblCustomer); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Delete(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to delete tblCustomer deleteRow = (from dt in dc.tblCustomers where dt.Id == id select dt).FirstOrDefault(); if (deleteRow != null) { dc.tblCustomers.Remove(deleteRow); return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static int Update(Genre genre) { using (DVDCentralEntities dc = new DVDCentralEntities()) { try { tblGenre updatedrow = dc.tblGenres.Where(dt => dt.Id == genre.Id).FirstOrDefault(); // Check to see if object exists if (genre != null) { // Update the proper fields updatedrow.Description = genre.Description; // Save and commit changes return(dc.SaveChanges()); } else { // throw an exception stating the row was not found throw new Exception("Row was not found."); } } catch (Exception ex) { throw ex; } } }
public static int Insert(out int id, string title, string description, double cost, int ratingId, int directorId, int formatId, int inStkQty, string imagePath) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblMovie newrow = new tblMovie(); newrow.Title = title; newrow.Description = description; newrow.Cost = cost; newrow.RatingId = ratingId; newrow.DirectorId = directorId; newrow.FormatId = formatId; newrow.InStkQty = inStkQty; newrow.ImagePath = imagePath; //giving a new row the next id after existing one or if there is none id equals to 1 newrow.Id = dc.tblMovies.Any() ? dc.tblMovies.Max(dt => dt.Id) + 1 : 1; id = newrow.Id; dc.tblMovies.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Update(Movie movie) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to update tblMovie updateRow = (from dt in dc.tblMovies where dt.Id == movie.Id select dt).FirstOrDefault(); if (updateRow != null) { updateRow.Title = movie.Title; updateRow.Description = movie.Description; updateRow.Cost = movie.Cost; updateRow.RatingID = movie.RatingID; updateRow.DirectorID = movie.DirectorID; updateRow.FormatID = movie.FormatID; updateRow.InStkQty = movie.InStkQty; updateRow.ImagePath = movie.ImagePath; return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static int Insert(out int id, int orderId, int movieId, int quantity, double cost) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblOrderItem newrow = new tblOrderItem(); newrow.OrderId = orderId; newrow.MovieId = movieId; newrow.Quantity = quantity; newrow.Cost = cost; //giving a new row the next id after existing one or if there is none id equals to 1 newrow.Id = dc.tblOrderItems.Any() ? dc.tblOrderItems.Max(dt => dt.Id) + 1 : 1; id = newrow.Id; dc.tblOrderItems.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static bool Insert(OrderItem orderItem) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { // Make a new row tblOrderItem newrow = new tblOrderItem(); // Set the properties // Ternary Operator condition ? true : false newrow.Id = dc.tblOrderItems.Any() ? dc.tblOrderItems.Max(p => p.Id) + 1 : 1; // If there are any rows, get the max id and add 1, if not use 1 newrow.OrderId = orderItem.OrderId; newrow.MovieId = orderItem.MovieId; newrow.Quantity = orderItem.Quantity; // Do the Insert dc.tblOrderItems.Add(newrow); // Commit the insert dc.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public static int Update(OrderItem orderItem) { using (DVDCentralEntities dc = new DVDCentralEntities()) { try { tblOrderItem updatedrow = dc.tblOrderItems.Where(dt => dt.Id == orderItem.Id).FirstOrDefault(); // Check to see if object exists if (orderItem != null) { // Update the proper fields updatedrow.OrderId = orderItem.OrderId; updatedrow.MovieId = orderItem.MovieId; updatedrow.Quantity = orderItem.Quantity; // Save and commit changes return(dc.SaveChanges()); } else { // throw an exception stating the row was not found throw new Exception("Row was not found."); } } catch (Exception ex) { throw ex; } } }
public void InsertTest() { tblRating newrow = new tblRating(); // Set the column values newrow.Id = -99; newrow.Description = "Test"; // Insert of the row dc.tblRatings.Add(newrow); // Commit the changes (insert a row) and then return the rows affected. int rowsaffected = dc.SaveChanges(); Assert.AreNotEqual(0, rowsaffected); }
public void InsertTest() { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblMovie newrow = new tblMovie(); newrow.Id = -99; newrow.Title = "Test Movie"; newrow.Description = "It's just a test"; newrow.Cost = 1.22; newrow.RatingID = -99; newrow.FormatID = -99; newrow.DirectorID = -99; newrow.InStkQty = -99; newrow.ImagePath = "ahhhhhh"; dc.tblMovies.Add(newrow); int results = dc.SaveChanges(); Assert.IsTrue(results == 1); } }
public static int Update(OrderItem orderItem) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to update tblOrderItem updateRow = (from dt in dc.tblOrderItems where dt.Id == orderItem.Id select dt).FirstOrDefault(); if (updateRow != null) { updateRow.MovieID = orderItem.MovieId; updateRow.OrderID = orderItem.OrderId; updateRow.Quantity = orderItem.Quantity; updateRow.Cost = orderItem.Cost; return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static int Insert(OrderItem orderItem) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblOrderItem tblOrderItem = new tblOrderItem(); tblOrderItem.MovieID = orderItem.MovieId; tblOrderItem.OrderID = orderItem.OrderId; tblOrderItem.Quantity = orderItem.Quantity; tblOrderItem.Cost = orderItem.Cost; //example of ternary operator tblOrderItem.Id = dc.tblOrderItems.Any() ? dc.tblOrderItems.Max(dt => dt.Id) + 1 : 1; //Change the ID of the inserted Student orderItem.Id = tblOrderItem.Id; dc.tblOrderItems.Add(tblOrderItem); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Update(Director director) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to update tblDirector updateRow = (from dt in dc.tblDirectors where dt.Id == director.Id select dt).FirstOrDefault(); if (updateRow != null) { updateRow.FirstName = director.FirstName; updateRow.LastName = director.LastName; return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static int Update(Order order) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to update tblOrder updateRow = (from dt in dc.tblOrders where dt.Id == order.Id select dt).FirstOrDefault(); if (updateRow != null) { updateRow.CustomerID = order.CustomerId; updateRow.OrderDate = order.OrderDate; updateRow.ShipDate = order.ShipDate; updateRow.UserID = order.UserId; return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static bool Insert(Director director) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { // Make a new row tblDirector newrow = new tblDirector(); // Set the properties // Ternary Operator condition ? true : false newrow.Id = dc.tblDirectors.Any() ? dc.tblDirectors.Max(p => p.Id) + 1 : 1; // If there are any rows, get the max id and add 1, if not use 1 newrow.FirstName = director.FirstName; newrow.LastName = director.LastName; // Do the Insert dc.tblDirectors.Add(newrow); // Commit the insert dc.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public static int Insert(Movie movie) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblMovie tblMovie = new tblMovie(); tblMovie.Title = movie.Title; tblMovie.Description = movie.Description; tblMovie.Cost = movie.Cost; tblMovie.RatingID = movie.RatingID; tblMovie.DirectorID = movie.DirectorID; tblMovie.FormatID = movie.FormatID; tblMovie.InStkQty = movie.InStkQty; tblMovie.ImagePath = movie.ImagePath; tblMovie.Id = dc.tblMovies.Any() ? dc.tblMovies.Max(dt => dt.Id) + 1 : 1; movie.Id = tblMovie.Id; dc.tblMovies.Add(tblMovie); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Update(Director director) { using (DVDCentralEntities dc = new DVDCentralEntities()) { try { tblDirector updatedrow = dc.tblDirectors.Where(dt => dt.Id == director.Id).FirstOrDefault(); // Check to see if object exists if (director != null) { // Update the proper fields updatedrow.FirstName = director.FirstName; updatedrow.LastName = director.LastName; // Save and commit changes return(dc.SaveChanges()); } else { // throw an exception stating the row was not found throw new Exception("Row was not found."); } } catch (Exception ex) { throw ex; } } }
public static int Insert(out int id, int customerId, int userId, DateTime orderDate, DateTime shipDate) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblOrder newrow = new tblOrder(); newrow.UserId = userId; newrow.OrderDate = orderDate; newrow.ShipDate = shipDate; newrow.CustomerId = customerId; //giving a new row the next id after existing one or if there is none id equals to 1 newrow.Id = dc.tblOrders.Any() ? dc.tblOrders.Max(dt => dt.Id) + 1 : 1; id = newrow.Id; dc.tblOrders.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Insert(Genre genre) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblGenre tblGenre = new tblGenre(); tblGenre.Description = genre.Description; //example of ternary operator tblGenre.Id = dc.tblGenres.Any() ? dc.tblGenres.Max(dt => dt.Id) + 1 : 1; //Change the ID of the inserted Student genre.Id = tblGenre.Id; dc.tblGenres.Add(tblGenre); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static bool Insert(Genre genre) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { // Make a new row tblGenre newrow = new tblGenre(); // Set the properties // Ternary Operator condition ? true : false newrow.Id = dc.tblGenres.Any() ? dc.tblGenres.Max(p => p.Id) + 1 : 1; // If there are any rows, get the max id and add 1, if not use 1 newrow.Description = genre.Description; // Do the Insert dc.tblGenres.Add(newrow); // Commit the insert dc.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public static int Update(Genre genre) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to update tblGenre updateRow = (from dt in dc.tblGenres where dt.Id == genre.Id select dt).FirstOrDefault(); if (updateRow != null) { updateRow.Description = genre.Description; return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static int Delete(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblGenre deleterow = dc.tblGenres.FirstOrDefault(dt => dt.Id == id); if (deleterow != null) { // Remove the row dc.tblGenres.Remove(deleterow); // Commit/Save the changes return(dc.SaveChanges()); } else { throw new Exception("Row was not found."); } } } catch (Exception ex) { throw ex; } }
public static int Insert(out int id, int userId, string firstName, string lastName, string address, string city, string state, string zip, string phone) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblCustomer newrow = new tblCustomer(); newrow.UserId = userId; newrow.FirstName = firstName; newrow.LastName = lastName; newrow.Address = address; newrow.City = city; newrow.State = state; newrow.ZIP = zip; newrow.Phone = phone; //giving a new row the next id after existing one or if there is none id equals to 1 newrow.Id = dc.tblCustomers.Any() ? dc.tblCustomers.Max(dt => dt.Id) + 1 : 1; id = newrow.Id; dc.tblCustomers.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Update(int id, string title, string description, double cost, int ratingId, int directorId, int formatId, int inStkQty, string imagePath) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblMovie updaterow = (from dt in dc.tblMovies where dt.Id == id select dt).FirstOrDefault(); updaterow.Title = title; updaterow.Description = description; updaterow.Cost = cost; updaterow.RatingId = ratingId; updaterow.DirectorId = directorId; updaterow.FormatId = formatId; updaterow.InStkQty = inStkQty; updaterow.ImagePath = imagePath; return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Update(int id, int userId, string firstName, string lastName, string address, string city, string state, string zip, string phone) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblCustomer updaterow = (from dt in dc.tblCustomers where dt.Id == id select dt).FirstOrDefault(); updaterow.UserId = userId; updaterow.FirstName = firstName; updaterow.LastName = lastName; updaterow.Address = address; updaterow.City = city; updaterow.State = state; updaterow.ZIP = zip; updaterow.Phone = phone; return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Update(Customer customer) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to update tblCustomer updateRow = (from dt in dc.tblCustomers where dt.Id == customer.Id select dt).FirstOrDefault(); if (updateRow != null) { updateRow.FirstName = customer.FirstName; updateRow.LastName = customer.LastName; updateRow.Address = customer.Address; updateRow.City = customer.City; updateRow.State = customer.State; updateRow.ZIP = customer.ZIP; updateRow.UserID = customer.UserId; updateRow.Phone = customer.Phone; return(dc.SaveChanges()); } else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static int Insert(Order order) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblOrder tblOrder = new tblOrder(); tblOrder.CustomerID = order.CustomerId; tblOrder.OrderDate = order.OrderDate; tblOrder.ShipDate = order.ShipDate; tblOrder.UserID = order.UserId; //example of ternary operator tblOrder.Id = dc.tblOrders.Any() ? dc.tblOrders.Max(dt => dt.Id) + 1 : 1; //Change the ID of the inserted Student order.Id = tblOrder.Id; dc.tblOrders.Add(tblOrder); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Insert(out int id, string description) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating newrow = new tblRating(); newrow.Description = description; //giving a new row the next id after existing one or if there is none id equals to 1 newrow.Id = dc.tblRatings.Any() ? dc.tblRatings.Max(dt => dt.Id) + 1 : 1; id = newrow.Id; //add the row dc.tblRatings.Add(newrow); return(dc.SaveChanges()); } } catch (Exception ex) { throw ex; } }
public static int Update(Order order) { using (DVDCentralEntities dc = new DVDCentralEntities()) { try { tblOrder updatedrow = dc.tblOrders.Where(dt => dt.Id == order.Id).FirstOrDefault(); // Check to see if object exists if (order != null) { // Update the proper fields updatedrow.CustomerId = order.CustomerId; updatedrow.OrderDate = order.OrderDate; updatedrow.UserId = order.UserId; updatedrow.PaymentReceipt = order.PaymentReceipt; // Save and commit changes return(dc.SaveChanges()); } else { // throw an exception stating the row was not found throw new Exception("Row was not found."); } } catch (Exception ex) { throw ex; } } }