Esempio n. 1
0
        public bool Insert(Models.Product prod)
        {
            string sql = @"insert product (Name, Category, SellPrice, BuyPrice) values (@Name, @Category, @SellPrice, @BuyPrice)";

            Dictionary <string, object> param = new Dictionary <string, object>();

            param.Add("@Name", prod.Name);
            param.Add("@Category", prod.Category);
            param.Add("@SellPrice", prod.SellPrice);
            param.Add("@BuyPrice", prod.BuyPrice);

            int qtdLinhas = _db.ExecuteNonQuery(sql, param);

            return(qtdLinhas > 0);
        }
Esempio n. 2
0
        public bool Insert(Models.User user)
        {
            MySQLPersistence db = new MySQLPersistence(true);
            bool             ok = false;


            try
            {
                db.StartTransaction();


                //Mapeamento Objeto-Relacional
                string sql = @"insert user (Name, Email, Password) values (@Name, @Email, @Password)";

                Dictionary <string, object> param = new Dictionary <string, object>();
                param.Add("@Name", user.Name);
                param.Add("@Email", user.Email);
                param.Add("@Password", user.Password);

                int qtdLinhas = db.ExecuteNonQuery(sql, param);

                /*db.CleanParam();
                 *
                 * sql = @"insert user (Name, Email, Password) values (@Name, @Email, @Password)";
                 *
                 * param.Clear();
                 * param.Add("@Name", user.Name);
                 * param.Add("@Email", user.Email);
                 * param.Add("@Password", user.Password);
                 *
                 * qtdLinhas = db.ExecuteNonQuery(sql, param);*/

                ok = qtdLinhas > 0;

                db.TransactionCommit();
            }
            catch
            {
                db.TransactionRollback();
            }
            finally
            {
                db.Close();
            }

            return(ok);
        }