Exemple #1
0
        public bool AddBestelling(Bestelling bestelling)
        {
            this.ResetErrorMessage();

            bool succes = false;

            try
            {
                this.MySqlConnection.Open();

                string sql = $"INSERT INTO tblbestelling(datum, gebruikersnaam, prijs, betaald, code) VALUES(@datum, @gebruikersnaam, @prijs, @betaald, @code);";

                MySqlCommand command = new MySqlCommand(sql, this.MySqlConnection);

                command.Parameters.AddWithValue("@datum", bestelling.AanmaakDatum);
                command.Parameters.AddWithValue("@gebruikersnaam", bestelling.GebruikersNaam);
                command.Parameters.AddWithValue("@prijs", bestelling.TotaalBedrag);
                command.Parameters.AddWithValue("@betaald", 0);
                command.Parameters.AddWithValue("@code", bestelling.Code);

                if (command.ExecuteNonQuery() > 0)
                {
                    succes = true;
                }
            }
            catch (MySqlException ex)
            {
                this.ErrorMessage = ex.ToString();
                succes            = false;
            }

            this.MySqlConnection.Close();

            int bestelnr = GetBestelnr(bestelling.Code);

            foreach (BesteldArtikel besteldArtikel in bestelling.GetBesteldeArtikels())
            {
                this.AddBesteldArtikel(besteldArtikel, bestelnr);
            }

            return(succes);
        }