/// <summary>
        /// method for creating the order
        /// </summary>
        private void OrderExecute()
        {
            try
            {
                using (PizzeriaEntities context = new PizzeriaEntities())
                {
                    tblOrder newOrder = new tblOrder();

                    newOrder.SmallPizza  = order.SmallPizza;
                    newOrder.MediumPizza = order.MediumPizza;
                    newOrder.BigPizza    = order.BigPizza;
                    newOrder.JumboPizza  = order.JumboPizza;
                    newOrder.OrderDate   = DateTime.Now;
                    newOrder.OrderStatus = "Waiting";
                    Status = "Waiting";
                    newOrder.CustomerJMBG = order.CustomerJMBG;

                    context.tblOrders.Add(newOrder);
                    context.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception" + ex.Message.ToString());
            }
        }
 /// <summary>
 /// changes order status
 /// </summary>
 /// <param name="order"></param>
 public void ApproveOrder(tblOrder order)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrder orderToEdit = (from p in context.tblOrders where p.OrderID == order.OrderID select p).First();
             if (order.StatusID == 2)
             {
                 orderToEdit.StatusID = 3;
                 MessageBox.Show("Order declined.");
             }
             else
             {
                 orderToEdit.StatusID = 2;
                 MessageBox.Show("Order approved.");
             }
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write("Exception" + ex.Message.ToString());
     }
 }
        /// <summary>
        /// Adds new order to the DataBase.
        /// </summary>
        /// <param name="price"></param>
        /// <returns></returns>
        public tblOrder AddOrder(int price)
        {
            tblOrder order = new tblOrder();

            try
            {
                using (PizzeriaEntities context = new PizzeriaEntities())
                {
                    order.JMBG        = GetJmbg();
                    order.DateAndTime = DateTime.ParseExact(DateTime.Now.ToString("yyyy-MM-dd-hh-mm"), "yyyy-MM-dd-hh-mm", System.Globalization.CultureInfo.InvariantCulture);
                    order.StatusID    = 1;
                    order.Price       = price;
                    context.tblOrders.Add(order);
                    context.SaveChanges();
                    int id = order.OrderID;
                    order.OrderID = id;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write("Exception" + ex.Message.ToString());
                return(null);
            }
            return(order);
        }
        /// <summary>
        /// Deletes an order from database.
        /// </summary>
        /// <param name="order"></param>
        internal void DeleteOrder(tblOrder order)
        {
            try
            {
                using (PizzeriaEntities context = new PizzeriaEntities())
                {
                    if (order.StatusID == 1)
                    {
                        MessageBox.Show("Orders with waiting status can not be deleted.");
                    }
                    else
                    {
                        tblOrder orderToDelete = (from o in context.tblOrders where o.OrderID == order.OrderID select o).First();
                        context.tblOrders.Remove(orderToDelete);

                        List <tblRecord> record = (from r in context.tblRecords where r.OrderID == order.OrderID select r).ToList();
                        for (int i = 0; i < record.Count; i++)
                        {
                            context.tblRecords.Remove(record[i]);
                        }
                        context.SaveChanges();
                        MessageBox.Show("Order deleted.");
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write("Exception" + ex.Message.ToString());
            }
        }
        /// <summary>
        /// Gets all records with the ID of the selected order, which is kept in the txt file.
        /// Adds them to the list.
        /// </summary>
        /// <returns></returns>
        public List <vwOrder> GetRecords()
        {
            string id = "";

            using (StreamReader sr = new StreamReader("../../Order.txt"))
            {
                string line;
                while ((line = sr.ReadLine()) != null)
                {
                    id = line;
                }
            }
            try
            {
                using (PizzeriaEntities context = new PizzeriaEntities())
                {
                    int            i    = Convert.ToInt32(id);
                    List <vwOrder> list = new List <vwOrder>();
                    list = (from x in context.vwOrders where x.OrderID == i select x).ToList();
                    return(list);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write("Exception" + ex.Message.ToString());
                return(null);
            }
        }
Beispiel #6
0
 /// <summary>
 /// Method create list of guest ordered items.
 /// </summary>
 /// <param name="username">Username of guest.</param>
 /// <returns>List of ordered item.</returns>
 public List <vwOrderItem> GetAllOrderedItems(string username)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             return(context.vwOrderItems.Where(x => x.JMBG == username).ToList());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Beispiel #7
0
 /// <summary>
 /// Method retreiving order based on forwarded Jmbg/username
 /// </summary>
 /// <param name="username">Username of guest</param>
 /// <returns>Order</returns>
 public vwOrder ViewOrder(string username)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             return(context.vwOrders.Where(x => x.JMBG == username).FirstOrDefault());
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Beispiel #8
0
 /// <summary>
 /// Change order status to denied and saves changes to database.
 /// </summary>
 /// <param name="order"></param>
 public void DenyOrder(vwOrder order)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrder orderToReject = context.tblOrders.Where(x => x.OrderId == order.OrderId).FirstOrDefault();
             orderToReject.OrderStatus = "denied";
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
Beispiel #9
0
 /// <summary>
 /// Method for deleting ordered item and saves changes to database.
 /// </summary>
 /// <param name="id">ID of order</param>
 public void RemoveItem(int id)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrderItem itemToDelete = context.tblOrderItems.Where(x => x.ID == id).FirstOrDefault();
             context.tblOrderItems.Remove(itemToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
 /// <summary>
 /// Checks if user has any waiting orders.
 /// </summary>
 /// <param name="userName"></param>
 /// <returns></returns>
 public bool IsWaiting(string userName)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrder order = new tblOrder();
             order = (from x in context.tblOrders where x.JMBG == userName && x.StatusID == 1 select x).First();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Beispiel #11
0
 /// <summary>
 /// Method for confirming the making of order afterwhich date and time of order is set to now
 /// </summary>
 /// <param name="order">Order.</param>
 public void ConfirmOrder(vwOrder order)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrder orderToEdit = context.tblOrders.Where(x => x.OrderId == order.OrderId).FirstOrDefault();
             orderToEdit.OrderDateTime = DateTime.Now;
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
 /// <summary>
 /// Adds all the meals from the database to a list.
 /// </summary>
 /// <returns></returns>
 public List <tblMenu> GetAllMeals()
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             List <tblMenu> list = new List <tblMenu>();
             list = (from x in context.tblMenus select x).ToList();
             return(list);
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write("Exception" + ex.Message.ToString());
         return(null);
     }
 }
Beispiel #13
0
 /// <summary>
 /// This method creates a list of all orders.
 /// </summary>
 /// <returns>List of all orders.</returns>
 public List <vwOrder> GetAllOrders()
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             List <vwOrder> orders = new List <vwOrder>();
             orders = (from x in context.vwOrders select x).ToList();
             return(orders);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(null);
     }
 }
 /// <summary>
 /// Adds new record to the DataBase.
 /// </summary>
 /// <param name="recordList"></param>
 /// <param name="orderID"></param>
 public void AddRecord(List <tblRecord> recordList, int orderID)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             foreach (var item in recordList)
             {
                 item.OrderID = orderID;
                 context.tblRecords.Add(item);
                 context.SaveChanges();
             }
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.Write("Exception" + ex.Message.ToString());
     }
 }
Beispiel #15
0
 /// <summary>
 /// Method for adding ordered item to OrderItem table and saves changes into database.
 /// </summary>
 /// <param name="menuItem">Item from menu.</param>
 /// <param name="order">Which order to add item.</param>
 /// <param name="quantity">Quatity of item.</param>
 public void AddOrderItem(vwMenu menuItem, vwOrder order, int quantity)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrderItem itemToAdd = new tblOrderItem
             {
                 ItemId   = menuItem.ItemId,
                 Quantity = quantity,
                 OrderID  = order.OrderId
             };
             context.tblOrderItems.Add(itemToAdd);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
Beispiel #16
0
 /// <summary>
 /// Method is canceling the order and deletes order and every item in that order from DB.
 /// </summary>
 /// <param name="orderID">ID of order.</param>
 public void CancelOrder(int orderID)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrder            order  = context.tblOrders.Where(x => x.OrderId == orderID).FirstOrDefault();
             List <tblOrderItem> orders = context.tblOrderItems.Where(x => x.OrderID == orderID).ToList();
             foreach (var item in orders)
             {
                 context.tblOrderItems.Remove(item);
                 context.SaveChanges();
             }
             context.tblOrders.Remove(order);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
Beispiel #17
0
 /// <summary>
 /// This method adds new order to DbSet and then saves changes to database.
 /// </summary>
 /// <param name="username"></param>
 public void AddOrder(string username)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrder order = new tblOrder
             {
                 OrderDateTime = DateTime.Now,
                 TotalPrice    = 0,
                 JMBG          = username,
                 OrderStatus   = "pennding"
             };
             context.tblOrders.Add(order);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
     }
 }
Beispiel #18
0
 /// <summary>
 /// This method checks if user already ordered.
 /// </summary>
 /// <param name="username">Username of guest.</param>
 /// <returns>True if ordered, false if not.</returns>
 public bool CheckIfUserOrdered(string username)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             List <vwOrder> orders = context.vwOrders.Where(x => x.JMBG == username).ToList();
             if (orders.Count() > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(false);
     }
 }
Beispiel #19
0
 /// <summary>
 /// Method for calculating total price of order.
 /// </summary>
 /// <param name="orderID">ID of order.</param>
 /// <returns>Total price of order.</returns>
 public int CalculateTotalPrice(int orderID)
 {
     try
     {
         using (PizzeriaEntities context = new PizzeriaEntities())
         {
             tblOrder           order  = context.tblOrders.Where(x => x.OrderId == orderID).FirstOrDefault();
             List <vwOrderItem> orders = context.vwOrderItems.Where(x => x.OrderID == orderID).ToList();
             int total = 0;
             foreach (var item in orders)
             {
                 total += item.Price * item.Quantity;
             }
             order.TotalPrice = total;
             context.SaveChanges();
             return(total);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine("Exception" + ex.Message.ToString());
         return(0);
     }
 }