public IActionResult Insert(ProductCategory product) { var myString = _config.GetSection("MyConnection").GetSection("ConnString").Value; DBOperations dbObj = new DBOperations(); int res = dbObj.AddProduct(product, myString); List <ProductCategory> products = dbObj.getAllProducts(myString); model.ProductList = products; //return View(model); return(RedirectToAction("Index", "Home")); }
public IActionResult AddProduct(Product product) { var dBOperations = new DBOperations(); var rowsAffected = dBOperations.AddProduct(product); if (rowsAffected > 0) { return(RedirectToAction("Index", "Product")); } return(Content("Internal Server Error")); }
// Добавяне на продукт в базата private void addProductButton_Click(object sender, EventArgs e) { decimal price = -1; int quantity = -1; string name = productNameTextBox.Text; if (dbo.CheckIfProductExists(name)) { MessageBox.Show("Продукт с това име вече съществува!"); return; } // Проверка за коректни данни за цена try { price = decimal.Parse(productPriceTextBox.Text); } catch (Exception) { MessageBox.Show("Невалидни данни за цена на продукт!"); return; } // Проверка за коректни данни за количество try { quantity = int.Parse(productQuantityTextBox.Text); } catch (Exception) { MessageBox.Show("Невалидни данни за количество на продукт!"); return; } dbo.AddProduct(name, price, quantity); this.productsBindingSource.Add(this.dbo.GetProductByName(name)); }
public IActionResult AddProduct(Product product) { dBOperations.AddProduct(product); return(RedirectToAction("Index")); }