private void deleteCategory_Click(object sender, EventArgs e) { var result = PromptMessage.ConfirmationMessage("Are you sure you want to delete this record?"); if (result) { var categoryName = categoryComboBox.Text; if (categoryName == "") { MessageForm.ShowError("You haven't selected category name"); return; } using (var context = new CandyStoreDbContext()) { try { var categoryToDelete = context.Categories.FirstOrDefault(p => p.Name == categoryName); context.Categories.Remove(categoryToDelete); context.SaveChanges(); } catch (Exception ex) { MessageForm.ShowError(ex.Message); } } MessageForm.ShowSuccess("Category deleted"); FillProductsAndCategoriesComboBoxes(); } }
private void minusButton_Click(object sender, EventArgs e) { var rowsSelected = productsGridView.SelectedRows; if (rowsSelected.Count > 1 || rowsSelected.Count < 1) { MessageForm.ShowWarning("Only 1 row can be edited!"); return; } var productName = GetSelectedRowProductName(); var product = Session.Products.FirstOrDefault(x => x.Key.Name == productName).Key; Session.Products[product] -= 1; _totalPrice -= product.Price; if (Session.Products[product] < 0) { Session.Products[product] = 0; _totalPrice += product.Price; var result = PromptMessage.ConfirmationMessage("Are you sure you want to remove the selected product?"); if (result) { Session.Products.Remove(product); } } else { var resultFromDb = CheckProductInDatabase(product.ProductID, "minus"); } LoadDatagridView(); }
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 addToCartBtn_Click(object sender, EventArgs e) { var productQuantity = productQuantityBox.Text; int quantityToNumber; bool result = int.TryParse(productQuantity, out quantityToNumber); if (result) { if (quantityToNumber <= 0) { MessageForm.ShowError("Quantity must be a positive number."); return; } var confirmationResult = PromptMessage.ConfirmationMessage("Are you sure you want to add these records to the shopping cart?"); if (!confirmationResult) { return; } using (var context = new CandyStoreDbContext()) { var productId = int.Parse(productsList.SelectedValue.ToString()); var product = context.Products.FirstOrDefault(p => p.ProductID == productId); if (product.Count < quantityToNumber) { MessageForm.ShowError("Not enough quantity on stock"); return; } else { product.Count -= quantityToNumber; if (Session.Products.ContainsKey(product)) { Session.Products[product] += quantityToNumber; } else { Session.Products.Add(product, quantityToNumber); } } context.SaveChanges(); productQuantityBox.Clear(); onStock.Text = product.Count.ToString(); } } else { MessageForm.ShowError("Quantity must be a whole positive number"); return; } }
private async void closeOrderButton_Click(object sender, EventArgs e) { var selectedOrder = ordersGridView.SelectedRows[0].DataBoundItem as OrderDto; if (selectedOrder == null) { MessageForm.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); MessageForm.ShowSuccess("Order close successfully."); InitializeOrdersGridView(); }
public bool GetConfirmationResult() { return(PromptMessage.ConfirmationMessage("Are you sure you want to delete this record?")); }
public bool ConfirmShoppingCartProductRemoval() { return(PromptMessage.ConfirmationMessage("Are you sure you want to remove the selected product?")); }
public bool GetProductAddToCartConfirmationResult() { return(PromptMessage.ConfirmationMessage("Are you sure you want to add these records to the shopping cart?")); }