Exemplo n.º 1
0
        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;
            }
        }
Exemplo n.º 2
0
        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;
            }
        }
Exemplo n.º 3
0
        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;
            }
        }
Exemplo n.º 4
0
        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;
            }
        }
Exemplo n.º 5
0
        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;
            }
        }
Exemplo n.º 6
0
        //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;
            }
        }
Exemplo n.º 7
0
        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;
            }
        }
Exemplo n.º 8
0
        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;
            }
        }
Exemplo n.º 9
0
        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;
            }
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 11
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;
            }
        }
Exemplo n.º 12
0
        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;
            }
        }
Exemplo n.º 13
0
        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;
            }
        }
Exemplo n.º 14
0
        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;
            }
        }
Exemplo n.º 15
0
        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;
            }
        }
Exemplo n.º 16
0
 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;
     }
 }
Exemplo n.º 17
0
        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;
            }
        }
Exemplo n.º 18
0
        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;
            }
        }
Exemplo n.º 19
0
        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;
            }
        }
Exemplo n.º 20
0
        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;
            }
        }
Exemplo n.º 21
0
        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;
            }
        }
Exemplo n.º 22
0
        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;
            }
        }
Exemplo n.º 23
0
        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);
            }
        }
Exemplo n.º 24
0
        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;
            }
        }
Exemplo n.º 25
0
        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;
            }
        }
Exemplo n.º 26
0
        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;
            }
        }
Exemplo n.º 27
0
        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;
            }
        }
Exemplo n.º 28
0
        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;
            }
        }
Exemplo n.º 29
0
        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;
            }
        }
Exemplo n.º 30
0
        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;
            }
        }