//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()); } }
//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()); } }
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()); } }
//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()); } }
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); } }
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())); } }
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(); }
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)); } }
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)); } }
// 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()); } }
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(); }