예제 #1
0
        public DataTable List()
        {
            return(handle.ExceptionTypeHandler <DataTable>(() =>
            {
                DataTable productTable = new DataTable();

                string query = "SELECT[platform], [url], [name], [price],[mail_address],[price_percent] FROM dbo.products as p INNER JOIN dbo.e_mails as e ON e.id = p.mail_id";

                using (command = new SqlCommand(query, connection))
                {
                    ConnectionControl();
                    using (SqlDataAdapter dataAdapter = new SqlDataAdapter())
                    {
                        dataAdapter.SelectCommand = command;

                        dataAdapter.Fill(productTable);

                        ConnectionControl();
                    }
                };

                return productTable;
            }));
        }
예제 #2
0
        public int Save(Email mail)
        {
            return(handle.ExceptionTypeHandler <int>(() =>
            {
                string query = "INSERT INTO dbo.e_mails(mail_address,price_percent) output INSERTED.id VALUES(@mail_address,@price_percent)";
                using (command = new SqlCommand(query, connection))
                {
                    command.Parameters.Add("@mail_address", SqlDbType.VarChar, 150).Value = mail.MailAddress;
                    command.Parameters.Add("@price_percent", SqlDbType.Int).Value = mail.PricePercent;

                    ConnectionControl();
                    int mailID = Convert.ToInt32(command.ExecuteScalar());
                    ConnectionControl();

                    return mailID;
                };
            }));

            return(0);
        }