Exemplo n.º 1
0
        private async void submitOrderBtn_Click(object sender, EventArgs e)
        {
            var selectedProductBoxesAndQuantitiesHash = _productsQuantityHash
                                                        .Where(x => x.Key.SelectedValue != null)
                                                        .ToDictionary(x => x.Key, x => x.Value);

            if (!selectedProductBoxesAndQuantitiesHash.Any())
            {
                NotifyMessageBox.ShowWarning("No products selected.");
                return;
            }

            var selectedSupplierDto = suppliersComboBox.SelectedValue as SupplierDto;

            var products = new Dictionary <int, ProductDto>();

            foreach (var item in selectedProductBoxesAndQuantitiesHash)
            {
                int quantity;
                var parsed = int.TryParse(item.Value.Text, out quantity);
                if (!parsed || quantity < 1)
                {
                    NotifyMessageBox.ShowError("Quantity must be a whole positive number.");
                    return;
                }

                var currentProduct = item.Key.SelectedValue as ProductDto;
                if (!products.ContainsKey(currentProduct.Id))
                {
                    currentProduct.Quantity = quantity;
                    products.Add(currentProduct.Id, currentProduct);
                }
                else
                {
                    products[currentProduct.Id].Quantity += quantity;
                }
            }

            var totalPrice   = products.Sum(x => x.Value.Price * x.Value.Quantity);
            var confirmation = PromptMessage.ConfirmationMessage($"Are you sure you want to order? Your total price is: ${totalPrice}");

            if (!confirmation)
            {
                return;
            }

            await Presenter.PlaceOrder(
                Mapper.Map <CustomerModel>(Constants.Customer),
                selectedSupplierDto.Name,
                Mapper.Map <ProductModel[]>(products.Values.ToArray()));

            NotifyMessageBox.ShowSuccess("Order request sent.");
            ClearProductsQuantityAndPrice();
        }
Exemplo n.º 2
0
        private void minusButton_Click(object sender, EventArgs e)
        {
            var rowsSelected = productsGridView.SelectedRows;

            if (rowsSelected.Count != 1)
            {
                NotifyMessageBox.ShowWarning("Only 1 row can be edited!");
                return;
            }

            var result = Presenter.PerformProdcutQuantityChange(GetSelectedRowProductId(), Constants.MINUS_OPERATION);

            if (!result.Valid)
            {
                NotifyMessageBox.ShowWarning(result.GetAllErrorMessages());
                return;
            }

            var product = result.Object as Product;

            LoadDatagridView();
        }