示例#1
0
        public void LoadById()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    //Make sure that the ID is set and valid
                    if (this.Id >= 0)
                    {
                        tblOrderItem orderItem = dc.tblOrderItems.FirstOrDefault(oi => oi.Id == this.Id);

                        //Make sure that a orderItem was retrieved
                        if (orderItem != null)
                        {
                            //Set the properties on this orderItem
                            this.MovieId  = orderItem.MovieId;
                            this.OrderId  = orderItem.OrderId;
                            this.Quantity = orderItem.Quantity;
                        }
                        else
                        {
                            throw new Exception("No orderItem to load with this Id");
                        }
                    }
                    else
                    {
                        throw new Exception("OrderItem Id not Valid");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#2
0
        public static int Update(OrderItem orderItem)
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                try
                {
                    tblOrderItem updatedrow = dc.tblOrderItems.Where(dt => dt.Id == orderItem.Id).FirstOrDefault();

                    // Check to see if object exists
                    if (orderItem != null)
                    {
                        // Update the proper fields
                        updatedrow.OrderId  = orderItem.OrderId;
                        updatedrow.MovieId  = orderItem.MovieId;
                        updatedrow.Quantity = orderItem.Quantity;


                        // Save and commit changes
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        // throw an exception stating the row was not found
                        throw new Exception("Row was not found.");
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
示例#3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="shoppingCart"></param>
        /// <returns></returns>
        public bool CartCheckout(ShoppingCart shoppingCart)
        {
            if (shoppingCart.ItemsList != null && shoppingCart.ItemsList.Count > 0)
            {
                int orderstatus = (int)OrderStatus.Incomplete;

                tblOrder tblOrder = bringlyEntities.tblOrders
                                    .Where(x => x.FK_CreatedByGuid == UserVariables.LoggedInUserGuid && x.FK_OrderStatusId == orderstatus)
                                    .FirstOrDefault();

                foreach (Items item in shoppingCart.ItemsList)
                {
                    tblOrderItem tblItem = bringlyEntities.tblOrderItems
                                           .Where(x => x.FK_ItemGuid == item.ItemGuid && x.FK_OrderGuid == x.tblOrder.OrderGuid &&
                                                  x.FK_CreatedByGuid == UserVariables.LoggedInUserGuid &&
                                                  x.tblOrder.FK_OrderStatusId == orderstatus)
                                           .FirstOrDefault();

                    tblItem.Quantity = item.Quantity;
                    bringlyEntities.SaveChanges();
                }

                tblOrder.FK_OrderStatusId = (int)OrderStatus.Inprogress;
                //tblOrder.OrderSubTotal = shoppingCart.SubTotal;
                tblOrder.OrderTotal = shoppingCart.Total;
                bringlyEntities.SaveChanges();

                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
        public JsonResult DeleteTempOrder(int id)
        {
            int    branchid         = Convert.ToInt32(Session["branchid"]);
            string tokenno          = id.ToString();
            List <tblTempOrder> lst = _db.tblTempOrders.Where(k => k.TokenNo == tokenno && k.BranchId == branchid).ToList();

            foreach (tblTempOrder item in lst)
            {
                tblOrderItem or = new tblOrderItem();
                or.GarmentId  = item.GarmentId;
                or.Quantity   = item.Quantity;
                or.TakeAway   = item.TW.ToString();
                or.BranchId   = branchid;
                or.TotalPrice = item.Total;
                tblOrder tbor = _db.tblOrders.Where(t => t.TokenNo == tokenno).OrderByDescending(a => a.OrderId).Take(1).FirstOrDefault();
                or.OrderId = tbor.OrderId;
                _db.tblOrderItems.Add(or);
                _db.SaveChanges();


                tblTempOrder tb = _db.tblTempOrders.Where(t => t.TokenNo == item.TokenNo && t.BranchId == branchid).FirstOrDefault();
                _db.tblTempOrders.Remove(tb);
                _db.SaveChanges();
            }
            return(Json(1, JsonRequestBehavior.AllowGet));
        }
示例#5
0
        public static bool Insert(OrderItem orderItem)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    // Make a new row
                    tblOrderItem newrow = new tblOrderItem();

                    // Set the properties
                    // Ternary Operator condition ? true : false
                    newrow.Id       = dc.tblOrderItems.Any() ? dc.tblOrderItems.Max(p => p.Id) + 1 : 1; // If there are any rows, get the max id and add 1, if not use 1
                    newrow.OrderId  = orderItem.OrderId;
                    newrow.MovieId  = orderItem.MovieId;
                    newrow.Quantity = orderItem.Quantity;

                    // Do the Insert
                    dc.tblOrderItems.Add(newrow);

                    // Commit the insert
                    dc.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static int Insert(out int id, int orderId, int movieId, int quantity, double cost)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblOrderItem newrow = new tblOrderItem();

                    newrow.OrderId  = orderId;
                    newrow.MovieId  = movieId;
                    newrow.Quantity = quantity;
                    newrow.Cost     = cost;

                    //giving a new row the next id after existing one or if there is none id equals to 1
                    newrow.Id = dc.tblOrderItems.Any() ? dc.tblOrderItems.Max(dt => dt.Id) + 1 : 1;

                    id = newrow.Id;

                    dc.tblOrderItems.Add(newrow);

                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#7
0
        public static int Insert(OrderItem orderItem)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblOrderItem tblOrderItem = new tblOrderItem();

                    tblOrderItem.MovieID  = orderItem.MovieId;
                    tblOrderItem.OrderID  = orderItem.OrderId;
                    tblOrderItem.Quantity = orderItem.Quantity;
                    tblOrderItem.Cost     = orderItem.Cost;

                    //example of ternary operator
                    tblOrderItem.Id = dc.tblOrderItems.Any() ? dc.tblOrderItems.Max(dt => dt.Id) + 1 : 1;

                    //Change the ID of the inserted Student
                    orderItem.Id = tblOrderItem.Id;

                    dc.tblOrderItems.Add(tblOrderItem);
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public static OrderItem LoadById(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblOrderItem row = (from dt in dc.tblOrderItems
                                        where dt.Id == id
                                        select dt).FirstOrDefault();

                    if (row != null)
                    {
                        return new OrderItem {
                                   Id = row.Id, OrderId = row.OrderId, MovieId = row.MovieId, Cost = row.Cost, Quantity = row.Quantity
                        }
                    }
                    ;
                    else
                    {
                        throw new Exception("Row was not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#9
0
        public tblOrderItem AddOrderItem(tblOrderItem orderItem)
        {
            try
            {
                using (PizzaRestoranEntities context = new PizzaRestoranEntities())
                {
                    tblOrderItem newOrderItem = new tblOrderItem
                    {
                        OrderItemID     = orderItem.OrderItemID,
                        OrderName       = orderItem.OrderName,
                        ProductName     = orderItem.ProductName,
                        ProductPrice    = orderItem.ProductPrice,
                        ProductQuantity = orderItem.ProductQuantity
                    };

                    context.tblOrderItems.Add(newOrderItem);
                    context.SaveChanges();
                    orderItem.OrderItemID = newOrderItem.OrderItemID;
                    return(orderItem);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
                return(null);
            }
        }
示例#10
0
        public static int Update(OrderItem orderItem)
        {
            try
            {
                using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities())
                {
                    tblOrderItem updatedrow = dc.tblOrderItems.FirstOrDefault(a => a.Id == orderItem.Id);

                    if (updatedrow != null)
                    {
                        updatedrow.OrderId    = orderItem.OrderId;
                        updatedrow.MenuItemId = orderItem.MenuItemId;


                        return(dc.SaveChanges());
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#11
0
        public static int Delete(Guid id)
        {
            try
            {
                using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities())
                {
                    tblOrderItem deletedrow = dc.tblOrderItems.FirstOrDefault(a => a.Id == id);

                    if (deletedrow != null)
                    {
                        dc.tblOrderItems.Remove(deletedrow);

                        return(dc.SaveChanges());
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#12
0
        public static bool Insert(Guid orderId, Guid menuItemId)
        {
            try
            {
                using (FoodOrderSystemEntities dc = new FoodOrderSystemEntities())
                {
                    // Make a new row
                    tblOrderItem newrow = new tblOrderItem();

                    // Set the properties
                    newrow.Id         = Guid.NewGuid();
                    newrow.OrderId    = orderId;
                    newrow.MenuItemId = menuItemId;

                    // Do the Insert
                    dc.tblOrderItems.Add(newrow);

                    // Commit the insert
                    dc.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#13
0
        public static int Delete(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    //get the row i want to delete
                    tblOrderItem deleteRow = (from dt in dc.tblOrderItems
                                              where dt.Id == id
                                              select dt).FirstOrDefault();

                    if (deleteRow != null)
                    {
                        dc.tblOrderItems.Remove(deleteRow);
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#14
0
        public static int Update(OrderItem orderItem)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    //get the row i want to update
                    tblOrderItem updateRow = (from dt in dc.tblOrderItems
                                              where dt.Id == orderItem.Id
                                              select dt).FirstOrDefault();

                    if (updateRow != null)
                    {
                        updateRow.MovieID  = orderItem.MovieId;
                        updateRow.OrderID  = orderItem.OrderId;
                        updateRow.Quantity = orderItem.Quantity;
                        updateRow.Cost     = orderItem.Cost;

                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row not found");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#15
0
        public static int Delete(int id)
        {
            try
            {
                using (DVDCentralEntities dc = new DVDCentralEntities())
                {
                    tblOrderItem deleterow = dc.tblOrderItems.FirstOrDefault(dt => dt.Id == id);

                    if (deleterow != null)
                    {
                        // Remove the row
                        dc.tblOrderItems.Remove(deleterow);

                        // Commit/Save the changes
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Row was not found.");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#16
0
        public int Insert()
        {
            try
            {
                using (DVDEntities dc = new DVDEntities())
                {
                    tblOrderItem orderItem = new tblOrderItem
                    {
                        OrderId  = this.OrderId,
                        MovieId  = this.MovieId,
                        Quantity = this.Quantity,
                        Id       = dc.tblOrderItems.Any() ? dc.tblOrderItems.Max(oi => oi.Id) + 1 : 1
                    };
                    this.Id = orderItem.Id;
                    dc.tblOrderItems.Add(orderItem);

                    //Return the rows effected
                    return(dc.SaveChanges());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
示例#17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool addToCart(Items item)
        {
            Guid OrderGuid   = Guid.Empty;
            int  orderStatus = (int)OrderStatus.Incomplete;

            tblOrder tblOrder = bringlyEntities.tblOrders
                                .Where(x => x.FK_CreatedByGuid == UserVariables.LoggedInUserGuid && x.FK_OrderStatusId != orderStatus)
                                .FirstOrDefault();

            if (tblOrder != null && tblOrder.OrderGuid != Guid.Empty)
            {
                OrderGuid = tblOrder.OrderGuid;
                tblOrder.FK_OrderStatusId = (int)(OrderStatus.Incomplete);
            }
            else
            {
                tblOrder                  = new tblOrder();
                tblOrder.OrderGuid        = Guid.NewGuid();
                OrderGuid                 = tblOrder.OrderGuid;
                tblOrder.FK_CreatedByGuid = UserVariables.LoggedInUserGuid;
                tblOrder.FK_OrderStatusId = (int)OrderStatus.Incomplete;
                tblOrder.OrderDiscount    = 0;
                //tblOrder.OrderSubTotal = 0;
                tblOrder.OrderTotal = 0;
                tblOrder.IsDeleted  = false;
                bringlyEntities.tblOrders.Add(tblOrder);
            }

            bringlyEntities.SaveChanges();

            tblOrderItem OrderItem = bringlyEntities.tblOrderItems
                                     .Where(x => x.FK_ItemGuid == item.ItemGuid && x.FK_OrderGuid == OrderGuid &&
                                            x.FK_CreatedByGuid == UserVariables.LoggedInUserGuid)
                                     .FirstOrDefault();

            if (OrderItem != null && OrderItem.OrderItemGuid != Guid.Empty)
            {
                OrderItem.Quantity = item.Quantity + OrderItem.Quantity;
            }
            else
            {
                OrderItem = new tblOrderItem();
                OrderItem.OrderItemGuid    = Guid.NewGuid();
                OrderItem.FK_OrderGuid     = OrderGuid;
                OrderItem.FK_ItemGuid      = item.ItemGuid;
                OrderItem.Quantity         = item.Quantity;
                OrderItem.UnitPrice        = 0;
                OrderItem.FK_CreatedByGuid = UserVariables.LoggedInUserGuid;
                OrderItem.DateCreated      = DateTime.Now;
                bringlyEntities.tblOrderItems.Add(OrderItem);
            }

            bringlyEntities.SaveChanges();
            return(true);
        }
示例#18
0
        public void Delete()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblOrderItem orderItem = dc.tblOrderItems.FirstOrDefault(oi => oi.Id == -99);
                dc.tblOrderItems.Remove(orderItem);
                int rowsEffected = dc.SaveChanges();

                Assert.IsTrue(rowsEffected == 1);
            }
        }
示例#19
0
        public void Update()
        {
            using (DVDEntities dc = new DVDEntities())
            {
                tblOrderItem orderItem = dc.tblOrderItems.FirstOrDefault(oi => oi.Id == -99);
                orderItem.Quantity = -98;

                //Save changed property
                dc.SaveChanges();

                tblOrderItem updatedOrderItem = dc.tblOrderItems.FirstOrDefault(oi => oi.Quantity == -98);
                Assert.AreEqual(orderItem.Id, updatedOrderItem.Id);
            }
        }
示例#20
0
        public void DeleteTest()
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                tblOrderItem row = (from dt in dc.tblOrderItems
                                    where dt.Id == -99
                                    select dt).FirstOrDefault();

                dc.tblOrderItems.Remove(row);


                int results = dc.SaveChanges();

                Assert.AreNotEqual(0, results);
            }
        }
示例#21
0
 public void DeleteOrderItem(int orderID)
 {
     try
     {
         using (PizzaRestoranEntities context = new PizzaRestoranEntities())
         {
             tblOrderItem orderItemToDelete = (from r in context.tblOrderItems where r.OrderItemID == orderID select r).First();
             context.tblOrderItems.Remove(orderItemToDelete);
             context.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine("Exception: " + ex.Message.ToString());
     }
 }
示例#22
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());
     }
 }
示例#23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ItemGuid"></param>
        /// <returns></returns>
        public bool deleteItemFromCart(Guid ItemGuid)
        {
            int      orderstatus = (int)OrderStatus.Incomplete;
            tblOrder tblOrder    = bringlyEntities.tblOrders
                                   .Where(x => x.FK_CreatedByGuid == UserVariables.LoggedInUserGuid && x.FK_OrderStatusId == orderstatus)
                                   .FirstOrDefault();

            tblOrderItem OrderItem = bringlyEntities.tblOrderItems
                                     .Where(x => x.FK_ItemGuid == ItemGuid && x.FK_OrderGuid == tblOrder.OrderGuid && x.FK_CreatedByGuid == UserVariables.LoggedInUserGuid)
                                     .FirstOrDefault();

            bringlyEntities.tblOrderItems.Attach(OrderItem);
            bringlyEntities.tblOrderItems.Remove(OrderItem);
            bringlyEntities.SaveChanges();

            return(true);
        }
示例#24
0
        public void Insert()
        {
            tblOrderItem newrow = new tblOrderItem();

            // Set the column values
            newrow.Id       = -99;
            newrow.OrderId  = 123456789;
            newrow.MovieId  = 55555;
            newrow.Quantity = 10;

            // Insert of the row
            dc.tblOrderItems.Add(newrow);

            // Commit the changes, return the rows affected
            int rowsaffected = dc.SaveChanges();

            Assert.AreNotEqual(0, rowsaffected);
        }
 public static int Delete(int id)
 {
     try
     {
         using (DVDCentralEntities dc = new DVDCentralEntities())
         {
             tblOrderItem deleterow = (from dt in dc.tblOrderItems
                                       where dt.Id == id
                                       select dt).FirstOrDefault();
             dc.tblOrderItems.Remove(deleterow);
             return(dc.SaveChanges());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#26
0
        public void UpdateTest()
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                tblOrderItem row = (from dt in dc.tblOrderItems
                                    where dt.Id == -99
                                    select dt).FirstOrDefault();

                if (row != null)
                {
                    row.Cost = 9.99;
                }

                int results = dc.SaveChanges();

                Assert.AreNotEqual(0, results);
            }
        }
示例#27
0
        public void Delete()
        {
            tblOrderItem existingOrderItem = (from dt in dc.tblOrderItems
                                              where dt.Id == -99
                                              select dt).FirstOrDefault();

            if (existingOrderItem != null)
            {
                // Delete the row
                dc.tblOrderItems.Remove(existingOrderItem);
                dc.SaveChanges();
            }

            tblOrderItem deletedOrderItem = (from dt in dc.tblOrderItems
                                             where dt.Id == -99
                                             select dt).FirstOrDefault();

            Assert.IsNull(deletedOrderItem);
        }
        /// <summary>
        /// A method for entering the quantity of an item in a product
        /// </summary>
        private void SaveExecute()
        {
            try
            {
                if (addOrderItem.txtQuantity.Text.Length < 1)
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("Enter a number.", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
                if (addOrderItem.txtQuantity.Text.ToString() == "0" || addOrderItem.txtQuantity.Text.ToString() == "00")
                {
                    Xceed.Wpf.Toolkit.MessageBox.Show("Quantity must be greater than zero.", "Wrong input", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }

                Service    s           = new Service();
                string     productName = addOrderItem.txtName.Text;
                tblProduct menu        = s.GetProductID(Convert.ToString(productName));

                using (PizzaRestoranEntities context = new PizzaRestoranEntities())
                {
                    tblOrderItem tblOrderItem = new tblOrderItem();
                    OrderList = s.GetAllOrder();

                    tblOrderItem.ProductName     = menu.ProductID;
                    tblOrderItem.ProductPrice    = Convert.ToInt32(addOrderItem.txtPrice.Text);
                    tblOrderItem.ProductQuantity = Convert.ToInt32(addOrderItem.txtQuantity.Text);
                    tblOrderItem.OrderName       = OrderList.LastOrDefault().OrderID;
                    tblOrderItem.OrderSum        = Convert.ToInt32(addOrderItem.txtPrice.Text) * Convert.ToInt32(addOrderItem.txtQuantity.Text);

                    context.tblOrderItems.Add(tblOrderItem);
                    context.SaveChanges();
                }

                IsUpdateItem = true;

                addOrderItem.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
示例#29
0
        public void InsertTest()
        {
            using (DVDCentralEntities dc = new DVDCentralEntities())
            {
                tblOrderItem newrow = new tblOrderItem();

                newrow.Id       = -99;
                newrow.MovieID  = 1;
                newrow.OrderID  = 1;
                newrow.Quantity = 1;
                newrow.Cost     = 10;

                dc.tblOrderItems.Add(newrow);

                int results = dc.SaveChanges();

                Assert.IsTrue(results == 1);
            }
        }
示例#30
0
        public void Update()
        {
            tblOrderItem existingOrderItem = (from dt in dc.tblOrderItems
                                              where dt.Id == -99
                                              select dt).FirstOrDefault();

            if (existingOrderItem != null)
            {
                // Update the Information
                existingOrderItem.OrderId  = 234567890;
                existingOrderItem.MovieId  = 66666;
                existingOrderItem.Quantity = 11;
                dc.SaveChanges();
            }

            tblOrderItem updatedOrderItem = (from dt in dc.tblOrderItems
                                             where dt.Id == -99
                                             select dt).FirstOrDefault();

            Assert.AreEqual(existingOrderItem, updatedOrderItem);
        }