public ActionResult FilterMenuCustomization_Titles()
 {
     using (var db = new SampleEntitiesDataContext())
     {
         return(Json(db.Employees.Select(e => e.Title).Distinct().ToList()));
     }
 }
Example #2
0
 private static OrderViewModel GetFirstOrder()
 {
     using (var northwind = new SampleEntitiesDataContext())
     {
         return(northwind.Orders.Select(order => new OrderViewModel
         {
             OrderDate = order.OrderDate,
         }).First());
     }
 }
        public JsonResult GetCascadeProducts(int?categories)
        {
            var northwind = new SampleEntitiesDataContext();
            var products  = northwind.Products.AsQueryable();

            if (categories != null)
            {
                products = products.Where(p => p.CategoryID == categories);
            }

            return(Json(products.Select(p => new { ProductID = p.ProductID, ProductName = p.ProductName })));
        }
        public JsonResult GetCascadeOrders(int?products)
        {
            var northwind = new SampleEntitiesDataContext();
            var orders    = northwind.OrderDetails.AsQueryable();

            if (products != null)
            {
                orders = orders.Where(o => o.ProductID == products);
            }

            return(Json(orders.Select(o => new { OrderID = o.OrderID, ShipCity = o.Order.ShipCity })));
        }
Example #5
0
        public ActionResult Tag_Helper()
        {
            using (var northwind = new SampleEntitiesDataContext())
            {
                var categories = northwind.Categories.ToList();
                categories.ForEach(c =>
                                   c.Products = northwind.Products
                                                .Where(p => p.CategoryID == c.CategoryID)
                                                .ToList());

                return(View(categories));
            }
        }
Example #6
0
        private void PopulateCategories()
        {
            var dataContext = new SampleEntitiesDataContext();
            var categories  = dataContext.Categories
                              .Select(c => new CategoryViewModel
            {
                CategoryID   = c.CategoryID,
                CategoryName = c.CategoryName
            })
                              .OrderBy(e => e.CategoryName);

            ViewData["categories"]      = categories;
            ViewData["defaultCategory"] = categories.First();
        }
 public ActionResult Pdf_Export_Read([DataSourceRequest] DataSourceRequest request)
 {
     using (var northwind = new SampleEntitiesDataContext())
     {
         return(Json(northwind.Employees.ToList().ToDataSourceResult(request, e => new EmployeeViewModel
         {
             EmployeeID = e.EmployeeID,
             Country = e.Country,
             Title = e.Title,
             FirstName = e.FirstName,
             LastName = e.LastName
         })));
     }
 }
        public IActionResult _StockData([DataSourceRequest] DataSourceRequest request)
        {
            var dateFrom = MIN_DATE;
            var dateTo   = DateTime.Now;
            var baseUnit = DEFAULT_UNIT;
            IEnumerable <StockDataPoint> result;

            using (var db = new SampleEntitiesDataContext())
            {
                if (request != null && request.Filters != null && request.Filters.Count > 0)
                {
                    var composite = request.Filters[0] as CompositeFilterDescriptor;
                    if (composite != null)
                    {
                        dateFrom = (DateTime)((FilterDescriptor)composite.FilterDescriptors[0]).ConvertedValue;
                        dateTo   = (DateTime)((FilterDescriptor)composite.FilterDescriptors[1]).ConvertedValue;
                        baseUnit = GetBaseUnit(dateFrom, dateTo);
                    }
                }

                var groupedData =
                    from s in db.Intradays
                    where s.Date >= dateFrom && s.Date <= dateTo
                    group s by new
                {
                    Year   = s.Date.Year,
                    Month  = baseUnit >= BaseUnit.Months ? s.Date.Month : 1,
                    Day    = baseUnit >= BaseUnit.Weeks ? s.Date.Day : 1,
                    Hour   = baseUnit >= BaseUnit.Hours ? s.Date.Hour : 0,
                    Minute = baseUnit >= BaseUnit.Minutes ? s.Date.Minute : 0
                } into g
                select g;

                var points =
                    from g in groupedData.ToList()
                    select new StockDataPoint
                {
                    Date   = new DateTime(g.Key.Year, g.Key.Month, g.Key.Day, g.Key.Hour, g.Key.Minute, 0),
                    Open   = g.Max(s => s.Open),
                    High   = g.Max(s => s.High),
                    Low    = g.Min(s => s.Low),
                    Close  = g.Max(s => s.Close),
                    Volume = g.Sum(s => s.Volume)
                };

                result = points.ToList().OrderBy(g => g.Date);
            }

            return(Json(result));
        }
        private static IEnumerable <ProductViewModel> GetProducts()
        {
            var northwind = new SampleEntitiesDataContext();

            return(northwind.Products.Select(product => new ProductViewModel
            {
                ProductID = product.ProductID,
                ProductName = product.ProductName,
                UnitPrice = product.UnitPrice.HasValue ? product.UnitPrice.Value : default(decimal),
                UnitsInStock = product.UnitsInStock.HasValue ? product.UnitsInStock.Value : default(int),
                UnitsOnOrder = product.UnitsOnOrder.HasValue ? product.UnitsOnOrder.Value : default(int),
                Discontinued = product.Discontinued,
                LastSupply = DateTime.Today
            }));
        }
        public ActionResult ToolbarTemplate_Categories()
        {
            using (var dataContext = new SampleEntitiesDataContext())
            {
                var categories = dataContext.Categories
                                 .Select(c => new CategoryViewModel
                {
                    CategoryID   = c.CategoryID,
                    CategoryName = c.CategoryName
                })
                                 .OrderBy(e => e.CategoryName);

                return(Json(categories.ToList()));
            }
        }
        public IActionResult _Weather(string station, int year, int month)
        {
            var db          = new SampleEntitiesDataContext();
            var weatherData = db.Weather
                              .Where(x => x.Station == station && x.Date.Year == year && x.Date.Month == month)
                              .Select(x => new
            {
                ID   = x.ID,
                Rain = x.Rain,
                TMax = x.TMax,
                Wind = x.Wind
            });

            return(Json(weatherData));
        }
Example #12
0
        private static IEnumerable <ProductViewModel> GetProducts()
        {
            var northwind = new SampleEntitiesDataContext();

            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
            }));
        }
        private static IEnumerable <EmployeeViewModel> GetEmployees()
        {
            var northwind = new SampleEntitiesDataContext();

            return(northwind.Employees.ToList().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 Employees(int?id)
        {
            var dataContext = new SampleEntitiesDataContext();

            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 = (from q in dataContext.Employees
                               where (q.ReportsTo == e.EmployeeID)
                               select q
                               ).Count() > 0
            };

            return(Json(employees));
        }
        public IActionResult _BoeingStockData()
        {
            var db = new SampleEntitiesDataContext();

            return(Json(
                       from s in db.Stocks
                       where s.Symbol == "BA"
                       select new StockDataPoint
            {
                Date = s.Date,
                Open = s.Open,
                High = s.High,
                Low = s.Low,
                Close = s.Close,
                Volume = s.Volume
            }
                       ));
        }
        public JsonResult GetCascadeOrders(int?products, string orderFilter)
        {
            using (var northwind = new SampleEntitiesDataContext())
            {
                var orders = northwind.OrderDetails.AsQueryable();

                if (products != null)
                {
                    orders = orders.Where(o => o.ProductID == products);
                }

                if (!string.IsNullOrEmpty(orderFilter))
                {
                    orders = orders.Where(o => o.Order.ShipCity.Contains(orderFilter));
                }

                return(Json(orders.Select(o => new { OrderID = o.OrderID, ShipCity = o.Order.ShipCity }).ToList()));
            }
        }
        private static IEnumerable <OrderViewModel> GetOrders()
        {
            var northwind = new SampleEntitiesDataContext();

            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
            }));
        }
Example #18
0
        private static IEnumerable <CustomerViewModel> GetCustomers()
        {
            var northwind = new SampleEntitiesDataContext();

            return(northwind.Customers.ToList().Select(customer => new CustomerViewModel
            {
                CustomerID = customer.CustomerID,
                CompanyName = customer.CompanyName,
                ContactName = customer.ContactName,
                ContactTitle = customer.ContactTitle,
                Address = customer.Address,
                City = customer.City,
                Region = customer.Region,
                PostalCode = customer.PostalCode,
                Country = customer.Country,
                Phone = customer.Phone,
                Fax = customer.Fax,
                Bool = customer.Bool
            }));
        }
        public IEnumerable <ProductSignalR> Read()
        {
            using (var context = new SampleEntitiesDataContext())
            {
                var createdAt = DateTime.Now;

                var products = context.Products
                               .OrderBy(p => p.ProductName)
                               .ToList()
                               .Select((p, index) => new ProductSignalR
                {
                    ID           = (index + 1),
                    ProductName  = p.ProductName,
                    UnitPrice    = (double)p.UnitPrice.GetValueOrDefault(),
                    UnitsInStock = p.UnitsInStock.GetValueOrDefault(),
                    CreatedAt    = createdAt = createdAt.AddMilliseconds(1)
                })
                               .ToList();
                return(products);
            }
        }
Example #20
0
        public JsonResult GetProducts(string text)
        {
            var northwind = new SampleEntitiesDataContext();

            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));
        }
        public IEnumerable <ProductSignalR> Read()
        {
            using (var context = new SampleEntitiesDataContext())
            {
                var products = context.Products.Select(p => new ProductSignalR
                {
                    ID           = p.ProductID,
                    ProductName  = p.ProductName,
                    UnitPrice    = (double)p.UnitPrice.GetValueOrDefault(),
                    UnitsInStock = p.UnitsInStock.GetValueOrDefault(),
                    CreatedAt    = DateTime.Now.AddMilliseconds(1),
                    Category     = new CategorySignalR()
                    {
                        CategoryID   = p.Category.CategoryID,
                        CategoryName = p.Category.CategoryName
                    }
                })
                               .ToList();

                return(products);
            }
        }
        public ActionResult CustomAjaxBinding_Read([DataSourceRequest] DataSourceRequest request)
        {
            var dataContext = new SampleEntitiesDataContext();

            // Convert to view model to avoid JSON serialization problems due to circular references.
            IQueryable <OrderViewModel> orders = dataContext.Orders.Select(o => new OrderViewModel
            {
                OrderID     = o.OrderID,
                ShipCity    = o.ShipCity,
                ShipCountry = o.ShipCountry,
                ShipName    = o.ShipName
            });

            orders = orders.ApplyOrdersFiltering(request.Filters);

            var total = orders.Count();

            orders = orders.ApplyOrdersSorting(request.Groups, request.Sorts);

            if (!request.Sorts.Any())
            {
                // Entity Framework doesn't support paging on unsorted data.
                orders = orders.OrderBy(o => o.OrderID);
            }

            orders = orders.ApplyOrdersPaging(request.Page, request.PageSize);

            IEnumerable data = orders.ApplyOrdersGrouping(request.Groups);

            var result = new DataSourceResult()
            {
                Data  = data,
                Total = total
            };

            return(Json(result));
        }
 public EmployeeDirectoryService(SampleEntitiesDataContext context)
 {
     db = context;
 }
        public JsonResult GetCascadeCategories()
        {
            var northwind = new SampleEntitiesDataContext();

            return(Json(northwind.Categories.Select(c => new { CategoryId = c.CategoryID, CategoryName = c.CategoryName })));
        }
 public GanttAssignmentService(SampleEntitiesDataContext context)
 {
     db = context;
 }
        public ActionResult FilterMenuCustomization_Cities()
        {
            var db = new SampleEntitiesDataContext();

            return(Json(db.Employees.Select(e => e.City).Distinct()));
        }
Example #27
0
 public SchedulerMeetingService(SampleEntitiesDataContext context)
 {
     db = context;
 }
 public GanttDependencyService(SampleEntitiesDataContext context)
 {
     db = context;
 }
Example #29
0
 public EmployeeDirectoryService(SampleEntitiesDataContext context)
 {
     db = context;
 }
 public SchedulerTaskService(SampleEntitiesDataContext context)
 {
     db = context;
 }
 public ProductRepository(SampleEntitiesDataContext db)
 {
     _db = db;
 }