public ActionResult Index(Product product)
        {
            try
            {
                ProductTableData.updateProduct(product.ID, (int)product.Quantity_Available, (int)product.Unit_Price, (int)product.Selling_Price, product.Barcodes.ToArray(), product.Unique_Barcode, DateTime.Now);

                Supplier supplier = SupplierTableData.getSupplier(product.Model);//supplier name is saved in product model

                Product_Supplier product_Supplier = new Product_Supplier()
                {
                    Date = DateTime.Now, Quantity = product.Quantity_Available, Supplier = supplier, Ref_Number = product.Type, Product_ID = product.ID, Unit_Price = product.Unit_Price
                };

                Journal journal = new Journal();
                journal.Date            = product.Date_Updated;
                journal.Sub_Account_ID  = 10; ///purchase account
                journal.Type            = 0;  /// 0 means Debit
                journal.Status          = 1;  ///posted
                journal.PreparedBy      = 1;
                journal.AuthenticatedBy = 1;
                //Product_SupplierTableData.addNewProduct_Supplier()
                return(Json(new
                {
                    msg = "Successfully added " + product.ID + " " +
                          product.Quantity_Available + " " +
                          product.Selling_Price + " " +
                          product.Barcodes.First().Barcode_Serial
                }));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        private void OK_Button_Click(object sender, RoutedEventArgs e)
        {
            if (dataGrid.Items.Count == 0)
            {
                return;
            }
            int count = 0;

            try
            {
                foreach (Product obj in listProduct)
                {
                    ProductTableData.updateProduct(obj.ID, (int)obj.Quantity_Available, (int)obj.Unit_Price, (int)obj.Selling_Price, obj.Barcodes.ToArray(), obj.Unique_Barcode, DateTime.Now);

                    Product_SupplierTableData.addNewProduct_Supplier(listProduct_Supplier[count]); /// inserting new row in product supplier

                    count++;
                    dataGrid.Items.RemoveAt(0);
                    ///Console.WriteLine(dataGrid.Items.Count);
                }
                int amount = (int)listProduct.Sum(ee => ee.Unit_Price * ee.Quantity_Available);

                ///
                Journal journal = new Journal();
                journal.Date            = datetime;
                journal.Sub_Account_ID  = 10; ///purchase account
                journal.Type            = 0;  /// 0 means Debit
                journal.Status          = 1;  ///posted
                journal.PreparedBy      = BL.Login.ID;
                journal.AuthenticatedBy = BL.Login.ID;

                if (paymentDueDouble != 0) ///adding due payment in journal details
                {
                    //listJournal_Detail.Add(new Journal_Detail(5, (decimal)paymentDueDouble, "")); /// 5 is Accounts Payable
                    listJournal_Detail.Add(new Journal_Detail()
                    {
                        Sub_Account_ID = 5, Amount = (decimal)paymentDueDouble
                    });                                                                                                     /// 5 is Accounts Payable
                }

                JurnalTable_Data.PostPurchaseJournal(journal, listProduct_Supplier, listJournal_Detail, amount, paymentDueDouble); ///posting journal for purchase

                DB.DBSubmitChanges();                                                                                              ///Confirming all the changes in Database
                listProduct.Clear();
                referenceNo.Text          = "";
                supplier.Text             = "";
                supplier.IsEnabled        = true;
                paymentCheckBox.IsChecked = false;

                totalPaymentDouble    = 0;
                totalPayment.Content  = 0;
                totalQuantityInt      = 0;
                totalQuantity.Content = 0;
                grandTotalDouble      = 0;
                grandTotal.Content    = 0;
                paymentDue.Content    = 0;
                paymentDueDouble      = 0;

                paymentDatagrid.Items.Clear();
                listProduct_Supplier.Clear();
                product = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }