Ejemplo n.º 1
0
        public void DeleteGenre(Genre genre)
        {
            MySqlTransaction trans = null;
            try
            {
                conn.Open();
                trans = conn.BeginTransaction();
                string insertString = @"delete from genre where genre_id=@id";

                MySqlCommand cmd = new MySqlCommand(insertString, conn);
                MySqlParameter idParam = new MySqlParameter("@id", MySqlDbType.Int32);
                idParam.Value = genre.ID;

                cmd.Parameters.Add(idParam);
                cmd.Prepare();
                cmd.ExecuteNonQuery();

                trans.Commit();

            }
            catch (Exception e)
            {
                trans.Rollback();
                Console.Write("Genre niet verwijderd: " + e);
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
 protected Genre GetGenreFromDataReader(MySqlDataReader dataReader)
 {
     string genreNaam = dataReader.GetString("genrenaam");
     int genreId = dataReader.GetInt32("genre_id");
     bool verslavend = dataReader.GetBoolean("verslavend");
     Genre genre = new Genre { ID = genreId, Naam = genreNaam, Verslavend = verslavend };
     return genre;
 }
Ejemplo n.º 3
0
        public ActionResult CreateGenreModelBinding(Genre genre)
        {
            try
            {
                genreDBController.InsertGenre(genre);

            }
            catch (Exception e)
            {
                ViewBag.Foutmelding = "Er is iets fout gegaan:" + e;
            }
            return RedirectToAction("Index", "Genre");
        }
Ejemplo n.º 4
0
 public ActionResult CreateGenreParameterBinding(String name, String verslavend)
 {
     bool isVerslavend = verslavend == "on";
     Genre genre = new Genre { Naam = name, Verslavend = isVerslavend };
     try
     {
         genreDBController.InsertGenre(genre);
     }
     catch (Exception e)
     {
         ViewBag.Foutmelding = "Er is iets fout gegaan:" + e;
     }
     return RedirectToAction("Index", "Genre");
 }
Ejemplo n.º 5
0
        public ActionResult CreateGenreOldSchool()
        {
            String name = Request["name"];
            bool verslavend = Request["verslavend"] == "on";
            Genre genre = new Genre { Naam = name, Verslavend = verslavend };
            try
            {
                genreDBController.InsertGenre(genre);
            }
            catch (Exception e)
            {
                ViewBag.Foutmelding = "Er is iets fout gegaan:" + e;
                return View();
            }

            return RedirectToAction("Index", "Genre");
        }
Ejemplo n.º 6
0
        public ActionResult WijzigGenre(Genre genre)
        {
            try
            {
                genreDBController.UpdateGenre(genre);

            }
            catch (Exception e)
            {
                ViewBag.FoutMelding("Er is iets fout gegaan: " + e);

            }
            return RedirectToAction("Index", "Genre");
        }
Ejemplo n.º 7
0
        public void UpdateGenre(Genre genre)
        {
            MySqlTransaction trans = null;
            try
            {
                conn.Open();
                trans = conn.BeginTransaction();
                string insertString = @"update genre set genrenaam=@genrenaam, verslavend=@verslavend where genre_id=@id";

                MySqlCommand cmd = new MySqlCommand(insertString, conn);
                MySqlParameter genrenaamParam = new MySqlParameter("@genrenaam", MySqlDbType.VarChar);
                MySqlParameter verslavendParam = new MySqlParameter("@verslavend", MySqlDbType.Bit);
                MySqlParameter idParam = new MySqlParameter("@id", MySqlDbType.Int32);

                genrenaamParam.Value = genre.Naam;
                verslavendParam.Value = genre.Verslavend;
                idParam.Value = genre.ID;

                cmd.Parameters.Add(genrenaamParam);
                cmd.Parameters.Add(verslavendParam);
                cmd.Parameters.Add(idParam);

                cmd.Prepare();
                cmd.ExecuteNonQuery();
                trans.Commit();

            }
            catch (Exception e)
            {
                trans.Rollback();
                Console.Write("Genre niet upgedate: " + e);
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }
Ejemplo n.º 8
0
        public void InsertGenre(Genre genre)
        {
            MySqlTransaction trans = null;
            try
            {
                conn.Open();
                trans = conn.BeginTransaction();
                string insertString = @"insert into genre (genrenaam, verslavend)
                                               values (@genrenaam, @verslavend)";
                MySqlCommand cmd = new MySqlCommand(insertString, conn);
                MySqlParameter genrenaamParam = new MySqlParameter("@genrenaam", MySqlDbType.VarChar);
                MySqlParameter verslavendParam = new MySqlParameter("@verslavend", MySqlDbType.Bit);

                genrenaamParam.Value = genre.Naam;
                verslavendParam.Value = genre.Verslavend;

                cmd.Parameters.Add(genrenaamParam);
                cmd.Parameters.Add(verslavendParam);

                cmd.Prepare();

                cmd.ExecuteNonQuery();

                trans.Commit();

            }
            catch (Exception e)
            {
                trans.Rollback();
                Console.Write("Genre niet toegevoegd: " + e);
                throw e;
            }
            finally
            {
                conn.Close();
            }
        }