public bool UpdateFoodItem(Food_Item foodItem)
        {
            //check the validity of the input
            if (ModelState.IsValid)
            {
                try
                {
                    //Call AddFoodItem method to fetch all Food Items
                    bool isUpdated = fs.UpdateFoodItem(foodItem);

                    //return the response
                    return(isUpdated);
                }
                catch (FoodOrderException)
                {
                    //rethrow
                    throw;
                }
            }

            else
            {
                //throw user defined exception object
                throw new FoodOrderException("The entered details to fetch the Food Items are not valid");
            }
        }
        public int AddFoodItem(Food_Item foodItem)
        {
            //check the validity of the input
            if (true)
            {
                try
                {
                    //Call AddFoodItem method to fetch all Food Items
                    int foodId = fs.AddFoodItem(foodItem);

                    //return the response
                    return(foodId);
                }
                catch (FoodOrderException)
                {
                    //rethrow
                    throw;
                }
            }

            else
            {
                //throw user defined exception object
                throw new FoodOrderException("The entered details to fetch the Food Items are not valid");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Method Deletes the Food item with foodItemId from table Food_Items
        /// </summary>
        /// <param name="foodItemId">integer indicating id of Food item</param>
        /// <returns>boolean value indicating whether food item is deleted or not</returns>
        public bool DeleteFoodItemById(int foodItemId)
        {
            try
            {
                //instantiating Online_Food_Ordering_SystemEntities3 Context class
                using (Online_Food_Ordering_SystemEntities1 db = new Online_Food_Ordering_SystemEntities1())
                {
                    //use LINQ query to find the Food Item with id foodItemId
                    Food_Item item = db.Food_Items.Where(f => f.Food_Item_Id == foodItemId && f.IsActive == true).FirstOrDefault();

                    if (item != null)
                    //use LINQ query to Add Food Items from table Food_Items
                    {
                        //remove item from Food_Items
                        db.Food_Items.Remove(item);

                        //save changes to the database
                        db.SaveChanges();

                        return(true);
                    }

                    else
                    {
                        throw new FoodOrderException("Food item does not exist");
                    }
                }
            }
            catch (Exception ex)
            {
                //throw user defined FoodOrderException
                throw new FoodOrderException(ex.Message);
            }
        }
Exemplo n.º 4
0
        public ActionResult DeleteConfirmed(int id)
        {
            Food_Item food_Item = db.Food_Item.Find(id);

            db.Food_Item.Remove(food_Item);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 5
0
 public ActionResult Edit([Bind(Include = "ID,Name,Sale_Price,Description")] Food_Item food_Item)
 {
     if (ModelState.IsValid)
     {
         db.Entry(food_Item).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(food_Item));
 }
Exemplo n.º 6
0
        public ActionResult Create([Bind(Include = "ID,Name,Sale_Price,Description")] Food_Item food_Item)
        {
            if (ModelState.IsValid)
            {
                db.Food_Item.Add(food_Item);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(food_Item));
        }
Exemplo n.º 7
0
        public void Update(int id, string item_name, int serve, decimal price, byte[] img)
        {
            SqlConnection con1 = sqlObj.Get_Con();

            con1.Open();
            Food_Item  i    = new Food_Item(item_name, serve, price, img);
            SqlCommand cmd1 = new SqlCommand("UPDATE Food_Items SET Item_Name='" + i.Food_Name + "',Item_Serve=" + i.Food_Serving + ",Item_Price=" + i.Food_Price + ",Item_Image=@img WHERE Item_ID=" + id + "", con1);

            cmd1.Parameters.AddWithValue("@img", i.Food_image);
            cmd1.ExecuteNonQuery();
            con1.Close();
        }
Exemplo n.º 8
0
        public void Create(string item_name, int serve, decimal price, byte[] img)
        {
            Food_Item     item = new Food_Item(item_name, serve, price, img);
            SqlConnection con1 = sqlObj.Get_Con();

            con1.Open();
            SqlCommand cmd1 = new SqlCommand("INSERT INTO Food_Items Values('" + item.Food_Name + "'," + item.Food_Serving + "," + item.Food_Price + ", @img)", con1);

            cmd1.Parameters.AddWithValue("@img", img);
            cmd1.ExecuteNonQuery();
            con1.Close();
        }
Exemplo n.º 9
0
        public user_cart()
        {
            InitializeComponent();
            Cart.signed = false;
            bool          receipt_empty = true;
            SqlConnection sqlConnection = new SqlConnection(connection_string);

            sqlConnection.Open();
            SqlCommand sqlCommand = new SqlCommand("delete from Receipt", sqlConnection);

            sqlCommand.ExecuteNonQuery();
            sqlCommand.Dispose();
            sqlCommand = new SqlCommand("select Cart from Users where FullName=@FullName", sqlConnection);
            sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName);
            SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();

            sqlDataReader.Read();
            List <string> cart = sqlDataReader.GetValue(0).ToString().Split(',').ToList();

            sqlCommand.Dispose();
            sqlDataReader.Close();
            sqlCommand    = new SqlCommand("select * from Food_Menu", sqlConnection);
            sqlDataReader = sqlCommand.ExecuteReader();
            List <Food_Item> Food_List = new List <Food_Item>();

            while (sqlDataReader.Read())
            {
                var item = new Food_Item();
                item.Name_Food        = sqlDataReader.GetValue(0).ToString();
                item.Cost_Food        = sqlDataReader.GetValue(1).ToString();
                item.Information_Food = sqlDataReader.GetValue(2).ToString();
                item.Date_Food        = sqlDataReader.GetValue(3).ToString();
                item.Uri_Food         = sqlDataReader.GetValue(4).ToString();
                item.Kind_Food        = sqlDataReader.GetValue(5).ToString();
                item.Number_Food      = sqlDataReader.GetValue(6).ToString();
                Food_List.Add(item);
            }
            foreach (var item in Food_List.Where(x => cart.Contains(x.Name_Food)))
            {
                receipt_empty = false;
                main_stack.Children.Add(Cart.Construct(item.Name_Food, item.Cost_Food, item.Information_Food, item.Date_Food, item.Uri_Food, item.Kind_Food, item.Number_Food, cart));
                receipt.Children.Add(Cart.receipt(item.Name_Food, item.Cost_Food, cart));
            }
            if (!receipt_empty)
            {
                Customer_Name_cart.Content = "Customer : " + Current_user.FullName;
                receipt.Children.Add(Cart.Total_Price());
            }
            sqlDataReader.Close();
            sqlCommand.Dispose();
            sqlConnection.Close();
        }
Exemplo n.º 10
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            Food_Item food_Item = db.Food_Item.Find(id);

            if (food_Item == null)
            {
                return(HttpNotFound());
            }
            return(View(food_Item));
        }
        public Food_Item GetFoodItemById(int foodItemId)
        {
            try
            {
                //Call GetAllFoodItems() to fetch all Food Items
                Food_Item foodItem = fs.GetFoodItemById(foodItemId);

                //return the response
                return(foodItem);
            }
            catch (FoodOrderException)
            {
                //rethrow
                throw;
            }
        }
        //GET: /RecipeIngredients/
        /// <summary>
        ///  
        /// </summary>
        /// <param name="recid"></param>
        /// <returns></returns>
        public ActionResult RecipeIngredients(int recid)
        {
            /* SpeedyChefDataContext scdc = new SpeedyChefDataContext();
             IEnumerable<RecipeIngredientsResult> recipeIngredients = null;

             recipeIngredients = scdc.RecipeIngredients(recid);
             return Json(recipeIngredients, JsonRequestBehavior.AllowGet);*/
            Food_Item[] tempResult = new Food_Item[4];
            tempResult[0] = new Food_Item();
            tempResult[0].Foodname = "2 small garlic cloves";
            tempResult[1] = new Food_Item();
            tempResult[1].Foodname = "2 sticks unsalted butter";
            tempResult[2] = new Food_Item();
            tempResult[2].Foodname = "1 1/2 teaspoons finely chopped flat-leaf parsley";
            tempResult[3] = new Food_Item();
            tempResult[3].Foodname = "2 (1 1/4-pound) live lobsters";
            return Json(tempResult, JsonRequestBehavior.AllowGet);
        }
Exemplo n.º 13
0
 //GET: /RecipeIngredients/
 /// <summary>
 ///
 /// </summary>
 /// <param name="recid"></param>
 /// <returns></returns>
 public ActionResult RecipeIngredients(int recid)
 {
     /* SpeedyChefDataContext scdc = new SpeedyChefDataContext();
      * IEnumerable<RecipeIngredientsResult> recipeIngredients = null;
      *
      * recipeIngredients = scdc.RecipeIngredients(recid);
      * return Json(recipeIngredients, JsonRequestBehavior.AllowGet);*/
     Food_Item[] tempResult = new Food_Item[4];
     tempResult[0]          = new Food_Item();
     tempResult[0].Foodname = "2 small garlic cloves";
     tempResult[1]          = new Food_Item();
     tempResult[1].Foodname = "2 sticks unsalted butter";
     tempResult[2]          = new Food_Item();
     tempResult[2].Foodname = "1 1/2 teaspoons finely chopped flat-leaf parsley";
     tempResult[3]          = new Food_Item();
     tempResult[3].Foodname = "2 (1 1/4-pound) live lobsters";
     return(Json(tempResult, JsonRequestBehavior.AllowGet));
 }
 /// <summary>
 /// Provides the Cart details of a specific customer
 /// </summary>
 /// <param name="customerId">integer value to uniquely identify the customer</param>
 /// <returns>Cart in form of object of class Order</returns>
 public Order GetCartByCustomerId(int customerId)
 {
     using (Online_Food_Ordering_SystemEntities1 db = new Online_Food_Ordering_SystemEntities1())
     {
         var cartQuery = db.Orders.FirstOrDefault(o => (o.isActive && o.Customer_Id == customerId && o.Submit_Status == false));
         var cart      = new Order();
         if (cartQuery != null)
         {
             cart.Customer_Id    = cartQuery.Customer_Id;
             cart.Order_Id       = cartQuery.Order_Id;
             cart.Order_Items    = new List <Order_Item>();
             cart.Creation_Date  = cartQuery.Creation_Date;
             cart.Employee_Id    = cartQuery.Employee_Id;
             cart.Food_Store_Id  = cartQuery.Food_Store_Id;
             cart.Order_date     = cartQuery.Order_date;
             cart.Total_Price    = cartQuery.Total_Price;
             cart.Total_Quantity = cartQuery.Total_Quantity;
         }
         List <Order_Item> cartItemsQuery = db.Order_Items.Where(item => item.Order_Id == cart.Order_Id).ToList();
         List <Order_Item> cartItems      = new List <Order_Item>();
         if (cartItemsQuery != null)
         {
             foreach (Order_Item singleItem in cartItemsQuery)
             {
                 var       currentItemFoodObject = db.Food_Items.FirstOrDefault(fitem => fitem.Food_Item_Id == singleItem.Food_Item_Id);
                 Food_Item food = currentItemFoodObject != null
                     ?
                                  new Food_Item()
                 {
                     Food_Name = currentItemFoodObject.Food_Name, Food_Type = currentItemFoodObject.Food_Type, ImagePath = currentItemFoodObject.ImagePath
                 }
                     : null;
                 cartItems.Add(new Order_Item()
                 {
                     Order_Id = singleItem.Order_Id, Food_Item_Id = singleItem.Food_Item_Id, Food_Items = food, Price = singleItem.Price, Quantity = singleItem.Quantity
                 });
             }
         }
         cart.Order_Items = cartItems;
         return(cart);
     }
 }
Exemplo n.º 15
0
        /// <summary>
        /// Method fetches the Food Item corresponding to the passed foodItemId
        /// </summary>
        /// <param name="foodItemId">indicates id of food item</param>
        /// <returns>returns Food_Item type value</returns>
        public Food_Item GetFoodItemById(int foodItemId)
        {
            try
            {
                //instantiating Online_Food_Ordering_SystemEntities3 Context class
                using (Online_Food_Ordering_SystemEntities1 db = new Online_Food_Ordering_SystemEntities1())
                {
                    //LINQ query to find Food Item corresponding to passed foodItemId
                    Food_Item item = db.Food_Items.Where(f => f.Food_Item_Id == foodItemId && f.IsActive == true).FirstOrDefault();

                    //return response
                    return(item);
                }
            }
            catch (Exception ex)
            {
                //throw our user defined FoodOrderException
                throw new FoodOrderException(ex.Message);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// AddFoodItem(Food_Items foodItem) adds the foodItem to the Food_Items table
        /// </summary>
        /// <param name="foodItem">object of type Food_Item</param>
        /// <returns>integer value indicating the Id of the added foodItem</returns>
        public int AddFoodItem(Food_Item foodItem)
        {
            try
            {
                //instantiating Online_Food_Ordering_SystemEntities3 Context class
                using (Online_Food_Ordering_SystemEntities1 db = new Online_Food_Ordering_SystemEntities1())
                {
                    //check if the foodItem already exists
                    Food_Item item = db.Food_Items.Where(f => f.Food_Name.Equals(foodItem.Food_Name, StringComparison.OrdinalIgnoreCase) && f.Food_Type.Equals(foodItem.Food_Type, StringComparison.OrdinalIgnoreCase) && f.IsActive == true).FirstOrDefault();

                    if (item != null)
                    {
                        //if exists then throw exception
                        throw new FoodOrderException("Food Item already present");
                    }

                    //set IsActive to true
                    foodItem.IsActive = true;

                    //set Creation Date to be the
                    foodItem.Creation_Date = DateTime.Now;

                    //use LINQ query to Add Food Items from table Food_Items
                    db.Food_Items.Add(foodItem);

                    //save changes to the database
                    db.SaveChanges();

                    Food_Item fItem = db.Food_Items.Where(f => f.Food_Item_Id == foodItem.Food_Item_Id && f.IsActive == true).FirstOrDefault();

                    return(fItem.Food_Item_Id);
                }
            }
            catch (Exception ex)
            {
                //throw user defined FoodOrderException
                throw new FoodOrderException(ex.Message);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Method updates or edits the changes of the passed foodItem in the Food_Items table
        /// </summary>
        /// <param name="foodItem">object of type FoodItem </param>
        /// <returns>boolean value indicating whether fooItem is updated or not</returns>
        public bool UpdateFoodItem(Food_Item foodItem)
        {
            try
            {
                //instantiating Online_Food_Ordering_SystemEntities3 Context class
                using (Online_Food_Ordering_SystemEntities1 db = new Online_Food_Ordering_SystemEntities1())
                {
                    //use LINQ query to find the Food Item with id foodItem.Food_Item_Id
                    Food_Item item = db.Food_Items.Where(f => f.Food_Item_Id == foodItem.Food_Item_Id && f.IsActive == true).FirstOrDefault();

                    if (item != null)
                    {
                        //update  Food Item details
                        item.Food_Name = foodItem.Food_Name;
                        item.Food_Type = foodItem.Food_Type;
                        item.Price     = foodItem.Price;

                        //save changes to the database
                        db.SaveChanges();

                        return(true);
                    }


                    else
                    {
                        throw new FoodOrderException("Food item does not exist");
                    }
                }
            }
            catch (Exception ex)
            {
                //throw user defined FoodOrderException
                throw new FoodOrderException(ex.Message);
            }
        }
Exemplo n.º 18
0
        private void Submit_Click(object sender, RoutedEventArgs e)
        {
            if (Cart.signed && (online_pay.IsChecked == true || cash_pay.IsChecked == true) && receipt.Children.Count != 0)
            {
                MessageBox.Show("order is submited");
                if (cash_pay.IsChecked == true)
                {
                    MessageBox.Show("Thank you for your Buy your order will be delivered soon");
                    PrintDialog printDialog = new PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        printDialog.PrintVisual(receipt, "Stack panel description");
                    }
                }
                if (online_pay.IsChecked == true)
                {
                    string total_price = current_order_cost.ToString();
                    MessageBox.Show($"{total_price:N2}  was deducted from your account");
                    MessageBox.Show("Thank you for your Buy your order will be delivered soon");
                    PrintDialog printDialog = new PrintDialog();
                    if (printDialog.ShowDialog() == true)
                    {
                        //StackPanel st = new StackPanel();
                        //foreach (UIElement item in receipt.Children)
                        //{
                        //	st.Children.Add(item);
                        //}
                        //st.Children.Add(discount);
                        //st.Children.Add(signiture);
                        printDialog.PrintVisual(factor, "Stack panel description");
                    }
                }
                SqlConnection sqlConnection = new SqlConnection(" Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = \"C:\\Users\\emad&javad\\Desktop\\visual studio\\Final_Project\\Final_Project\\database.mdf\"; Integrated Security = True; Connect Timeout = 30");
                sqlConnection.Open();
                SqlCommand sqlCommand = new SqlCommand("update Users set Order_Number=Order_Number+1 where FullName=@FullName", sqlConnection);
                sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName);
                sqlCommand.ExecuteNonQuery();
                sqlCommand.Dispose();
                sqlCommand = new SqlCommand("select Order_Number from Users where FullName=@FullName", sqlConnection);
                sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName);
                SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
                sqlDataReader.Read();
                double order_num = double.Parse(sqlDataReader.GetValue(0).ToString());
                sqlDataReader.Close();
                sqlCommand.Dispose();
                sqlCommand    = new SqlCommand("select * from Receipt", sqlConnection);
                sqlDataReader = sqlCommand.ExecuteReader();
                List <Food_Item> order       = new List <Food_Item>();
                string           Name_Food   = "";
                string           Cost_Food   = "";
                string           Number_Food = "";
                while (sqlDataReader.Read())
                {
                    Food_Item a = new Food_Item();
                    a.Name_Food   = sqlDataReader.GetValue(0).ToString();
                    a.Cost_Food   = sqlDataReader.GetValue(1).ToString();
                    a.Number_Food = sqlDataReader.GetValue(2).ToString();
                    order.Add(a);
                }
                foreach (var item in order)
                {
                    Name_Food   += item.Name_Food + ",";
                    Cost_Food   += item.Cost_Food + ",";
                    Number_Food += item.Number_Food + ",";
                }
                Name_Food   = Name_Food.Substring(0, Name_Food.Length - 1);
                Cost_Food   = Cost_Food.Substring(0, Cost_Food.Length - 1);
                Number_Food = Number_Food.Substring(0, Number_Food.Length - 1);
                sqlDataReader.Close();
                sqlCommand.Dispose();
                sqlCommand = new SqlCommand("update Users set Orders+=@Orders where FullName=@FullName ", sqlConnection);
                sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName);
                sqlCommand.Parameters.AddWithValue("@Orders", order_num.ToString() + ":" + Name_Food + ":" + Cost_Food + ":" + Number_Food + "/");
                sqlCommand.ExecuteNonQuery();
                sqlCommand.Dispose();
                sqlCommand = new SqlCommand("update Users set Cart=@Cart where FullName=@FullName ", sqlConnection);
                sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName);
                sqlCommand.Parameters.AddWithValue("@Cart", ",");
                sqlCommand.ExecuteNonQuery();
                sqlConnection.Close();
                receipt.Children.Clear();
                main_stack.Children.Clear();
                signiture.Strokes.Clear();
                online_pay.IsChecked = cash_pay.IsChecked = false;
            }

            else if (online_pay.IsChecked == false && cash_pay.IsChecked == false)
            {
                MessageBox.Show("you have choose payment way");
            }
            else if (receipt.Children.Count == 0)
            {
                MessageBox.Show("Nothing to Buy");
            }
            else
            {
                MessageBox.Show("you have to sign before submit");
            }
        }
Exemplo n.º 19
0
            public static StackPanel Total_Price()
            {
                SqlConnection sqlConnection = new SqlConnection(" Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = \"C:\\Users\\emad&javad\\Desktop\\visual studio\\Final_Project\\Final_Project\\database.mdf\"; Integrated Security = True; Connect Timeout = 30");

                sqlConnection.Open();
                SqlCommand       sqlCommand    = new SqlCommand("select Name_Food,Cost_Food,Number_Food from Receipt", sqlConnection);
                SqlDataReader    sqlDataReader = sqlCommand.ExecuteReader();
                List <Food_Item> Food          = new List <Food_Item>();

                while (sqlDataReader.Read())
                {
                    Food_Item a = new Food_Item();
                    a.Name_Food   = sqlDataReader.GetValue(0).ToString();
                    a.Cost_Food   = sqlDataReader.GetValue(1).ToString();
                    a.Number_Food = sqlDataReader.GetValue(2).ToString();
                    Food.Add(a);
                }
                sqlDataReader.Close();
                sqlCommand.Dispose();
                //order price
                StackPanel       stackPanel = new StackPanel();
                Grid             grid       = new Grid();
                ColumnDefinition c1         = new ColumnDefinition();

                c1.Width = new GridLength(2.5, GridUnitType.Star);
                ColumnDefinition c2 = new ColumnDefinition();

                c2.Width = new GridLength(1, GridUnitType.Star);
                grid.ColumnDefinitions.Add(c1);
                grid.ColumnDefinitions.Add(c2);
                Label lable1 = new Label();
                var   bc     = new BrushConverter();

                lable1.Foreground = (System.Windows.Media.Brush)bc.ConvertFrom("#FFFFEFDD");
                lable1.Content    = "Order Cost";
                lable1.FontWeight = FontWeights.Bold;
                lable1.FontStyle  = FontStyles.Italic;
                lable1.FontSize   = 16;
                lable1.Margin     = new Thickness(0, 0, 10, 0);
                Grid.SetColumn(lable1, 0);
                Label lable2 = new Label();

                bc = new BrushConverter();
                lable2.Foreground = (System.Windows.Media.Brush)bc.ConvertFrom("#FFFFEFDD");
                double total = Food.Select(a => (double.Parse(a.Cost_Food) * double.Parse(a.Number_Food))).Sum(x => x);

                lable2.Content    = $"{ total.ToString():N2}$";
                lable2.FontSize   = 16;
                lable2.FontWeight = FontWeights.Bold;
                lable2.FontStyle  = FontStyles.Italic;
                lable2.Margin     = new Thickness(5, 0, 10, 0);
                Grid.SetColumn(lable2, 1);
                grid.Children.Add(lable2);
                grid.Children.Add(lable1);
                grid.Margin = new Thickness(0, 10, 0, 0);
                stackPanel.Children.Add(grid);
                current_order_cost = total;
                //order price

                sqlCommand = new SqlCommand("select Order_Number from Users where FullName=@FullName", sqlConnection);
                sqlCommand.Parameters.AddWithValue("@FullName", Current_user.FullName);
                sqlDataReader = sqlCommand.ExecuteReader();
                sqlDataReader.Read();
                int order_num = int.Parse(sqlDataReader.GetValue(0).ToString());

                sqlDataReader.Close();
                sqlCommand.Dispose();
                sqlConnection.Close();
                StackPanel stackPanel2 = new StackPanel();
                StackPanel stackPanel3 = new StackPanel();

                if (order_num <= 4)
                {
                    //tax
                    stackPanel2 = new StackPanel();
                    Grid             grid2 = new Grid();
                    ColumnDefinition c21   = new ColumnDefinition();
                    c21.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition c22 = new ColumnDefinition();
                    c22.Width = new GridLength(1, GridUnitType.Star);
                    grid2.ColumnDefinitions.Add(c21);
                    grid2.ColumnDefinitions.Add(c22);
                    Label lable21 = new Label();
                    var   bc2     = new BrushConverter();
                    lable21.Foreground = (System.Windows.Media.Brush)bc2.ConvertFrom("#FFFFEFDD");
                    lable21.Content    = "Tax Cost";
                    lable21.FontWeight = FontWeights.Bold;
                    lable21.FontStyle  = FontStyles.Italic;
                    lable21.FontSize   = 16;
                    lable21.Margin     = new Thickness(0, 0, 10, 0);
                    Grid.SetColumn(lable21, 0);
                    Label lable22 = new Label();
                    bc2 = new BrushConverter();
                    lable22.Foreground = (System.Windows.Media.Brush)bc2.ConvertFrom("#FFFFEFDD");
                    double total2 = Food.Select(a => (double.Parse(a.Cost_Food) * double.Parse(a.Number_Food))).Sum(x => x) * (100.0 / 124.0) * 0.09;
                    lable22.Content    = $"{ total2:N2}$";
                    lable22.FontSize   = 16;
                    lable22.FontWeight = FontWeights.Bold;
                    lable22.FontStyle  = FontStyles.Italic;
                    lable22.Margin     = new Thickness(5, 0, 10, 0);
                    Grid.SetColumn(lable22, 1);
                    grid2.Children.Add(lable22);
                    grid2.Children.Add(lable21);
                    grid2.Margin = new Thickness(0, 10, 0, 0);
                    stackPanel2.Children.Add(grid2);
                    current_order_cost += total2;
                    //tax

                    //Amazing Offer
                    stackPanel3 = new StackPanel();
                    Grid             grid3 = new Grid();
                    ColumnDefinition c31   = new ColumnDefinition();
                    c31.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition c32 = new ColumnDefinition();
                    c32.Width = new GridLength(1, GridUnitType.Star);
                    grid3.ColumnDefinitions.Add(c31);
                    grid3.ColumnDefinitions.Add(c32);
                    Label lable31 = new Label();
                    var   bc3     = new BrushConverter();
                    lable31.Foreground = (System.Windows.Media.Brush)bc3.ConvertFrom("#FFFFEFDD");
                    lable31.Content    = "Amazing Offer";
                    lable31.FontWeight = FontWeights.Bold;
                    lable31.FontStyle  = FontStyles.Italic;
                    lable31.FontSize   = 16;
                    lable31.Margin     = new Thickness(0, 0, 10, 0);
                    Grid.SetColumn(lable31, 0);
                    Label lable32 = new Label();
                    bc3 = new BrushConverter();
                    lable32.Foreground = (System.Windows.Media.Brush)bc3.ConvertFrom("#FFFFEFDD");
                    double total3 = 0;
                    lable32.Content    = total3.ToString() + "$";
                    lable32.FontSize   = 16;
                    lable32.FontWeight = FontWeights.Bold;
                    lable32.FontStyle  = FontStyles.Italic;
                    lable32.Margin     = new Thickness(5, 0, 10, 0);
                    Grid.SetColumn(lable32, 1);
                    grid3.Children.Add(lable32);
                    grid3.Children.Add(lable31);
                    grid3.Margin = new Thickness(0, 10, 0, 0);
                    stackPanel3.Children.Add(grid3);
                    current_order_cost -= total3;
                    //Amazing Offer
                }

                else if (order_num >= 5 && order_num <= 8)
                {
                    //tax
                    stackPanel2 = new StackPanel();
                    Grid             grid2 = new Grid();
                    ColumnDefinition c21   = new ColumnDefinition();
                    c21.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition c22 = new ColumnDefinition();
                    c22.Width = new GridLength(1, GridUnitType.Star);
                    grid2.ColumnDefinitions.Add(c21);
                    grid2.ColumnDefinitions.Add(c22);
                    Label lable21 = new Label();
                    var   bc2     = new BrushConverter();
                    lable21.Foreground = (System.Windows.Media.Brush)bc2.ConvertFrom("#FFFFEFDD");
                    lable21.Content    = "Tax Cost";
                    lable21.FontWeight = FontWeights.Bold;
                    lable21.FontStyle  = FontStyles.Italic;
                    lable21.FontSize   = 16;
                    lable21.Margin     = new Thickness(0, 0, 10, 0);
                    Grid.SetColumn(lable21, 0);
                    Label lable22 = new Label();
                    bc2 = new BrushConverter();
                    lable22.Foreground = (System.Windows.Media.Brush)bc2.ConvertFrom("#FFFFEFDD");
                    double total2 = Food.Select(a => (double.Parse(a.Cost_Food) * double.Parse(a.Number_Food))).Sum(x => x) * (100.0 / 124.0) * 0.07;
                    lable22.Content    = $"{ total2:N2}$";
                    lable22.FontSize   = 16;
                    lable22.FontWeight = FontWeights.Bold;
                    lable22.FontStyle  = FontStyles.Italic;
                    lable22.Margin     = new Thickness(5, 0, 10, 0);
                    Grid.SetColumn(lable22, 1);
                    grid2.Children.Add(lable22);
                    grid2.Children.Add(lable21);
                    grid2.Margin = new Thickness(0, 10, 0, 0);
                    stackPanel2.Children.Add(grid2);
                    current_order_cost += total2;
                    //tax

                    //Amazing Offer
                    stackPanel3 = new StackPanel();
                    Grid             grid3 = new Grid();
                    ColumnDefinition c31   = new ColumnDefinition();
                    c31.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition c32 = new ColumnDefinition();
                    c32.Width = new GridLength(1, GridUnitType.Star);
                    grid3.ColumnDefinitions.Add(c31);
                    grid3.ColumnDefinitions.Add(c32);
                    Label lable31 = new Label();
                    var   bc3     = new BrushConverter();
                    lable31.Foreground = (System.Windows.Media.Brush)bc3.ConvertFrom("#FFFFEFDD");
                    lable31.Content    = "Amazing Offer";
                    lable31.FontWeight = FontWeights.Bold;
                    lable31.FontStyle  = FontStyles.Italic;
                    lable31.FontSize   = 16;
                    lable31.Margin     = new Thickness(0, 0, 10, 0);
                    Grid.SetColumn(lable31, 0);
                    Label lable32 = new Label();
                    bc3 = new BrushConverter();
                    lable32.Foreground = (System.Windows.Media.Brush)bc3.ConvertFrom("#FFFFEFDD");
                    double total3 = Food.Select(a => (double.Parse(a.Cost_Food) * double.Parse(a.Number_Food))).Sum(x => x) * 0.05;
                    lable32.Content    = $"{ total3:N2}$";
                    lable32.FontSize   = 16;
                    lable32.FontWeight = FontWeights.Bold;
                    lable32.FontStyle  = FontStyles.Italic;
                    lable32.Margin     = new Thickness(5, 0, 10, 0);
                    Grid.SetColumn(lable32, 1);
                    grid3.Children.Add(lable32);
                    grid3.Children.Add(lable31);
                    grid3.Margin = new Thickness(0, 10, 0, 0);
                    stackPanel3.Children.Add(grid3);
                    current_order_cost -= total3;
                    //Amazing Offer
                }

                else if (order_num >= 9 && order_num <= 12)
                {
                    //tax
                    stackPanel2 = new StackPanel();
                    Grid             grid2 = new Grid();
                    ColumnDefinition c21   = new ColumnDefinition();
                    c21.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition c22 = new ColumnDefinition();
                    c22.Width = new GridLength(1, GridUnitType.Star);
                    grid2.ColumnDefinitions.Add(c21);
                    grid2.ColumnDefinitions.Add(c22);
                    Label lable21 = new Label();
                    var   bc2     = new BrushConverter();
                    lable21.Foreground = (System.Windows.Media.Brush)bc2.ConvertFrom("#FFFFEFDD");
                    lable21.Content    = "Tax Cost";
                    lable21.FontWeight = FontWeights.Bold;
                    lable21.FontStyle  = FontStyles.Italic;
                    lable21.FontSize   = 16;
                    lable21.Margin     = new Thickness(0, 0, 10, 0);
                    Grid.SetColumn(lable21, 0);
                    Label lable22 = new Label();
                    bc2 = new BrushConverter();
                    lable22.Foreground = (System.Windows.Media.Brush)bc2.ConvertFrom("#FFFFEFDD");
                    double total2 = Food.Select(a => (double.Parse(a.Cost_Food) * double.Parse(a.Number_Food))).Sum(x => x) * (100.0 / 124.0) * 0.05;
                    lable22.Content    = $"{ total2:N2}$";
                    lable22.FontSize   = 16;
                    lable22.FontWeight = FontWeights.Bold;
                    lable22.FontStyle  = FontStyles.Italic;
                    lable22.Margin     = new Thickness(5, 0, 10, 0);
                    Grid.SetColumn(lable22, 1);
                    grid2.Children.Add(lable22);
                    grid2.Children.Add(lable21);
                    grid2.Margin = new Thickness(0, 10, 0, 0);
                    stackPanel2.Children.Add(grid2);
                    current_order_cost += total2;
                    //tax

                    //Amazing Offer
                    stackPanel3 = new StackPanel();
                    Grid             grid3 = new Grid();
                    ColumnDefinition c31   = new ColumnDefinition();
                    c31.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition c32 = new ColumnDefinition();
                    c32.Width = new GridLength(1, GridUnitType.Star);
                    grid3.ColumnDefinitions.Add(c31);
                    grid3.ColumnDefinitions.Add(c32);
                    Label lable31 = new Label();
                    var   bc3     = new BrushConverter();
                    lable31.Foreground = (System.Windows.Media.Brush)bc3.ConvertFrom("#FFFFEFDD");
                    lable31.Content    = "Amazing Offer";
                    lable31.FontWeight = FontWeights.Bold;
                    lable31.FontStyle  = FontStyles.Italic;
                    lable31.FontSize   = 16;
                    lable31.Margin     = new Thickness(0, 0, 10, 0);
                    Grid.SetColumn(lable31, 0);
                    Label lable32 = new Label();
                    bc3 = new BrushConverter();
                    lable32.Foreground = (System.Windows.Media.Brush)bc3.ConvertFrom("#FFFFEFDD");
                    double total3 = Food.Select(a => (double.Parse(a.Cost_Food) * double.Parse(a.Number_Food))).Sum(x => x) * 0.08;
                    lable32.Content    = $"{ total3:N2}$";
                    lable32.FontSize   = 16;
                    lable32.FontWeight = FontWeights.Bold;
                    lable32.FontStyle  = FontStyles.Italic;
                    lable32.Margin     = new Thickness(5, 0, 10, 0);
                    Grid.SetColumn(lable32, 1);
                    grid3.Children.Add(lable32);
                    grid3.Children.Add(lable31);
                    grid3.Margin = new Thickness(0, 10, 0, 0);
                    stackPanel3.Children.Add(grid3);
                    current_order_cost -= total3;
                    //Amazing Offer
                }

                else if (order_num >= 13)
                {
                    //tax
                    stackPanel2 = new StackPanel();
                    Grid             grid2 = new Grid();
                    ColumnDefinition c21   = new ColumnDefinition();
                    c21.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition c22 = new ColumnDefinition();
                    c22.Width = new GridLength(1, GridUnitType.Star);
                    grid2.ColumnDefinitions.Add(c21);
                    grid2.ColumnDefinitions.Add(c22);
                    Label lable21 = new Label();
                    var   bc2     = new BrushConverter();
                    lable21.Foreground = (System.Windows.Media.Brush)bc2.ConvertFrom("#FFFFEFDD");
                    lable21.Content    = "Tax Cost";
                    lable21.FontWeight = FontWeights.Bold;
                    lable21.FontStyle  = FontStyles.Italic;
                    lable21.FontSize   = 16;
                    lable21.Margin     = new Thickness(0, 0, 10, 0);
                    Grid.SetColumn(lable21, 0);
                    Label lable22 = new Label();
                    bc2 = new BrushConverter();
                    lable22.Foreground = (System.Windows.Media.Brush)bc2.ConvertFrom("#FFFFEFDD");
                    double total2 = 0;
                    lable22.Content    = $"{ total2:N2}$";
                    lable22.FontSize   = 16;
                    lable22.FontWeight = FontWeights.Bold;
                    lable22.FontStyle  = FontStyles.Italic;
                    lable22.Margin     = new Thickness(5, 0, 10, 0);
                    Grid.SetColumn(lable22, 1);
                    grid2.Children.Add(lable22);
                    grid2.Children.Add(lable21);
                    grid2.Margin = new Thickness(0, 10, 0, 0);
                    stackPanel2.Children.Add(grid2);
                    current_order_cost += total2;
                    //tax

                    //Amazing Offer
                    stackPanel3 = new StackPanel();
                    Grid             grid3 = new Grid();
                    ColumnDefinition c31   = new ColumnDefinition();
                    c31.Width = new GridLength(2.5, GridUnitType.Star);
                    ColumnDefinition c32 = new ColumnDefinition();
                    c32.Width = new GridLength(1, GridUnitType.Star);
                    grid3.ColumnDefinitions.Add(c31);
                    grid3.ColumnDefinitions.Add(c32);
                    Label lable31 = new Label();
                    var   bc3     = new BrushConverter();
                    lable31.Foreground = (System.Windows.Media.Brush)bc3.ConvertFrom("#FFFFEFDD");
                    lable31.Content    = "Amazing Offer";
                    lable31.FontWeight = FontWeights.Bold;
                    lable31.FontStyle  = FontStyles.Italic;
                    lable31.FontSize   = 16;
                    lable31.Margin     = new Thickness(0, 0, 10, 0);
                    Grid.SetColumn(lable31, 0);
                    Label lable32 = new Label();
                    bc3 = new BrushConverter();
                    lable32.Foreground = (System.Windows.Media.Brush)bc3.ConvertFrom("#FFFFEFDD");
                    double total3 = Food.Select(a => (double.Parse(a.Cost_Food) * double.Parse(a.Number_Food))).Sum(x => x) * 0.10;
                    lable32.Content    = $"{ total3:N2}$";
                    lable32.FontSize   = 16;
                    lable32.FontWeight = FontWeights.Bold;
                    lable32.FontStyle  = FontStyles.Italic;
                    lable32.Margin     = new Thickness(5, 0, 10, 0);
                    Grid.SetColumn(lable32, 1);
                    grid3.Children.Add(lable32);
                    grid3.Children.Add(lable31);
                    grid3.Margin = new Thickness(0, 10, 0, 0);
                    stackPanel3.Children.Add(grid3);
                    current_order_cost -= total3;
                    //Amazing Offer
                }

                StackPanel       stackPanel4 = new StackPanel();
                Grid             grid4       = new Grid();
                ColumnDefinition c41         = new ColumnDefinition();

                c41.Width = new GridLength(2.5, GridUnitType.Star);
                ColumnDefinition c42 = new ColumnDefinition();

                c42.Width = new GridLength(1, GridUnitType.Star);
                grid4.ColumnDefinitions.Add(c41);
                grid4.ColumnDefinitions.Add(c42);
                Label lable41 = new Label();
                var   bc4     = new BrushConverter();

                lable41.Foreground = (System.Windows.Media.Brush)bc4.ConvertFrom("#FFFFEFDD");
                lable41.Content    = "Total Cost";
                lable41.FontWeight = FontWeights.Bold;
                lable41.FontStyle  = FontStyles.Italic;
                lable41.FontSize   = 16;
                lable41.Margin     = new Thickness(0, 0, 10, 0);
                Grid.SetColumn(lable41, 0);
                Label lable42 = new Label();

                bc4 = new BrushConverter();
                lable42.Foreground = (System.Windows.Media.Brush)bc4.ConvertFrom("#FFFFEFDD");
                double total4 = current_order_cost;

                lable42.Content    = $"{current_order_cost:N2}$";
                lable42.FontSize   = 16;
                lable42.FontWeight = FontWeights.Bold;
                lable42.FontStyle  = FontStyles.Italic;
                lable42.Margin     = new Thickness(5, 0, 10, 0);
                Grid.SetColumn(lable42, 1);
                grid4.Children.Add(lable42);
                grid4.Children.Add(lable41);
                grid4.Margin = new Thickness(0, 10, 0, 0);
                stackPanel4.Children.Add(grid4);

                StackPanel main = new StackPanel();

                main.Children.Add(stackPanel);
                main.Children.Add(stackPanel2);
                main.Children.Add(stackPanel3);
                main.Children.Add(stackPanel4);
                return(main);
            }
        /// <summary>
        /// Provides history of all previous orders of a specific customer
        /// </summary>
        /// <param name="customerId">integer value to uniquely identify the customer</param>
        /// <param name="fromEntryNo">integer value that will query the database from which entry number to begin from</param>
        /// <param name="toEntryNo">integer value that will query the database till which entry number to get record</param>
        /// <returns>List of all the past orders</returns>
        public List <Order> GetOrdersByCustomerId(int customerId, int fromEntryNo, int toEntryNo)
        {
            List <Order> OrdersList = new List <Order>();

            using (Online_Food_Ordering_SystemEntities1 db = new Online_Food_Ordering_SystemEntities1())
            {
                try
                {
                    int totalOrdersCount = db.Orders.Select(o => o.isActive && o.Customer_Id == customerId && o.Submit_Status).Count();
                    if (fromEntryNo > totalOrdersCount)
                    {
                        throw new FoodOrderException($"Not enough entries to start from {fromEntryNo}");
                    }
                    if (toEntryNo > totalOrdersCount)
                    {
                        toEntryNo = totalOrdersCount;
                    }
                    IQueryable <Order> OrdersQuery = db.Orders.Where(o => o.isActive && o.Customer_Id == customerId && o.Submit_Status);
                    if (OrdersQuery != null)
                    {
                        foreach (Order singleOrder in OrdersQuery)
                        {
                            Order orderToAdd = new Order()
                            {
                                Customer_Id    = singleOrder.Customer_Id,
                                Order_date     = singleOrder.Order_date,
                                Order_Id       = singleOrder.Order_Id,
                                Employee_Id    = singleOrder.Employee_Id,
                                Food_Store_Id  = singleOrder.Food_Store_Id,
                                Total_Price    = singleOrder.Total_Price,
                                Total_Quantity = singleOrder.Total_Quantity,
                                isActive       = singleOrder.isActive,
                                Submit_Status  = singleOrder.Submit_Status
                            };
                            List <Order_Item> orderItemsQuery = db.Order_Items.Where(item => item.Order_Id == orderToAdd.Order_Id).ToList();
                            List <Order_Item> orderItems      = new List <Order_Item>();
                            if (orderItemsQuery != null)
                            {
                                foreach (Order_Item singleItem in orderItemsQuery)
                                {
                                    var       currentItemFoodObject = db.Food_Items.FirstOrDefault(fitem => fitem.Food_Item_Id == singleItem.Food_Item_Id);
                                    Food_Item food = currentItemFoodObject != null
                                        ?
                                                     new Food_Item()
                                    {
                                        Food_Name = currentItemFoodObject.Food_Name, Food_Type = currentItemFoodObject.Food_Type, ImagePath = currentItemFoodObject.ImagePath
                                    }
                                        : null;
                                    orderItems.Add(new Order_Item()
                                    {
                                        Order_Id = singleItem.Order_Id, Food_Item_Id = singleItem.Food_Item_Id, Food_Items = food, Price = singleItem.Price, Quantity = singleItem.Quantity
                                    });
                                }
                            }
                            orderToAdd.Order_Items = orderItems;
                            OrdersList.Add(orderToAdd);
                        }
                    }
                }
                catch
                {
                    throw new FoodOrderException("Not able to fetch Order List");
                }
                OrdersList.Reverse();
                return(OrdersList);
            }
        }
        /// <summary>
        /// Updates
        /// </summary>
        /// <param name="customerId"></param>
        /// <param name="foodItemId"></param>
        /// <param name="foodItemQuantity"></param>
        /// <returns></returns>
        public bool UpdateCart(int customerId, ICollection <Order_Item> orderItems)
        {
            using (Online_Food_Ordering_SystemEntities1 db = new Online_Food_Ordering_SystemEntities1())
            {
                bool isUpdated = false;

                try
                {
                    //find if customer exists, if not then:
                    if (db.Customers.Where(c => c.Customer_Id == customerId).Count() == 0)
                    {
                        throw new FoodOrderException("Customer Doesn't Exist");
                    }
                    //find cart for given customer
                    Order cart = db.Orders.FirstOrDefault(o => (o.isActive && o.Customer_Id == customerId && o.Submit_Status == false));
                    //if cart doesn't exist for customer
                    int finalTotalPrice    = 0;
                    int finalTotalQuantity = 0;
                    if (cart == null)
                    {
                        foreach (Order_Item o in orderItems)
                        {
                            //setting the latest price of the product in the cart
                            decimal foodItemPrice = db.Food_Items.FirstOrDefault(item => item.IsActive && item.Food_Item_Id == o.Food_Item_Id).Price;
                            o.Price = foodItemPrice;
                            if (o.Quantity < 1)
                            {
                                orderItems.Remove(o);
                            }
                        }

                        Order newCart = new Order()
                        {
                            Customer_Id   = customerId,
                            Order_date    = DateTime.Now,
                            Employee      = null,
                            Order_Items   = orderItems,
                            Food_Store_Id = null,
                            Submit_Status = false,
                            Creation_Date = DateTime.Now,
                            isActive      = true
                        };
                        cart = newCart;
                        db.Orders.Add(newCart);
                    }
                    //else if cart exists for customer
                    else
                    {
                        foreach (Order_Item orderItem in orderItems)
                        {
                            //find latest price of given orderItem
                            Food_Item foodItemForPrice = db.Food_Items.FirstOrDefault(item => item.IsActive && item.Food_Item_Id == orderItem.Food_Item_Id);
                            if (foodItemForPrice == null)
                            {
                                continue;
                            }
                            decimal foodItemPrice = foodItemForPrice.Price;
                            //find if item already exist in cart
                            Order_Item existingOrderItem = db.Order_Items.FirstOrDefault(i => i.Order_Id == cart.Order_Id && i.Food_Item_Id == orderItem.Food_Item_Id);
                            //if item doesn't already exist in the cart add new item
                            if (existingOrderItem == null)
                            {
                                if (orderItem.Quantity > 0)
                                {
                                    db.Order_Items.Add(new Order_Item()
                                    {
                                        Order_Id = cart.Order_Id, Food_Item_Id = orderItem.Food_Item_Id, Quantity = orderItem.Quantity, Price = foodItemPrice
                                    });
                                }
                            }
                            //else if item exists in the cart update quantity and latest price
                            else
                            {
                                existingOrderItem.Quantity = orderItem.Quantity;
                                existingOrderItem.Price    = foodItemPrice;
                            }
                        }
                    }
                    db.SaveChanges();
                    //Updating Total_Quantity and Total_Price in the db
                    IQueryable <Order_Item> orderItemList = db.Order_Items.Where(item => item.Order_Id == cart.Order_Id);
                    foreach (Order_Item orderItem in orderItemList)
                    {
                        finalTotalQuantity += (int)orderItem.Quantity;
                        finalTotalPrice    += (int)orderItem.Price * (int)orderItem.Quantity;
                        if (orderItem.Quantity < 1)
                        {
                            db.Order_Items.Remove(orderItem);
                        }
                    }
                    cart.Total_Quantity = finalTotalQuantity;
                    cart.Total_Price    = finalTotalPrice;

                    db.SaveChanges();
                    isUpdated = true;
                }
                catch
                {
                    throw new FoodOrderException();
                }

                return(isUpdated);
            }
        }