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; }
private void PopulateCategories() { var dataContext = new NorthwindDataContext(); var categories = dataContext.Categories .Select(c => new ClientCategoryViewModel { CategoryID = c.CategoryID, CategoryName = c.CategoryName }) .OrderBy(e => e.CategoryName); ViewData["categories"] = categories; ViewData["defaultCategory"] = categories.First(); }
private ClientCategoryViewModel GetCategory(int categoryID) { var dataContext = new NorthwindDataContext(); var category = dataContext.Categories .Where(c=> c.CategoryID == categoryID) .Select(c => new ClientCategoryViewModel { CategoryID = c.CategoryID, CategoryName = c.CategoryName }).FirstOrDefault(); return category; }
public ActionResult ToolbarTemplate_Categories() { var dataContext = new NorthwindDataContext(); var categories = dataContext.Categories .Select(c => new ClientCategoryViewModel { CategoryID = c.CategoryID, CategoryName = c.CategoryName }) .OrderBy(e => e.CategoryName); return Json(categories, JsonRequestBehavior.AllowGet); }
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 ActionResult Categories([DataSourceRequest] DataSourceRequest request) { var dataContext = new NorthwindDataContext(); var categories = dataContext.Categories .Select(c => new ClientCategoryViewModel { CategoryID = c.CategoryID, CategoryName = c.CategoryName }) .OrderBy(e => e.CategoryName); return Json(categories.ToDataSourceResult(request)); }
public ActionResult Order_Details([DataSourceRequest] DataSourceRequest request) { var dataContext = new NorthwindDataContext(); var details = dataContext.Order_Details .Select(d => new { Discount = d.Discount, Quantity = d.Quantity, UnitPrice = d.UnitPrice, ProductID = d.ProductID }); return Json(details.ToDataSourceResult(request)); }
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); }
public JsonResult Employees(int? EmployeeId) { var dataContext = new NorthwindDataContext(); var employees = from e in dataContext.Employees where (EmployeeId.HasValue ? e.ReportsTo == EmployeeId : e.ReportsTo == null) select new { EmployeeId = e.EmployeeID, FullName = e.FirstName + " " + e.LastName, HasEmployees = 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 }); }
public ActionResult Products([DataSourceRequest] DataSourceRequest request) { var dataContext = new NorthwindDataContext(); var products = dataContext.Products .Select(p => new ClientProductViewModel { ProductID = p.ProductID, ProductName = p.ProductName, UnitPrice = p.UnitPrice ?? 0, QuantityPerUnit = p.QuantityPerUnit, CategoryID = p.CategoryID.Value }) .OrderBy(p => p.ProductName); return Json(products.ToDataSourceResult(request)); }
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 }); }
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); }
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, Freight = order.Freight, OrderDate = order.OrderDate, ShippedDate = order.ShippedDate, OrderID = order.OrderID, ShipAddress = order.ShipAddress, ShipCountry = order.ShipCountry, ShipName = order.ShipName, ShipCity = order.ShipCity, EmployeeID = order.EmployeeID, CustomerID = order.CustomerID }); }
public ActionResult ModelBinding() { NorthwindDataContext northwind = new NorthwindDataContext(); return View(northwind.Categories); }
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 ActionResult FilterMenuCustomization_Titles() { var db = new NorthwindDataContext(); return Json(db.Employees.Select(e => e.Title).Distinct(), JsonRequestBehavior.AllowGet); }
public JsonResult GetCascadeCategories() { var northwind = new NorthwindDataContext(); return Json(northwind.Categories.Select(c => new { CategoryId = c.CategoryID, CategoryName = c.CategoryName }), JsonRequestBehavior.AllowGet); }