public async Task SearchProducts()
        {
            var dbContext = new SalesDbContext();

            dbContext.Database.Log = s => Console.WriteLine(s);

            var uow = new SalesUow(dbContext) as ISalesUow;

            var businessObject = new SalesBusinessObject(uow) as ISalesBusinessObject;

            Int32? supplierID  = null;
            Int32? categoryID  = null;
            String productName = null;

            var query = await Task.Run(() =>
            {
                return(businessObject.GetProductsDetails(supplierID, categoryID, productName));
            });

            foreach (var item in query.ToList())
            {
                Console.Write("ID: {0},", item.ProductID);
                Console.Write("Name: {0},", item.ProductName);
                Console.Write("Supplier: {0},", item.SupplierID);
                Console.Write("Category: {0}", item.CategoryID);
                Console.WriteLine();
            }
        }
Esempio n. 2
0
        public async Task CreateOrder()
        {
            var header = new Order();

            header.CustomerID     = "ANATR";
            header.EmployeeID     = 6;
            header.OrderDate      = DateTime.Now;
            header.RequiredDate   = DateTime.Now.AddDays(7);
            header.ShippedDate    = null;
            header.ShipVia        = 1;
            header.Freight        = 25.0m;
            header.ShipName       = "Bill Gates";
            header.ShipAddress    = "Redmon II";
            header.ShipCity       = "Washington";
            header.ShipRegion     = "West";
            header.ShipPostalCode = "12345";
            header.ShipCountry    = "USA";

            header.OrderSummaries = new Collection <OrderDetailSummary>()
            {
                new OrderDetailSummary {
                    ProductID = 1, Quantity = 3, Discount = 0.0m
                },
                new OrderDetailSummary {
                    ProductID = 10, Quantity = 2, Discount = 0.0m
                },
                new OrderDetailSummary {
                    ProductID = 20, Quantity = 1, Discount = 0.0m
                },
                new OrderDetailSummary {
                    ProductID = 30, Quantity = 1, Discount = 0.0m
                }
            };

            var dbContext = new SalesDbContext();

            dbContext.Database.Log = s => Console.WriteLine(s);

            var uow = new SalesUow(dbContext) as ISalesUow;

            var businessObject = new SalesBusinessObject(uow) as ISalesBusinessObject;

            var entity = await Task.Run(() =>
            {
                return(businessObject.CreateOrder(header));
            });

            Console.WriteLine("Order #: {0}", entity.OrderID);

            businessObject.Release();
        }
Esempio n. 3
0
        public async Task IncreaseStocks()
        {
            var businessObject = new SalesBusinessObject(new SalesUow(new SalesDbContext()) as ISalesUow) as ISalesBusinessObject;

            var products = await Task.Run(() => { return(businessObject.GetProductsDetails(null, null, String.Empty).Where(item => item.Discontinued == false).ToList()); });

            foreach (var item in products)
            {
                var entity = await Task.Run(() =>
                {
                    return(businessObject.GetProduct(new Product(item.ProductID)));
                });

                entity.UnitsInStock += 9999;

                await Task.Run(() =>
                {
                    businessObject.UpdateProduct(entity);
                });
            }

            businessObject.Release();
        }
Esempio n. 4
0
        async Task CreateData(DateTime startDate, DateTime endDate, Int32 limit, Decimal?[] freights)
        {
            var date = new DateTime(startDate.Year, startDate.Month, startDate.Day);

            var random = new Random();

            while (date <= endDate)
            {
                if (date.DayOfWeek != DayOfWeek.Sunday)
                {
                    var businessObject = new SalesBusinessObject(new SalesUow(new SalesDbContext()) as ISalesUow) as ISalesBusinessObject;

                    var customers = await Task.Run(() => { return(businessObject.GetCustomers().ToList()); });

                    var employees = await Task.Run(() => { return(businessObject.GetEmployees().ToList()); });

                    var shippers = await Task.Run(() => { return(businessObject.GetShippers().ToList()); });

                    var products = await Task.Run(() => { return(businessObject.GetProductsDetails(null, null, null).Where(item => item.Discontinued == false).ToList()); });

                    for (var j = 0; j < limit; j++)
                    {
                        var header = new Order();

                        var selectecCustomer = customers[random.Next(0, customers.Count - 1)];
                        var selectedEmployee = employees[random.Next(0, employees.Count - 1)];
                        var selectedShipper  = shippers[random.Next(0, shippers.Count - 1)];

                        header.CustomerID     = selectecCustomer.CustomerID;
                        header.EmployeeID     = selectedEmployee.EmployeeID;
                        header.OrderDate      = date;
                        header.RequiredDate   = date.AddDays(7);
                        header.ShippedDate    = null;
                        header.ShipVia        = selectedShipper.ShipperID;
                        header.Freight        = freights[random.Next(0, freights.Length)];
                        header.ShipName       = selectecCustomer.CompanyName;
                        header.ShipAddress    = selectecCustomer.Address;
                        header.ShipCity       = selectecCustomer.City;
                        header.ShipRegion     = selectecCustomer.Region;
                        header.ShipPostalCode = selectecCustomer.PostalCode;
                        header.ShipCountry    = selectecCustomer.Country;

                        header.OrderSummaries = new Collection <OrderDetailSummary>()
                        {
                        };

                        var summaries = random.Next(1, 10);

                        for (var i = 0; i < summaries; i++)
                        {
                            var summary = new OrderDetailSummary
                            {
                                ProductID = products[random.Next(0, products.Count - 1)].ProductID,
                                Quantity  = (Int16)random.Next(1, 10),
                                Discount  = 0.0m
                            };

                            if (header.OrderSummaries.Where(item => item.ProductID == summary.ProductID).Count() == 0)
                            {
                                header.OrderSummaries.Add(summary);
                            }
                        }

                        var entity = await Task.Run(() =>
                        {
                            return(businessObject.CreateOrder(header));
                        });

                        Console.WriteLine("Order #: {0}", entity.OrderID);
                    }

                    businessObject.Release();
                }

                date = date.AddDays(1);
            }
        }