/// <summary>
        /// This method validates login information and opens new windows depending on the results
        /// </summary>
        /// <param name="username">Username parameter</param>
        /// <param name="password">Password parameter</param>
        /// <param name="main">Window that needs to be closed if validation is successfull</param>
        public void Login(string username, string password, MainWindow main)
        {
            List <FoodOrder> orderList = fom.GetAllFoodOrders();

            //Admin login
            if (username == "Employee" && password == "Employee")
            {
                AdminView av = new AdminView();
                main.Close();
                av.Show();
            }
            //Guest login
            else if (orderList.Contains((from o in orderList where o.CustomerJMBG == username select o).FirstOrDefault()) && password == "Guest")
            {
                FoodOrder fo;
                using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
                {
                    fo = (from o in context.FoodOrders where o.CustomerJMBG == username select o).FirstOrDefault();
                }
                //Guest loging with FoodOrder on Ready status
                if (fo.StatusOfOrder == "READY")
                {
                    AutoClosingMessageBox.Show("You order is ready!\nEnjoy your meal.", "Bon Appétit", 2000);
                    CustomerView cv = new CustomerView(username);
                    main.Close();
                    cv.Show();
                }
                //Guest loging with FoodOrder on Processing status
                else if (fo.StatusOfOrder == "PROCESSING")
                {
                    MessageBox.Show("You order is still processing.\nThank you for your patience.", "Almost there...", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
                //Guest loging with FoodOrder on Rejected status
                else if (fo.StatusOfOrder == "REJECTED")
                {
                    AutoClosingMessageBox.Show("You order is rejected.\nPlease try again.", "Rejected", 2000);
                    CustomerView cv = new CustomerView(username);
                    main.Close();
                    cv.Show();
                }
                //Guest loging with no existing FoodOrder
                else if (fo == null)
                {
                    CustomerView cv = new CustomerView(username);
                    main.Close();
                    cv.Show();
                }
            }
            else if (!orderList.Contains((from o in orderList where o.CustomerJMBG == username select o).FirstOrDefault()) && password == "Guest")
            {
                CustomerView cv = new CustomerView(username);
                main.Close();
                cv.Show();
            }
            //Wrong credentials
            else
            {
                MessageBox.Show("Username or Password was incorrect ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Exemple #2
0
        public void Login(string username, string password, MainWindow main)
        {
            List <FoodCustomer> customersList = fcm.GetAllFoodCustomers();

            if (username == "Employee" && password == "Employee")
            {
                AdminView av = new AdminView();
                main.Close();
                av.Show();
            }
            else if (customersList.Contains((from c in customersList where c.JMBG == username select c).FirstOrDefault()) && password == "Guest")
            {
                FoodCustomer fc;
                FoodOrder    fo;
                using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
                {
                    fc = (from c in context.FoodCustomers where c.JMBG == username select c).FirstOrDefault();
                    fo = (from o in context.FoodOrders where o.FoodCustomer.JMBG == fc.JMBG select o).FirstOrDefault();
                }
                if (fo == null)
                {
                    CustomerView cv = new CustomerView(fc);
                    main.Close();
                    cv.Show();
                }
                else if (fo.StatusOfOrder == "READY")
                {
                    AutoClosingMessageBox.Show("You order is ready!\nEnjoy your meal.", "Bon Appétit", 2000);
                    CustomerView cv = new CustomerView(fc);
                    main.Close();
                    cv.Show();
                }
                else if (fo.StatusOfOrder == "PROCESSING")
                {
                    MessageBox.Show("You order is still processing.\nThank you for your patience.", "Almost there...", MessageBoxButton.OK, MessageBoxImage.Asterisk);
                }
                else if (fo.StatusOfOrder == "REJECTED")
                {
                    AutoClosingMessageBox.Show("You order is rejected.\nPlease try again.", "Rejected", 2000);
                    CustomerView cv = new CustomerView(fc);
                    main.Close();
                    cv.Show();
                }
            }
            else if (!customersList.Contains((from c in customersList where c.JMBG == username select c).FirstOrDefault()) && password == "Guest")
            {
                FoodCustomer fc = new FoodCustomer();
                fc.JMBG = username;
                fcm.AddFoodCustomer(fc);
                CustomerView cv = new CustomerView(fc);
                main.Close();
                cv.Show();
            }
            else
            {
                MessageBox.Show("Username or Password was incorrect ", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
 public void AddFoodCustomer(FoodCustomer customer)
 {
     try
     {
         using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
         {
             context.FoodCustomers.Add(customer);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
 public void DeleteFoodCustomer(int customerID)
 {
     try
     {
         using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
         {
             FoodCustomer customer = (from c in context.FoodCustomers where c.CustomerID == customerID select c).FirstOrDefault();
             context.FoodCustomers.Remove(customer);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
 public void UpdateFoodOrder(FoodOrder updatedOrder)
 {
     try
     {
         using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
         {
             FoodOrder order = (from o in context.FoodOrders where o.OrderID == updatedOrder.OrderID select o).FirstOrDefault();
             order.StatusOfOrder = updatedOrder.StatusOfOrder;
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemple #6
0
 public List <FoodMenu> GetAllMenuItems()
 {
     try
     {
         using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
         {
             List <FoodMenu> menu = new List <FoodMenu>();
             menu = (from m in context.FoodMenus select m).ToList();
             return(menu);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return(null);
     }
 }
 public FoodCustomer GetFoodCustomer(int id)
 {
     try
     {
         using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
         {
             FoodCustomer fc = new FoodCustomer();
             fc = (from c in context.FoodCustomers where c.CustomerID == id select c).FirstOrDefault();
             return(fc);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return(null);
     }
 }
 public List <FoodCustomer> GetAllFoodCustomers()
 {
     try
     {
         using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
         {
             List <FoodCustomer> customers = new List <FoodCustomer>();
             customers = (from c in context.FoodCustomers select c).ToList();
             return(customers);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return(null);
     }
 }
 public FoodOrder GetFoodOrder(string jmbg)
 {
     try
     {
         using (FoodOrderAppBaseEntities context = new FoodOrderAppBaseEntities())
         {
             FoodOrder fo = new FoodOrder();
             fo = (from o in context.FoodOrders where o.FoodCustomer.JMBG == jmbg select o).FirstOrDefault();
             return(fo);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Exception " + ex.Message.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
         return(null);
     }
 }