Esempio n. 1
0
        /// <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());
            }
        }
Esempio n. 2
0
        /// <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>
        /// 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());
            }
        }
Esempio n. 4
0
 /// <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());
     }
 }
Esempio n. 5
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());
     }
 }
Esempio n. 6
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());
     }
 }
Esempio n. 7
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());
     }
 }
Esempio n. 8
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());
     }
 }
Esempio n. 9
0
 /// <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());
     }
 }
Esempio n. 10
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());
     }
 }
Esempio n. 11
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());
     }
 }
Esempio n. 12
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);
     }
 }