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(); }
private void deleteCategory_Click(object sender, EventArgs e) { var result = Presenter.DeleteCategory(categoryComboBox.Text); if (!result.Valid) { NotifyMessageBox.ShowError(result.GetAllErrorMessages()); return; } NotifyMessageBox.ShowSuccess("Category deleted"); FillProductsAndCategoriesComboBoxes(); }
private void saveProductQuantityBtn_Click(object sender, EventArgs e) { var result = Presenter.SaveProductQuantity(productInsertStock.Text, productQuantityToAdd.Text); if (!result.Valid) { NotifyMessageBox.ShowError(result.GetAllErrorMessages()); return; } NotifyMessageBox.ShowSuccess("Record successfully added"); productInsertStock.Text = string.Empty; productQuantityToAdd.Text = string.Empty; FillProductsAndCategoriesComboBoxes(); }
private void saveCategoryButton_Click(object sender, EventArgs e) { var result = Presenter.AddNewCategory(categoryNameBox.Text, _categoryImage); if (!result.Valid) { NotifyMessageBox.ShowError(result.GetAllErrorMessages()); return; } NotifyMessageBox.ShowSuccess("Record successfully added"); categoryNameBox.Text = string.Empty; _categoryImage = null; categoryImageSelectedLabel.Text = "No image selected..."; FillProductsAndCategoriesComboBoxes(); }
private void productSave_Click(object sender, EventArgs e) { var result = Presenter.AddNewProduct(productPriceBox.Text, productNameBox.Text, productCategoryComboBox.Text, _productImage); if (!result.Valid) { NotifyMessageBox.ShowError(result.GetAllErrorMessages()); return; } NotifyMessageBox.ShowSuccess("Record successfully added"); productNameBox.Text = string.Empty; productPriceBox.Text = string.Empty; productCategoryComboBox.Text = string.Empty; _productImage = null; imageSelectedLabelProduct.Text = "No image selected..."; FillProductsAndCategoriesComboBoxes(); }
private async void closeOrderButton_Click(object sender, EventArgs e) { var selectedOrder = ordersGridView.SelectedRows[0].DataBoundItem as OrderDto; if (selectedOrder == null) { NotifyMessageBox.ShowError("No orders selected."); return; } var result = PromptMessage.ConfirmationMessage("Are you sure you want to close this order"); if (!result) { return; } await _orderService.CloseOrderAsync(selectedOrder.OrderId); NotifyMessageBox.ShowSuccess("Order close successfully."); InitializeOrdersGridView(); }