Ejemplo n.º 1
0
        public List <CustOrderHist> GetCustOrderHist(string customerId)
        {
            string spName            = "dbo.CustOrderHist";
            var    custOrderHistList = new List <CustOrderHist>();

            using (var connection = new SqlConnection(ConnectionString))
            {
                connection.ConnectionString = ConnectionString;
                connection.Open();

                using (var command = new SqlCommand(spName, connection))
                {
                    command.CommandType = CommandType.StoredProcedure;
                    var customerIdParam = new SqlParameter("@CustomerID", customerId);
                    command.Parameters.Add(customerIdParam);

                    using (var reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var custOrderHist = new CustOrderHist();
                            custOrderHist.ProductName = reader.GetSafe <string>("ProductName");
                            custOrderHist.Total       = reader.GetSafe <int>("Total");

                            custOrderHistList.Add(custOrderHist);
                        }

                        return(custOrderHistList);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void Test()
        {
            TimeWatch.Clean();
            TimeWatch.________________________________________________________("Peaunt Exeuctes");

            CustOrderHist coh = new CustOrderHist();

            coh.CustomerID = "ANATR";
            IList <CustOrderHistItem> cohs = coh.List <CustOrderHistItem>();

            foreach (CustOrderHistItem item in cohs)
            {
                Console.WriteLine(item.ProductName);
            }


            SQL      sql;
            Employee employee = (Employee.employeeID == 3).ListFirst <Employee>(DB.DB3);

            Console.WriteLine(employee);
            TimeWatch.________________________________________________________("Insert Employee");
            sql = "insert into employees(firstname,lastname) values(@p1,@p2)";
            sql["p1", "henry"]["p2", "fan"].Execute();
            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("del employee");
            sql = "delete from employees where firstname=@p1";
            sql["p1", "henry"].Execute();
            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("count employee");
            Query <int> getCount = "select count(*) from employees";

            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("get employee");
            Query <Employee> getEmp = "select * from employees where employeeid=3";

            TimeWatch.________________________________________________________();


            TimeWatch.________________________________________________________("list employee");
            Query <IList <Employee> > getEmps = "select * from employees";

            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("del employee with expression");
            (Employee.firstName == "henry").Delete <Employee>();
            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("modify employee");
            (Employee.employeeID == 3).Edit <Employee>(d => { d.LastName = "a"; });
            TimeWatch.________________________________________________________();

            ListOrders();

            TimeWatch.________________________________________________________();

            TimeWatch.Report(o => { Console.WriteLine(o.ToString()); });
        }
Ejemplo n.º 3
0
        public void GetOrderHistsTest()
        {
            const string custId = "LAZYK";

            var histReal = repository.GetOrderHists(custId);

            var histExp = new OrderHist
            {
                CustHist = new List <CustOrderHist>()
            };
            var prodBoston = new CustOrderHist()
            {
                ProductName = "Boston Crab Meat",
                Total       = 10
            };

            histExp.CustHist.Add(prodBoston);

            var prodQueso = new CustOrderHist()
            {
                ProductName = "Queso Cabrales",
                Total       = 10
            };

            histExp.CustHist.Add(prodQueso);

            Assert.That(histExp, Is.EqualTo(histReal).Using(new OrderHistComparer()));
        }
Ejemplo n.º 4
0
        public static void Test()
        {

           

            TimeWatch.Clean();
            TimeWatch.________________________________________________________("Peaunt Exeuctes");

            CustOrderHist coh = new CustOrderHist();
            coh.CustomerID = "ANATR";
            IList<CustOrderHistItem> cohs = coh.List<CustOrderHistItem>();
            foreach (CustOrderHistItem item in cohs)
            {
                Console.WriteLine(item.ProductName);
            }

           
            SQL sql;
            Employee employee = (Employee.employeeID == 3).ListFirst<Employee>(DB.DB3);
            Console.WriteLine(employee);
            TimeWatch.________________________________________________________("Insert Employee");
            sql = "insert into employees(firstname,lastname) values(@p1,@p2)";
            sql["p1", "henry"]["p2", "fan"].Execute();
            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("del employee");
            sql = "delete from employees where firstname=@p1";
            sql["p1", "henry"].Execute();
            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("count employee");
            Query<int> getCount = "select count(*) from employees";
            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("get employee");
            Query<Employee> getEmp = "select * from employees where employeeid=3";
            TimeWatch.________________________________________________________();


            TimeWatch.________________________________________________________("list employee");
            Query<IList<Employee>> getEmps = "select * from employees";
            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("del employee with expression");
            (Employee.firstName == "henry").Delete<Employee>();
            TimeWatch.________________________________________________________();

            TimeWatch.________________________________________________________("modify employee");
            (Employee.employeeID == 3).Edit<Employee>(d => { d.LastName = "a"; });
            TimeWatch.________________________________________________________();

            ListOrders();

            TimeWatch.________________________________________________________();

            TimeWatch.Report(o => { Console.WriteLine(o.ToString()); });
        }
Ejemplo n.º 5
0
        public static void Test()
        {
            CustOrderHist coh = new CustOrderHist();

            coh.CustomerID = "ANATR";
            IList <CustOrderHistItem> cohs = coh.List <CustOrderHistItem>();

            foreach (CustOrderHistItem item in cohs)
            {
                Console.WriteLine(item.ProductName);
            }


            SQL      sql;
            Employee employee = (Employee.employeeID == 3).ListFirst <Employee>(DB.DB3);

            Console.WriteLine(employee);

            sql = "insert into employees(firstname,lastname) values(@p1,@p2)";
            sql["p1", "henry"]["p2", "fan"].Execute();

            sql = "delete from employees where firstname=@p1";
            sql["p1", "henry"].Execute();

            Query <int> getCount = "select count(*) from employees";



            Query <Employee> getEmp = "select * from employees where employeeid=3";



            Query <IList <Employee> > getEmps = "select * from employees";



            (Employee.firstName == "henry").Delete <Employee>();



            (Employee.employeeID == 3).Edit <Employee>(d => { d.LastName = "a"; });

            ListOrders();
        }
        /// <inheritdoc/>
        public virtual IEnumerable <CustOrderHist> GetCustOrderHist(string customerId)
        {
            using (var connection = _providerFactory.CreateConnection())
            {
                connection.ConnectionString = _connectionString;
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "CustOrderHist";
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.Add(
                        new SqlParameter
                    {
                        ParameterName = "@CustomerID",
                        Value         = customerId,
                        DbType        = DbType.String
                    }
                        );

                    using (var reader = command.ExecuteReader())
                    {
                        var custList = new List <CustOrderHist>();
                        while (reader.Read())
                        {
                            var custOrderHist = new CustOrderHist();

                            custOrderHist.ProductName   = (string)reader["ProductName"];
                            custOrderHist.CoastQuantity = (int)reader["Total"];

                            custList.Add(custOrderHist);
                        }

                        return(custList);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        public void GetCustOrderHistTest()
        {
            var result = new CustOrderHist();

            result.ProductName = new List <string>();
            result.Total       = new List <int>();
            var resExecMethod = new CustOrderHist();

            resExecMethod.ProductName = new List <string>();
            resExecMethod.Total       = new List <int>();

            using (DbConnection connection = this.providerFactory.CreateConnection())
            {
                connection.ConnectionString = this.connectionString;
                connection.Open();

                var command = (SqlCommand)connection.CreateCommand();
                command.CommandText = "SELECT TOP 1 CustomerID FROM [dbo].[Customers]";
                result.CustomerID   = (string)command.ExecuteScalar();
                resExecMethod       = this.repository.GetCustOrderHist(result.CustomerID);

                command.Parameters.AddWithValue("@custId", result.CustomerID);
                command.CommandText = "EXECUTE [dbo].[CustOrderHist] @CustomerID = @custId";

                using (IDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        result.ProductName.Add((string)reader["ProductName"]);
                        result.Total.Add((int)reader["Total"]);
                    }
                }
            }

            Assert.AreEqual(resExecMethod.CustomerID, result.CustomerID);
            Assert.AreEqual(resExecMethod.ProductName[0], result.ProductName[0]);
            Assert.AreEqual(resExecMethod.Total[0], result.Total[0]);
        }