コード例 #1
0
        private async void UpdateSale()
        {
            var sale             = _saleManager.GetByID(SaleID);
            var updateSaleResult = await _saleManager.UpdateSale(new Sale()
            {
                AmountPaid     = Convert.ToDouble(textBox1.Text),
                Change         = Convert.ToDouble(Convert.ToDecimal(textBox1.Text) - Total),
                DateCreated    = sale.DateCreated,
                DateTime       = sale.DateTime,
                IsDeleted      = false,
                StoreID        = sale.StoreID,
                Total          = Convert.ToDecimal(Total),
                UserCreatedID  = sale.UserCreatedID,
                UserID         = sale.UserID,
                DateModified   = DateTime.Now,
                SaleID         = sale.SaleID,
                UserModifiedID = Global.User.UserID
            });

            if (updateSaleResult.IsSuccess)
            {
                SaleProducts = SaleProducts.Select(m =>
                {
                    m.SaleID = sale.SaleID;
                    return(m);
                }).ToList();

                //update saleproducts
                //bawasan quantity ng dapat bawasan
                //dagdagan ang dapat dagdagan
                updateSaleResult = await _saleManager.UpdateSaleProduct(SaleProducts, SaleID);
            }

            if (updateSaleResult.IsSuccess)
            {
                //bawasan quantity sa store
                await _storeManager.DecreaseProductLeft(Global.Store.StoreID, SaleProducts);

                Close();
                TransactionDone = true;
            }
            else
            {
                //delete sale by id
                //delete saleproduct by saleid
                await _saleManager.DeleteSale(SaleID);

                await _saleManager.DeleteSaleProductBySaleID(SaleID);

                MessageBox.Show("An error occured", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }