예제 #1
0
 public ActionResult UpdateCategorie(Categorie categorie)
 {
     CategorieDbController controller = new CategorieDbController();
     controller.UpdateCategorie(categorie);
     ViewBag.Succes = "Het updaten van deze categorie is gelukt";
     return RedirectToAction("Beheer", "Account");
 }
예제 #2
0
        public ActionResult VoegCategorieToe(Categorie categorie)
        {
            if(ModelState.IsValid){
            CategorieDbController controller = new CategorieDbController();
            controller.insertCategorie(categorie);
            ViewBag.succes = "Het toevoegen van het product is gelukt";
            }

            return RedirectToAction("Beheer", "Account");
        }
        public void insertCategorie(Categorie categorie)
        {
            try
            {
                conn.Open();
                string insertString = @"insert into categorie (naam, omschrijving, hoofdId) " +
                                        "values (@naam, @omschrijving, @hoofdId)";

                MySqlCommand cmd = new MySqlCommand(insertString, conn);
                MySqlParameter naamParam = new MySqlParameter("@naam", MySqlDbType.VarChar);
                MySqlParameter omschrijvingParam = new MySqlParameter("@omschrijving", MySqlDbType.VarChar);
                MySqlParameter hoofdIdParam = new MySqlParameter("@hoofdId", MySqlDbType.Int32);

                naamParam.Value = categorie.Naam;
                omschrijvingParam.Value = categorie.Omschrijving;
                if (categorie.HoofdcategorieId != 0)
                {
                    hoofdIdParam.Value = categorie.HoofdcategorieId;
                }
                else
                {
                    hoofdIdParam.Value = null;
                }
                cmd.Parameters.Add(naamParam);
                cmd.Parameters.Add(omschrijvingParam);
                
                cmd.Parameters.Add(hoofdIdParam);

                cmd.Prepare();
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.Write("Categorie niet toegevoegd: " + e);
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
        public void UpdateCategorie(Categorie categorie)
        {
            try
            {
                conn.Open();

                string insertString = "Update categorie set naam = @naam, omschrijving = @omschrijving, hoofdId = @hoofdId where categorieId = @categorieId";
                
                MySqlCommand cmd = new MySqlCommand(insertString, conn);
                MySqlParameter naamParam = new MySqlParameter("@naam", MySqlDbType.VarChar);
                MySqlParameter omschrijvingParam = new MySqlParameter("@omschrijving", MySqlDbType.VarChar);
                MySqlParameter hoofdIdPercentageParam = new MySqlParameter("@hoofdId", MySqlDbType.Int32);
                MySqlParameter idParam = new MySqlParameter("@categorieId", MySqlDbType.Int32);

                naamParam.Value = categorie.Naam;
                omschrijvingParam.Value = categorie.Omschrijving;
                hoofdIdPercentageParam.Value = categorie.HoofdcategorieId;
                idParam.Value = categorie.Id;
                cmd.Parameters.Add(idParam);
                cmd.Parameters.Add(naamParam);
                cmd.Parameters.Add(omschrijvingParam);
                cmd.Parameters.Add(hoofdIdPercentageParam);

                cmd.Prepare();
                cmd.ExecuteNonQuery();
            }
            catch (Exception e)
            {
                Console.Write("Categorie niet toegevoegd: " + e);
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
        public Categorie getCategorieFromId(int categorieId)
        {
            Categorie categorie = new Categorie();
            try
            {
                conn.Open();

                string selectQuery = "SELECT categorieId, naam, omschrijving, hoofdId FROM categorie where categorieId = @categorieId;";
                MySqlCommand cmd = new MySqlCommand(selectQuery, conn);
                MySqlParameter categorieIdParam = new MySqlParameter("@categorieId", MySqlDbType.Int32);
                categorieIdParam.Value = categorieId;
                cmd.Parameters.Add(categorieIdParam);
                cmd.Prepare();
                MySqlDataReader dataReader = cmd.ExecuteReader();

                if (dataReader != null)
                {
                    while (dataReader.Read())
                    {
                        categorie = getFullCategorieFromDataReader(dataReader);
                        categorie.Id = categorieId;
                    }
                }

            }
            catch (Exception e)
            {
                Console.Write("Ophalen van categorie mislukt " + e);
                throw e;
            }
            finally
            {
                conn.Close();
            }

            return categorie;
        }
예제 #6
0
        protected Categorie getFullCategorieFromDataReader(MySqlDataReader datareader)
        {
            Categorie categorie = new Categorie
            {
                Id = datareader.GetInt32("categorieId"),
                Naam = datareader.GetString("naam"),
                Omschrijving = datareader.GetString("omschrijving")
                
            };
            try { categorie.HoofdcategorieId = datareader.GetInt32("hoofdId"); }
            catch { }

                
            return categorie;
        }