protected override void UpdateProductsQuantities(List <TransactionProduct> products, bool isRollBack)
 {
     foreach (var prodTrans in products)
     {
         var product = ProductDbService.FindById(prodTrans.ProductId);
         if (isRollBack)
         {
             product.Quantity += prodTrans.ProductQuantity;
         }
         else
         {
             product.Quantity -= prodTrans.ProductQuantity;
         }
         ProductDbService.UpdateProduct(product);
     }
 }
Beispiel #2
0
        public void EditProductRequest()
        {
            Product product;

            if (!Roles.IsStandard(Presenter.GetStateManager().UserSession.SessionEntity.Roles))
            {
                Presenter.GetStateManager()
                .Push(new ErrorPresenter(Presenter.GetStateManager(), Messages.NotAuthorizedMsg));
                return;
            }

            try
            {
                product = ProductDbService.FindById(ViewService.GetSelectedProductId());
            }
            catch (ArgumentException e)
            {
                Presenter.GetStateManager().Push(new ErrorPresenter(Presenter.GetStateManager(), e.Message));
                return;
            }

            Presenter.GetStateManager().Push(new EditProductPresenter(Presenter.GetStateManager(), product, this));
        }
        protected List <TransactionProduct> GetProductsFromDataGrid(TransactionType transactionType)
        {
            var products = new List <TransactionProduct>();

            for (var i = 0; i < OperationsViewService.GetRowsCount(); i++)
            {
                //var row = this.OperationsViewService.DataGrid.Rows[i];
                var     transactionNumber       = OperationsViewService.GetDataAtRow(i, TransactionNumber);
                var     productId               = -1;
                var     selectedProductQuantity = 0D;
                Product product;
                try
                {
                    var prodIdCell = OperationsViewService.GetDataAtRow(i, ProductId);
                    if (prodIdCell == null)
                    {
                        continue;
                    }
                    productId = (int)prodIdCell;
                    product   = ProductDbService.FindById(productId);
                    if (product == null)
                    {
                        throw new Exception();
                    }
                    selectedProductQuantity = double.Parse(OperationsViewService.GetDataAtRow(i, ProductQuantity) + "");
                }
                catch (Exception)
                {
                    throw new ArgumentException($"{ThereWasAnErrorOnRow} {transactionNumber}");
                }

                if (selectedProductQuantity <= 0D)
                {
                    throw new ArgumentException($"{ChooseValidQuantity} {transactionNumber}");
                }

                if (transactionType == TransactionType.SALE)
                {
                    if (product.Quantity < selectedProductQuantity)
                    {
                        throw new ArgumentException($"{InsufficientAmount} {transactionNumber}");
                    }
                }

                var subTotal = 0.0;
                switch (transactionType)
                {
                case TransactionType.SALE:
                    subTotal = product.SellPrice * selectedProductQuantity;
                    break;

                case TransactionType.DELIVERY:
                    subTotal = product.ImportPrice * selectedProductQuantity;
                    break;
                }

                var productTransaction = new TransactionProduct
                {
                    ProductId       = product.Id,
                    ProductQuantity = selectedProductQuantity,
                    SubTotalPrice   = subTotal
                };
                products.Add(productTransaction);
            }

            return(products);
        }