// Check if item exists in cart private bool CartItemExists(ProductDetail product, WinkelwagenItem item) { if (item.product.Find(p => p.product.ProductId == product.product.ProductId) != null) return true; else return false; }
// Update 1 productdetail public void UpdateProductDetail(ProductDetail productDetail) { try { conn.Open(); string updateQuery = @"UPDATE productdetail SET verkoopprijs = @verkoopprijs, inkoopprijs = @inkoopprijs, maatId = @maatId, voorraad = @voorraad WHERE detailId = @detailId;"; MySqlCommand cmd = new MySqlCommand(updateQuery, conn); MySqlParameter verkoopprijsParam = new MySqlParameter("@verkoopprijs", MySqlDbType.Double); MySqlParameter inkoopprijsParam = new MySqlParameter("@inkoopprijs", MySqlDbType.Double); MySqlParameter maatParam = new MySqlParameter("@maatId", MySqlDbType.Int32); MySqlParameter voorraadParam = new MySqlParameter("@voorraad", MySqlDbType.Int32); MySqlParameter detailIdParam = new MySqlParameter("@detailId", MySqlDbType.Int32); verkoopprijsParam.Value = productDetail.verkoopprijs; inkoopprijsParam.Value = productDetail.inkoopprijs; maatParam.Value = productDetail.maatId; voorraadParam.Value = productDetail.voorraad; detailIdParam.Value = productDetail.detailId; cmd.Parameters.Add(verkoopprijsParam); cmd.Parameters.Add(inkoopprijsParam); cmd.Parameters.Add(maatParam); cmd.Parameters.Add(voorraadParam); cmd.Parameters.Add(detailIdParam); cmd.Prepare(); cmd.ExecuteNonQuery(); } catch (Exception e) { Console.Write("ProductDetail update mislukt " + e); throw e; } finally { conn.Close(); } }
// Insert 1 productDetail public void InsertProductDetail(ProductDetail productDetail) { try { conn.Open(); string insertString = @"insert into productdetail (verkoopprijs, inkoopprijs, maatId, voorraad, productId) " + "values (@verkoopprijs, @inkoopprijs, @maatId, @voorraad, @productId)"; MySqlCommand cmd = new MySqlCommand(insertString, conn); MySqlParameter verkoopprijsParam = new MySqlParameter("@verkoopprijs", MySqlDbType.Double); MySqlParameter inkoopprijsParam = new MySqlParameter("@inkoopprijs", MySqlDbType.Double); MySqlParameter maatParam = new MySqlParameter("@maatId", MySqlDbType.Int32); MySqlParameter voorraadParam = new MySqlParameter("@voorraad", MySqlDbType.Int32); MySqlParameter productIdParam = new MySqlParameter("@productId", MySqlDbType.Int32); verkoopprijsParam.Value = productDetail.verkoopprijs; inkoopprijsParam.Value = productDetail.inkoopprijs; maatParam.Value = productDetail.maatId; voorraadParam.Value = productDetail.voorraad; productIdParam.Value = productDetail.productId; cmd.Parameters.Add(verkoopprijsParam); cmd.Parameters.Add(inkoopprijsParam); cmd.Parameters.Add(maatParam); cmd.Parameters.Add(voorraadParam); cmd.Parameters.Add(productIdParam); cmd.Prepare(); cmd.ExecuteNonQuery(); } catch (Exception e) { Console.Write("ProductDetail niet toegevoegd: " + e); throw e; } finally { conn.Close(); } }
// Update 1 product met details public ProductDetail UpdateProductAndDetail(ProductDetail productDetail) { try { conn.Open(); string selectQuery = @"Update verkoopprijs, inkoopprijs, maatId, voorraad, naam, omschrijving, FROM productdetail LEFT JOIN product on productdetail.productId = product.productId;"; MySqlCommand cmd = new MySqlCommand(selectQuery, conn); MySqlDataReader dataReader = cmd.ExecuteReader(); if (dataReader != null) { return getFullProductFromDataReader(dataReader); } else { return null; } } catch (Exception e) { Console.Write("Ophalen van producten mislukt " + e); throw e; } finally { conn.Close(); } }
// Get 1 productdetail public ProductDetail GetProductDetail(int id) { ProductDetail productDetail = new ProductDetail(); try { conn.Open(); string selectQuery = "SELECT detailId, verkoopprijs, inkoopprijs, maatId, voorraad, naam, omschrijving, categorieId, pd.productId FROM productdetail pd LEFT JOIN product p on pd.productId = p.productId where pd.detailId = @detailId;"; MySqlCommand cmd = new MySqlCommand(selectQuery, conn); MySqlParameter detailIdParam = new MySqlParameter("@detailId", MySqlDbType.Int32); detailIdParam.Value = id; cmd.Parameters.Add(detailIdParam); MySqlDataReader dataReader = cmd.ExecuteReader(); if (dataReader != null) while (dataReader.Read()) productDetail = getFullProductFromDataReader(dataReader); } catch (Exception e) { Console.Write("Ophalen van producten mislukt " + e); throw e; } finally { conn.Close(); } return productDetail; }
public ActionResult WijzigProductDetail(WijzigProductDetailViewModel viewModel) { if (ModelState.IsValid) { try { ProductDetail productDetail = new ProductDetail(); productDetail.product = new ProductBase(); productDetail.detailId = viewModel.productDetail.detailId; productDetail.inkoopprijs = viewModel.productDetail.inkoopprijs; productDetail.verkoopprijs = viewModel.productDetail.inkoopprijs; productDetail.maatId = viewModel.SelectedMaat; productDetail.voorraad = viewModel.productDetail.voorraad; productDBController.UpdateProductDetail(productDetail); TempData[Enum.ViewMessage.WIJZIGING.ToString()] = "Detail: " + productDBController.GetProductByDetail(productDetail.detailId).Naam; return RedirectToAction("Beheer", "Account"); } catch (Exception e) { ViewBag.FoutMelding("Er is iets fout gegaan: " + e); return View(); } } else { viewModel.listMaat = selectListProductMaat(); return View(viewModel); } }
public ActionResult ToevoegenProductDetail(ProductDetail productDetail) { if (ModelState.IsValid) { try { productDBController.InsertProductDetail(productDetail); return RedirectToAction("Beheer", "Account"); } catch (Exception e) { ViewBag.FoutMelding("Er is iets fout gegaan: " + e); return View(); } } else { ViewBag.ProductId = productDetail.productId; return View(); } }
public ActionResult WijzigProduct(ProductDetail productDetailModel) { if (ModelState.IsValid) { try { productDBController.UpdateProductAndDetail(productDetailModel); TempData[Enum.ViewMessage.WIJZIGING.ToString()] = "Product: " + productDetailModel.product.Naam; return RedirectToAction("Beheer", "Account"); } catch (Exception e) { ViewBag.FoutMelding("Er is iets fout gegaan: " + e); return View(); } } else { return View(productDetailModel); } }
protected ProductDetail getProductDetailFromDataReader(MySqlDataReader datareader) { ProductDetail productDetail = new ProductDetail { detailId = datareader.GetInt32("detailID"), verkoopprijs = datareader.GetDouble("verkoopprijs"), inkoopprijs = datareader.GetDouble("inkoopprijs"), maatId = datareader.GetInt32("maatId"), voorraad = datareader.GetInt32("voorraad"), }; return productDetail; }