예제 #1
0
 //Create orders without parametrs
 public static List <OrderDO> GetOrders()
 {
     using (MyCSharpDotNetEntities context =
                new MyCSharpDotNetEntities())
     {
         return(context.Orders
                .Select(x => new OrderDO
         {
             orderID = x.OrderID,
             orderDate = x.OrderDate,
             lastName = x.Employee.LastName
         }).ToList());
     }
 }
예제 #2
0
 //Create orders async without parametrs
 public static async Task <List <OrderDO> > GetOrdersAsync()
 {
     using (MyCSharpDotNetEntities context =
                new MyCSharpDotNetEntities())
     {
         return(await context.Orders
                .Select(x => new OrderDO()
         {
             orderID = x.OrderID,
             orderDate = x.OrderDate,
             lastName = x.Employee.LastName
         })
                .ToListAsync());
     }
 }
예제 #3
0
 public List <OrderDataModel> GetOrders(string customerId)
 {
     using (MyCSharpDotNetEntities context =
                new MyCSharpDotNetEntities())
     {
         return(context.Orders
                .Where(order => order.CustomerID == customerId)
                .Select(order => new OrderDataModel
         {
             OrderID = order.OrderID,
             OrderDate = order.OrderDate,
             EmployeeLastName = order.Employee.LastName,
             CustomerID = order.CustomerID
         }).ToList());
     }
 }
예제 #4
0
 //Create orders with parametr customerID
 public List <OrderDO> GetOrders(string customerID)
 {
     using (MyCSharpDotNetEntities context =
                new MyCSharpDotNetEntities())
     {
         return(context.Orders
                .Select(x => new OrderDO()
         {
             orderID = x.OrderID,
             orderDate = x.OrderDate,
             lastName = x.Employee.LastName,
             customerID = x.CustomerID
         })
                .Where(x => x.customerID.Equals(customerID))
                .ToList());
     }
 }
예제 #5
0
 public static List <OrderDataObject> ListOrders(string customerId)
 {
     using (MyCSharpDotNetEntities context =
                new MyCSharpDotNetEntities())
     {
         List <OrderDataObject> orders = context.Orders
                                         .Where(order => order.CustomerID == customerId)
                                         .Select(order => new OrderDataObject()
         {
             OrderID          = order.OrderID,
             OrderDate        = order.OrderDate,
             EmployeeLastName = order.Employee.LastName,
             CustomerID       = order.CustomerID
         }).ToList();
         return(orders);
     }
 }
예제 #6
0
 public async Task <IHttpActionResult> GetOrders([FromUri] string parametr)
 {
     using (MyCSharpDotNetEntities context =
                new MyCSharpDotNetEntities())
     {
         return(Ok(await context.Orders
                   .Select(x => new OrderDO()
         {
             orderID = x.OrderID,
             orderDate = x.OrderDate,
             lastName = x.Employee.LastName,
             customerID = x.CustomerID
         })
                   .Where(x => x.customerID == parametr)
                   .ToListAsync()));
     }
 }
예제 #7
0
        static void Main(string[] args)
        {
            using (MyCSharpDotNetEntities context = new MyCSharpDotNetEntities())
            {
                List <Category> categories = context.Categories.ToList();

                //Print categories
                PrintCategories(categories);

                //Get category from user
                Category selectedCategory = SelectCategory(categories);

                //Print category products
                PrintProducts(selectedCategory);
            }
            Console.ReadKey();
        }
예제 #8
0
        public static async Task <List <OrderDataObject> > ListOrdersAsync(string customerId)
        {
            using (MyCSharpDotNetEntities context =
                       new MyCSharpDotNetEntities())
            {
                await Task.Delay(1000);

                List <OrderDataObject> orders = context.Orders
                                                .Where(order => order.CustomerID == customerId)
                                                .Select(order => new OrderDataObject()
                {
                    OrderID          = order.OrderID,
                    OrderDate        = order.OrderDate,
                    EmployeeLastName = order.Employee.LastName,
                    CustomerID       = order.CustomerID
                }).ToList();
                return(await Task.FromResult(orders));
            }
        }
예제 #9
0
        public async Task <ObservableCollection <OrderDataModel> > LoadOrdersAsync()
        {
            using (MyCSharpDotNetEntities context =
                       new MyCSharpDotNetEntities())
            {
                Loading = true;
                await Task.Delay(1000);

                Orders = new ObservableCollection <OrderDataModel>(context.Orders
                                                                   .Where(order => order.CustomerID == SearchText)
                                                                   .Select(order => new OrderDataModel
                {
                    OrderID          = order.OrderID,
                    OrderDate        = order.OrderDate,
                    EmployeeLastName = order.Employee.LastName,
                    CustomerID       = order.CustomerID
                }));
                Loading = false;
                return(await Task.FromResult(Orders));
            }
        }
예제 #10
0
 // asynchroní metoda pro načtení objednávek
 public static async Task <List <CustomerOrderDO> > GetOrdersAsync(
     string customerID)
 {
     using (MyCSharpDotNetEntities context =
                new MyCSharpDotNetEntities())
     {
         // return obstarávající select a join tabulek pro získání dat
         return(await context.Orders
                .Where(orders => orders.CustomerID == customerID)
                .Join(context.Employees,
                      orders => orders.EmployeeID,           // cizí klíč z tab objednávek
                      employees => employees.EmployeeID,     // prim. klíč z tab zaměstnanců
                      (orders, employees) => new CustomerOrderDO()
         {
             OrderID = orders.OrderID,
             OrderDate = (DateTime)orders.OrderDate,
             EmployeeLastName = employees.LastName,
         })
                .ToListAsync());
     }
 }
예제 #11
0
        static void Main(string[] args)
        {
            Console.WriteLine("AVAILABLE CATEGORIES:");
            Console.WriteLine("--------------------");
            Console.WriteLine("");
            List <String> ExistCategory = new List <string>()
            ;

            // Create SQL query to ask for information about Categories

            using (MyCSharpDotNetEntities context = new MyCSharpDotNetEntities())
            {
                var smallCategories = context.Categories
                                      .Select(x => new {
                    CategoryID   = x.CategoryID,
                    CategoryName = x.CategoryName,
                    Description  = x.Description
                });;


                // Write to console information about Categories
                foreach (var smallCategorie in smallCategories)
                {
                    ExistCategory.Add(smallCategorie.CategoryID.ToString());
                    Console.WriteLine(
                        "{0}, {1} ({2})",
                        smallCategorie.CategoryID,
                        smallCategorie.CategoryName,
                        smallCategorie.Description);
                }
            }


            // End part about category
            Console.WriteLine();
            bool   idIsNotReady = true;
            string categoryID   = null;

            // Choose category ID and validate it
            while (idIsNotReady)
            {
                Console.Write("To list product, enter the category ID: ");


                categoryID = Console.ReadLine();

                try
                {
                    Int32.Parse(categoryID);
                    idIsNotReady = false;
                }
                catch
                {
                    Console.WriteLine("Wrong input! ");
                }
            }


            Console.Clear();
            Console.WriteLine("LIST OF PRODUCTS:");
            Console.WriteLine("--------------------");
            Console.WriteLine("");
            if (ExistCategory.Contains(categoryID.ToString()))
            {
                // Create SQL query to ask for information about TOP 5 products in choosen category
                using (MyCSharpDotNetEntities context = new MyCSharpDotNetEntities())
                {
                    var smallProducts =
                        context.Products
                        .Where(x => x.CategoryID.ToString().Equals(categoryID))
                        .OrderByDescending(x => x.UnitsInStock)
                        .Take(5)
                        .Select(x => new {
                        ProductID   = x.ProductID,
                        ProductName = x.ProductName
                    });


                    foreach (var smallProduct in smallProducts)
                    {
                        Console.WriteLine(
                            "ID: {0}, Name: {1} ",
                            smallProduct.ProductID,
                            smallProduct.ProductName);
                    }
                }
            }
            else
            {
                Console.WriteLine("Unknow ID");
            }

            // END part of the code

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Press enter to close the application");
            Console.Read();
        }