public static bool Insert(Guid userid, Guid addressid, Guid paymentid, DateTime date) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { // Make a new row tblOrder newrow = new tblOrder(); // Set the properties newrow.Id = Guid.NewGuid(); newrow.UserId = userid; newrow.AddressId = addressid; newrow.PaymentId = paymentid; newrow.Date = date; // Do the Insert dc.tblOrders.Add(newrow); // Commit the insert return(Convert.ToBoolean(dc.SaveChanges())); } } catch (Exception ex) { throw ex; } }
public static int Update(UserPayment userPayment) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserPayment updatedrow = dc.tblUserPayments.FirstOrDefault(a => a.Id == userPayment.Id); if (updatedrow != null) { updatedrow.UserId = userPayment.UserId; updatedrow.CardHolderName = userPayment.CardHolderName; updatedrow.CardNumber = userPayment.CardNumber; updatedrow.ExpirationDate = userPayment.ExpirationDate; updatedrow.CVC = userPayment.CVC; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static UserPayment LoadById(Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserPayment UserPaymentRow = dc.tblUserPayments.FirstOrDefault(a => a.Id == id); if (UserPaymentRow != null) { return(new UserPayment { Id = UserPaymentRow.Id, UserId = UserPaymentRow.UserId, CardHolderName = UserPaymentRow.CardHolderName, CardNumber = UserPaymentRow.CardNumber, ExpirationDate = UserPaymentRow.ExpirationDate, CVC = UserPaymentRow.CVC }); } else { throw new Exception("Row not found..."); } } } catch (Exception ex) { throw ex; } }
public static List <UserPayment> Load() { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { List <UserPayment> results = new List <UserPayment>(); dc.tblUserPayments.ToList().ForEach(p => results.Add(new UserPayment { Id = p.Id, UserId = p.UserId, CardHolderName = p.CardHolderName, CardNumber = p.CardNumber, ExpirationDate = p.ExpirationDate, CVC = p.CVC })); return(results); } } catch (Exception ex) { throw ex; } }
public static bool Insert(Guid userid, string cardholdername, string cardnumber, string expirationdate, string cvc) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { // Make a new row tblUserPayment newrow = new tblUserPayment(); // Set the properties newrow.Id = Guid.NewGuid(); newrow.UserId = userid; newrow.CardHolderName = cardholdername; newrow.CardNumber = cardnumber; newrow.ExpirationDate = expirationdate; newrow.CVC = cvc; // Do the Insert dc.tblUserPayments.Add(newrow); // Commit the insert return(Convert.ToBoolean(dc.SaveChanges())); } } catch (Exception ex) { throw ex; } }
//public static List<StateId> LoadStateIds() //{ // try // { // using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) // { // List<StateId> results = new List<StateId>(); // dc.tblStateIds.ToList().ForEach(s => results.Add(new StateId // { // Id = s.Id, // Name = s.Name // })); // return results; // } // } // catch (Exception ex) // { // throw ex; // } //} public static UserAddress LoadById(Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserAddress UserAddressRow = dc.tblUserAddresses.FirstOrDefault(a => a.Id == id); if (UserAddressRow != null) { return(new UserAddress { Id = UserAddressRow.Id, UserId = UserAddressRow.UserId, Address = UserAddressRow.Address, City = UserAddressRow.City, StateId = UserAddressRow.StateId, StateName = LoadStateById(UserAddressRow.StateId).Name, StateAbbreviation = LoadStateById(UserAddressRow.StateId).Abbreviation, ZipCode = UserAddressRow.ZipCode }); } else { throw new Exception("Row not found..."); } } } catch (Exception ex) { throw ex; } }
public static MenuItem LoadById(Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblMenuItem MenuItemRow = dc.tblMenuItems.FirstOrDefault(a => a.Id == id); if (MenuItemRow != null) { return(new MenuItem { Id = MenuItemRow.Id, ItemName = MenuItemRow.ItemName, Price = (float)MenuItemRow.Price, }); } else { throw new Exception("Row not found..."); } } } catch (Exception ex) { throw ex; } }
public static int Update(Guid id, string firstName, string lastName, string email, string phone, string password) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUser updatedrow = dc.tblUsers.FirstOrDefault(a => a.Id == id); if (updatedrow != null) { updatedrow.FirstName = firstName; updatedrow.LastName = lastName; updatedrow.Email = email; updatedrow.Phone = phone; updatedrow.Password = password; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(User user) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUser updatedrow = dc.tblUsers.FirstOrDefault(a => a.Id == user.Id); if (updatedrow != null) { updatedrow.FirstName = user.FirstName; updatedrow.LastName = user.LastName; updatedrow.Email = user.Email; updatedrow.Phone = user.Phone; updatedrow.Password = user.Password; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Insert(User user) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { // Make a new row tblUser newrow = new tblUser(); // Set the properties newrow.Id = Guid.NewGuid(); newrow.FirstName = user.FirstName; newrow.LastName = user.LastName; newrow.Phone = user.Phone; newrow.Email = user.Email; newrow.Password = user.Password; user.Id = newrow.Id; // Do the Insert dc.tblUsers.Add(newrow); // Commit the insert return(dc.SaveChanges()); } } catch (Exception ex) { return(0); } }
public static List <User> Load() { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { List <User> results = new List <User>(); dc.tblUsers.ToList().ForEach(p => results.Add(new User { Id = p.Id, FirstName = p.FirstName, LastName = p.LastName, Email = p.Email, Phone = p.Phone, Password = p.Password, Addresses = UserAddressManager.LoadByUserId(p.Id), Payments = UserPaymentManager.LoadByUserId(p.Id) })); return(results); } } catch (Exception ex) { throw ex; } }
public static Order LoadById(Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblOrder OrderRow = dc.tblOrders.FirstOrDefault(a => a.Id == id); if (OrderRow != null) { return(new Order { Id = OrderRow.Id, UserId = OrderRow.UserId, AddressId = OrderRow.AddressId, PaymentId = OrderRow.PaymentId, Date = OrderRow.Date }); } else { throw new Exception("Row not found..."); } } } catch (Exception ex) { throw ex; } }
public static int Update(Order order) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblOrder updatedrow = dc.tblOrders.FirstOrDefault(a => a.Id == order.Id); if (updatedrow != null) { updatedrow.UserId = order.UserId; updatedrow.AddressId = order.AddressId; updatedrow.PaymentId = order.PaymentId; updatedrow.Date = order.Date; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(Guid id, Guid userid, Guid addressid, Guid paymentid, DateTime date) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblOrder updatedrow = dc.tblOrders.FirstOrDefault(a => a.Id == id); if (updatedrow != null) { updatedrow.UserId = userid; updatedrow.AddressId = addressid; updatedrow.PaymentId = paymentid; updatedrow.Date = date; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(Guid id, Guid userid, string address, string city, string stateAbbreviation, string zipcode) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserAddress updatedrow = dc.tblUserAddresses.FirstOrDefault(a => a.Id == id); if (updatedrow != null) { State newstate = new State(); newstate.Id = LoadStateByAbbreviation(stateAbbreviation).Id; // This is so the user will only need to enter WI. updatedrow.UserId = userid; updatedrow.Address = address; updatedrow.City = city; updatedrow.StateId = newstate.Id; updatedrow.ZipCode = zipcode; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static int Login(string userEmail, string userPassword, out Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUser user = dc.tblUsers.FirstOrDefault(l => l.Email == userEmail && l.Password == userPassword); if (user != null) { id = user.Id; return(1); } else { id = Guid.Empty; return(0); } } } catch (Exception ex) { throw ex; } }
public static int Update(UserAddress userAddress) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserAddress updatedrow = dc.tblUserAddresses.FirstOrDefault(a => a.Id == userAddress.Id); if (updatedrow != null) { State newstate = new State(); //newstate.Id = LoadStateByAbbreviation(userAddress.StateAbbreviation).Id; // This is so the user will only need to enter WI. updatedrow.UserId = userAddress.UserId; updatedrow.Address = userAddress.Address; updatedrow.City = userAddress.City; updatedrow.StateId = userAddress.StateId; updatedrow.ZipCode = userAddress.ZipCode; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static User LoadById(Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUser userRow = dc.tblUsers.FirstOrDefault(a => a.Id == id); if (userRow != null) { return(new User { Id = userRow.Id, FirstName = userRow.FirstName, LastName = userRow.LastName, Email = userRow.Email, Phone = userRow.Phone, Password = userRow.Password, Addresses = UserAddressManager.LoadByUserId(id), Payments = UserPaymentManager.LoadByUserId(id) }); } else { throw new Exception("Row not found..."); } } } catch (Exception ex) { throw ex; } }
public static int Update(MenuItem menuItem) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblMenuItem updatedrow = dc.tblMenuItems.FirstOrDefault(a => a.Id == menuItem.Id); if (updatedrow != null) { updatedrow.ItemName = menuItem.ItemName; updatedrow.Price = menuItem.Price; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static User LoadByEmail(string email, string password) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUser userRow = dc.tblUsers.FirstOrDefault(a => a.Email == email && a.Password == password); if (userRow != null) { return(new User { Id = userRow.Id, FirstName = userRow.FirstName, LastName = userRow.LastName, Email = userRow.Email, Phone = userRow.Phone, Password = userRow.Password, Addresses = UserAddressManager.LoadByUserId(userRow.Id), Payments = UserPaymentManager.LoadByUserId(userRow.Id) }); } else { return(null); } } } catch (Exception ex) { throw ex; } }
public static bool Insert(string itemName, float price) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { // Make a new row tblMenuItem newrow = new tblMenuItem(); // Set the properties newrow.Id = Guid.NewGuid(); newrow.ItemName = itemName; newrow.Price = price; // Do the Insert dc.tblMenuItems.Add(newrow); // Commit the insert dc.SaveChanges(); return(true); } } catch (Exception ex) { throw ex; } }
public static List <UserAddress> Load() { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { List <UserAddress> results = new List <UserAddress>(); dc.tblUserAddresses.ToList().ForEach(p => results.Add(new UserAddress { Id = p.Id, UserId = p.UserId, Address = p.Address, City = p.City, StateId = p.StateId, StateName = LoadStateById(p.StateId).Name, StateAbbreviation = LoadStateById(p.StateId).Abbreviation, ZipCode = p.ZipCode })); return(results); } } catch (Exception ex) { throw ex; } }
public static bool Insert(UserPayment userPayment) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { // Make a new row tblUserPayment newrow = new tblUserPayment(); // Set the properties newrow.Id = Guid.NewGuid(); newrow.UserId = userPayment.UserId; newrow.CardHolderName = userPayment.CardHolderName; newrow.CardNumber = userPayment.CardNumber; newrow.ExpirationDate = userPayment.ExpirationDate; newrow.CVC = userPayment.CVC; // Do the Insert dc.tblUserPayments.Add(newrow); // Commit the insert return(Convert.ToBoolean(dc.SaveChanges())); } } catch (Exception ex) { //throw ex; return(false); } }
public static State LoadStateByAbbreviation(string abb) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblState StateRow = dc.tblStates.FirstOrDefault(a => a.Abbreviation == abb); if (StateRow != null) { return(new State { Id = StateRow.Id, Abbreviation = StateRow.Abbreviation, Name = StateRow.Name }); } else { throw new Exception("Row not found..."); } } } catch (Exception ex) { throw ex; } }
public static int Update(Guid id, Guid userid, string cardholdername, string cardnumber, string expirationdate, string cvc) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserPayment updatedrow = dc.tblUserPayments.FirstOrDefault(a => a.Id == id); if (updatedrow != null) { updatedrow.UserId = userid; updatedrow.CardHolderName = cardholdername; updatedrow.CardNumber = cardnumber; updatedrow.ExpirationDate = expirationdate; updatedrow.CVC = cvc; return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static List <UserAddress> LoadByUserId(Guid userid) { try { List <UserAddress> addresses = new List <UserAddress>(); using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUser row = dc.tblUsers.FirstOrDefault(a => a.Id == userid); var results = (from v in dc.tblUserAddresses where v.UserId == row.Id select v).ToList(); results.ForEach(p => addresses.Add(new UserAddress { Id = p.Id, UserId = p.UserId, Address = p.Address, City = p.City, StateId = p.StateId, StateName = LoadStateById(p.StateId).Name, StateAbbreviation = LoadStateById(p.StateId).Abbreviation, ZipCode = p.ZipCode })); } return(addresses); } catch (Exception ex) { throw ex; } }
public static int Delete(Guid id) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUserPayment deletedrow = dc.tblUserPayments.FirstOrDefault(a => a.Id == id); if (deletedrow != null) { dc.tblUserPayments.Remove(deletedrow); return(dc.SaveChanges()); } else { return(0); } } } catch (Exception ex) { throw ex; } }
public static bool Insert(Guid userid, string address, string city, string stateAbbreviation, string zipcode) { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { // Make a new row tblUserAddress newrow = new tblUserAddress(); State newstate = new State(); newstate.Id = LoadStateByAbbreviation(stateAbbreviation).Id; // This is so the user will only need to enter WI. // Set the properties newrow.Id = Guid.NewGuid(); newrow.UserId = userid; newrow.Address = address; newrow.City = city; newrow.StateId = newstate.Id; newrow.ZipCode = zipcode; // Do the Insert dc.tblUserAddresses.Add(newrow); // Commit the insert return(Convert.ToBoolean(dc.SaveChanges())); } } catch (Exception ex) { throw ex; } }
public static List <UserPayment> LoadByUserId(Guid userid) { try { List <UserPayment> payMethods = new List <UserPayment>(); using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { tblUser row = dc.tblUsers.FirstOrDefault(a => a.Id == userid); var results = (from v in dc.tblUserPayments where v.UserId == row.Id select v).ToList(); results.ForEach(p => payMethods.Add(new UserPayment { Id = p.Id, UserId = p.UserId, CardHolderName = p.CardHolderName, CardNumber = p.CardNumber, ExpirationDate = p.ExpirationDate, CVC = p.CVC })); } return(payMethods); } catch (Exception ex) { throw ex; } }
public static List <Order> Load() { try { using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities()) { List <Order> results = new List <Order>(); dc.tblOrders.ToList().ForEach(p => results.Add(new Order { Id = p.Id, UserId = p.UserId, AddressId = p.AddressId, PaymentId = p.PaymentId, Date = p.Date, OrderItems = OrderItemManager.LoadByOrderId(p.Id) // Add OrderItems })); return(results); } } catch (Exception ex) { throw ex; } }