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(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 void Checkout(ShoppingCart cart, User user) { using (DVDCentralEntities dc = new DVDCentralEntities()) { Order order = new Order(); order.Id = dc.tblOrders.Any() ? dc.tblOrders.Max(p => p.Id) + 1 : 1; order.UserId = user.UserId; order.CustomerId = cart.CustomerId; order.PaymentReceipt = Convert.ToString(cart.TotalCost); order.OrderDate = DateTime.Now; OrderManager.Insert(order, cart.Items); // Add an order item for each movie foreach (Movie movie in cart.Items) { OrderItem orderItem = new OrderItem(); orderItem.MovieId = movie.Id; orderItem.OrderId = order.Id; orderItem.Quantity = 1; OrderItemManager.Insert(orderItem); } cart.Items = null; // Clear the cart } }
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()) { 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 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 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 Order LoadById(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblOrder row = (from dt in dc.tblOrders where dt.Id == id select dt).FirstOrDefault(); if (row != null) { return new Order { Id = row.Id, CustomerId = row.CustomerId, UserId = row.UserId, OrderDate = row.OrderDate, ShipDate = row.ShipDate } } ; else { throw new Exception("Row was not found"); } } } 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 List <Order> Load() { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { List <Order> orders = new List <Order>(); foreach (tblOrder dt in dc.tblOrders) { orders.Add(new Order { Id = dt.Id, UserId = dt.UserId, CustomerId = dt.CustomerId, OrderDate = dt.OrderDate, ShipDate = dt.ShipDate }); } return(orders); } } 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(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 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 List <Genre> Load(int?movieId) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { List <Genre> genres = new List <Genre>(); var results = (from a in dc.tblGenres join pda in dc.tblMovieGenres on a.Id equals pda.GenreId where pda.MovieId == movieId select new { a.Id, a.Description }).ToList(); results.ForEach(r => genres.Add(new Genre { Id = r.Id, Description = r.Description })); return(genres); } } catch (Exception ex) { throw ex; } }
public static List <Order> LoadByCustomerId(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { List <Order> results = new List <Order>(); var orders = (from dt in dc.tblOrders where dt.CustomerId == id select dt).ToList(); orders.ForEach(o => results.Add(new Order { Id = o.Id, CustomerId = o.CustomerId, UserId = o.UserId, OrderDate = o.OrderDate, ShipDate = o.ShipDate })); return(results); } } 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 List <OrderItem> Load() { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { List <OrderItem> orderItems = new List <OrderItem>(); foreach (tblOrderItem dt in dc.tblOrderItems) { orderItems.Add(new OrderItem { Id = dt.Id, OrderId = dt.OrderId, MovieId = dt.MovieId, Quantity = dt.Quantity, Cost = dt.Cost }); } return(orderItems); } } 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 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 Director LoadById(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblDirector row = (from dt in dc.tblDirectors where dt.Id == id select dt).FirstOrDefault(); if (row != null) { return new Director { Id = row.Id, FirstName = row.FirstName, LastName = row.LastName } } ; else { throw new Exception("Row was not found"); } } } catch (Exception ex) { throw ex; } }
public static OrderItem LoadById(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblOrderItem row = (from dt in dc.tblOrderItems where dt.Id == id select dt).FirstOrDefault(); if (row != null) { return new OrderItem { Id = row.Id, OrderId = row.OrderId, MovieId = row.MovieId, Cost = row.Cost, Quantity = row.Quantity } } ; else { throw new Exception("Row was not found"); } } } catch (Exception ex) { throw ex; } }
public static Customer LoadByID(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { //get the row i want to load tblCustomer row = (from dt in dc.tblCustomers where dt.Id == id select dt).FirstOrDefault(); if (row != null) { return new Customer { Id = row.Id, FirstName = row.FirstName, LastName = row.LastName, Address = row.Address, City = row.City, State = row.State, ZIP = row.ZIP, Phone = row.Phone, UserId = row.UserID } } ; else { throw new Exception("Row not found"); } } } catch (Exception ex) { throw ex; } }
public static List <OrderItem> LoadByOrderId(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { List <OrderItem> results = new List <OrderItem>(); var orderItems = (from dt in dc.tblOrderItems where dt.OrderId == id select dt).ToList(); orderItems.ForEach(oi => results.Add(new OrderItem { Id = oi.Id, OrderId = oi.OrderId, MovieId = oi.MovieId, Cost = oi.Cost, Quantity = oi.Quantity })); return(results); } } catch (Exception ex) { throw ex; } }
public static Customer Load(int userid) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { var customer = (from c in dc.tblCustomers join u in dc.tblUsers on c.UserID equals u.Id where u.Id == userid select new { c.Id, c.FirstName, c.LastName, c.Address, c.City, c.State, c.ZIP, c.Phone, c.UserID }).FirstOrDefault(); if (customer == null) { return(new Customer()); } return(new Customer { Id = customer.Id, FirstName = customer.FirstName, LastName = customer.LastName, Address = customer.Address, City = customer.City, State = customer.State, ZIP = customer.ZIP, Phone = customer.Phone, UserId = customer.UserID }); } } catch (Exception ex) { throw ex; } }
public static void Checkout(ShoppingCart cart, User user, int customerId) { Order order = new Order(); order.CustomerId = customerId; order.OrderDate = DateTime.Now; order.ShipDate = DateTime.Now; using (DVDCentralEntities dc = new DVDCentralEntities()) { tblUser result = (from dt in dc.tblUsers where user.UserId == dt.UserId select dt).FirstOrDefault(); order.UserId = result.Id; tblCustomer customer = (from dt in dc.tblCustomers where order.UserId == dt.UserId select dt).FirstOrDefault(); order.CustomerId = customer.Id; } OrderManager.Insert(order); foreach (Movie movie in cart.Items) { OrderItem item = new OrderItem(); item.MovieId = movie.Id; item.OrderId = order.Id; item.Quantity = 1; item.Cost = movie.Cost; OrderItemManager.Insert(item); } cart.Checkout(); }
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 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 Rating LoadById(int id) { try { using (DVDCentralEntities dc = new DVDCentralEntities()) { tblRating row = (from dt in dc.tblRatings where dt.Id == id select dt).FirstOrDefault(); if (row != null) { return new Rating { Id = row.Id, Description = row.Description } } ; 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; } }