public CustomerViewModel(CustomerView newView, FoodCustomer currentFoodCustmer)
 {
     fc         = currentFoodCustmer;
     view       = newView;
     menuItems  = mim.GetAllMenuItems();
     TotalPrice = 0;
 }
Example #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 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 CustomerView(FoodCustomer fc)
 {
     InitializeComponent();
     DataContext = new CustomerViewModel(this, fc);
 }