public DetailBillItemViewModel() : base()
 {
     productModel      = new ProductModel();
     unitModel         = new UnitModel();
     detailBillModel   = new DetailBillModel();
     RemoveItemCommand = new DelegateCommand <DetailBillItemViewModel>(RemoveItem);
 }
        private void SaveToDatabase()
        {
            // save bill
            BillModel.SaveToDatabase(newBill);

            // save detail bill
            foreach (DetailBillItemViewModel item in ListDetailBill)
            {
                DetailBillModel.SaveToDatabase(item.DetailBillModel);
            }
        }
        private void SelectedProductChange(ProductModel product)
        {
            if (SelectedIndex == -1)
            {
                return;
            }

            if (Mouse.LeftButton == MouseButtonState.Pressed)
            {
                //Check if product was chosen, then update quantity
                foreach (DetailBillItemViewModel item in ListDetailBill)
                {
                    if (item.ProductName.Equals(product.Name))
                    {
                        //update quantity
                        item.Quantity++;
                        NotifyDetaillBillProperty();
                        return;
                    }
                }

                //Otherwise, create the bill
                // model related
                UnitModel unit = UnitModel.GetModelFromID(product.UnitID);

                // Generate id for detaill bill
                DetailBillModel detail = new DetailBillModel(DetailBillModel.GenerateID(listDetailBill.ListDetail), newBill.ID, product.ID, unit.ID, 1, product.Price);
                listDetailBill.Add(new DetailBillItemViewModel(product, unit, detail));

                NotifyDetaillBillProperty();
            }

            if (Mouse.RightButton == MouseButtonState.Pressed)
            {
                //Check if product was chosen, then update quantity
                foreach (DetailBillItemViewModel item in ListDetailBill)
                {
                    if (item.ProductName.Equals(product.Name))
                    {
                        //update quantity
                        item.Quantity--;
                        if (item.Quantity == 0)
                        {
                            RemoveItem(item);
                        }
                        NotifyDetaillBillProperty();
                        return;
                    }
                }
            }
        }
        private void SaveToDatabase()
        {
            // save bill
            BillModel.SaveToDatabase(bill);

            // save detail bill
            foreach (DetailBillItemViewModel item in listDetailBill)
            {
                DetailBillModel.SaveToDatabase(item.DetailBillModel);
            }

            // if it a awaiting bill
            if (Index >= 0)
            {
                ListGeneralBillModel.GetInstance().List.Remove(ListGeneralBillModel.GetInstance().List[Index]);
                ListGeneralBillModel.GetInstance().NotifyListChange();
            }
        }
 public DetailBillItemViewModel(ProductModel product, UnitModel unit, DetailBillModel detail)
 {
     productModel    = product;
     unitModel       = unit;
     detailBillModel = detail;
 }