public static IEnumerable<ClientOrderViewModel> All()
        {
            IEnumerable<ClientOrderViewModel> result = HttpContext.Current.Session["orders"] as IEnumerable<ClientOrderViewModel>;

            if (result == null)
            {
                HttpContext.Current.Session["orders"] = result = new NorthwindDataContext().Orders
                    .Select(o => new ClientOrderViewModel
                    {
                        OrderID = o.OrderID,
                        OrderDate = o.OrderDate ?? DateTime.Now,
                        ShipAddress = o.ShipAddress,
                        ShipCountry = o.ShipCountry,
                        ShipName = o.ShipName,
                        ContactName = o.Customer.CompanyName,
                        EmployeeID = o.EmployeeID ?? 0,
                        Employee = new ClientEmployeeViewModel {
                            EmployeeName = o.Employee.FirstName + " " + o.Employee.LastName,
                            EmployeeID = o.EmployeeID ?? 0
                        }
                    }).ToList();
            }

            return result;
        }
예제 #2
0
 private void PopulateEmployees()
 {
     ViewData["employees"] = new NorthwindDataContext().Employees
                 .Select(e => new ClientEmployeeViewModel {
                     EmployeeID = e.EmployeeID,
                     EmployeeName = e.FirstName + " " + e.LastName
                 })
                 .OrderBy(e => e.EmployeeName);
 }
        public JsonResult GetCascadeProducts(string categories)
        {
            var northwind = new NorthwindDataContext();
            var products = northwind.Products.AsQueryable();

            if (!string.IsNullOrEmpty(categories))
            {
                products = products.Where(p => p.CategoryID.ToString() == categories);
            }

            return Json(products.Select(p => new { ProductID = p.ProductID, ProductName = p.ProductName}), JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetCascadeOrders(string products)
        {
            var northwind = new NorthwindDataContext();
            var orders = northwind.Order_Details.AsQueryable();

            if (!string.IsNullOrEmpty(products))
            {
                orders = orders.Where(o => o.ProductID.ToString() == products);
            }

            return Json(orders.Select(o => new { OrderID = o.OrderID, ShipCity = o.Order.ShipCity }), JsonRequestBehavior.AllowGet);
        }
        public JsonResult Employees(int? id)
        {
            var dataContext = new NorthwindDataContext();

            var employees = from e in dataContext.Employees
                            where (id.HasValue ? e.ReportsTo == id : e.ReportsTo == null)
                            select new {
                                id = e.EmployeeID,
                                Name = e.FirstName + " " + e.LastName,
                                hasChildren = e.Employees.Any()
                            };

            return Json(employees, JsonRequestBehavior.AllowGet);
        }
        private static IEnumerable<ProductViewModel> GetProducts()
        {
            var northwind = new NorthwindDataContext();

            return northwind.Products.Select(product => new ProductViewModel
            {
                ProductID = product.ProductID,
                ProductName = product.ProductName,
                UnitPrice = product.UnitPrice ?? 0,
                UnitsInStock = product.UnitsInStock ?? 0,
                UnitsOnOrder = product.UnitsOnOrder ?? 0,
                Discontinued = product.Discontinued,
                LastSupply = DateTime.Today
            });
        }
예제 #7
0
        private static IEnumerable<EmployeeViewModel> GetEmployees()
        {
            var northwind = new NorthwindDataContext();

            return northwind.Employees.Select(employee => new EmployeeViewModel
            {
                EmployeeID = employee.EmployeeID,
                FirstName = employee.FirstName,
                LastName = employee.LastName,
                Country = employee.Country,
                City = employee.City,
                Notes = employee.Notes,
                Title = employee.Title,
                Address = employee.Address,
                HomePhone = employee.HomePhone
            });
        }
예제 #8
0
        private static IEnumerable<OrderViewModel> GetOrders()
        {
            var northwind = new NorthwindDataContext();

            var loadOptions = new DataLoadOptions();

            loadOptions.LoadWith<Order>(o => o.Customer);
            northwind.LoadOptions = loadOptions;

            return northwind.Orders.Select(order => new OrderViewModel
            {
                ContactName = order.Customer.ContactName,
                OrderDate = order.OrderDate,
                OrderID = order.OrderID,
                ShipAddress = order.ShipAddress,
                ShipCountry = order.ShipCountry,
                ShipName = order.ShipName,
                EmployeeID = order.EmployeeID
            });
        }
        public JsonResult GetProducts(string text)
        {
            var northwind = new NorthwindDataContext();

            var products = northwind.Products.Select(product => new ProductViewModel
            {
                ProductID = product.ProductID,
                ProductName = product.ProductName,
                UnitPrice = product.UnitPrice ?? 0,
                UnitsInStock = product.UnitsInStock ?? 0,
                UnitsOnOrder = product.UnitsOnOrder ?? 0,
                Discontinued = product.Discontinued
            });

            if (!string.IsNullOrEmpty(text))
            {
                products = products.Where(p => p.ProductName.Contains(text));
            }

            return Json(products, JsonRequestBehavior.AllowGet);
        }
        public JsonResult GetCascadeCategories()
        {
            var northwind = new NorthwindDataContext();

            return Json(northwind.Categories.Select(c => new { CategoryId = c.CategoryID, CategoryName = c.CategoryName }), JsonRequestBehavior.AllowGet);
        }
 public ActionResult FilterMenuCustomization_Titles()
 {
     var db = new NorthwindDataContext();
     return Json(db.Employees.Select(e => e.Title).Distinct(), JsonRequestBehavior.AllowGet);
 }
 public ActionResult ModelBinding()
 {
     NorthwindDataContext northwind = new NorthwindDataContext();
     return View(northwind.Categories);
 }