예제 #1
0
        /// <summary>
        /// simulate live data by creating a new order
        /// </summary>
        private void CreateNewOrder()
        {
            using (var db = new DataContext())
            {
                Random r = new Random();

                Order o = new Order();
                o.OrderDate = DateTime.Now;
                o.Product = db.Products.OrderBy(x => x.Id).Skip(r.Next(0, 3)).FirstOrDefault();
                o.Customer = db.Customers.FirstOrDefault();

                db.Orders.Add(o);
                db.SaveChanges();
            }
        }
예제 #2
0
        public JsonResult MonthSalesSummary()
        {
            var tomorrow = DateTime.Now.AddDays(1).Date;
            var first = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            List<Order> month;

            using (var db = new DataContext())
            {
                month = db.Orders.Include("Product").Where(o => o.OrderDate >= first && o.OrderDate < tomorrow).OrderBy(o => o.Product.ShortName).OrderBy(o => o.OrderDate).ToList();
            }

            var monthly = new { Count = month.Count().ToString("#,#"), Total = month.Sum(z => z.Product.Price).ToString("#,#.00") };

            return Json(monthly, JsonRequestBehavior.AllowGet);
        }
예제 #3
0
        public JsonResult TodaysSalesDetail()
        {
            List<Order> today;

            using (var db = new DataContext())
            {
                var now = DateTime.Now.Date;
                today = db.Orders.Include("Product").Where(o => o.OrderDate >= now).ToList();
            }

            var orders =
                (from x in today group x by x.Product.ShortName into p select new {p.Key, Total = p.Count()}).ToList();

            var transformedData = (from x in orders select new List<object>{ x.Key,x.Total});

            return Json(transformedData, JsonRequestBehavior.AllowGet);
        }
예제 #4
0
        public JsonResult TodaySalesSummary()
        {
            // to simulate live data, add a new order each time this is called
            CreateNewOrder();

            List<Order> today;

            using (var db = new DataContext())
            {
                var now = DateTime.Now.Date;
                today = db.Orders.Include("Product").Where(o => o.OrderDate >= now).ToList();                
            }

            var daily = new {Count = today.Count().ToString("#,#"), Total = today.Sum(z => z.Product.Price).ToString("#,#.00")};

            return Json(daily, JsonRequestBehavior.AllowGet);
        }
예제 #5
0
        protected void Application_Start()
        {

            Database.SetInitializer<DataContext>(new DashboardDataContextSeedInitializer());
            
            // this is here to force the initializer to run
            using (var db = new DataContext())
            {
                db.Database.Initialize(false);
            }

            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BootstrapSupport.BootstrapBundleConfig.RegisterBundles(System.Web.Optimization.BundleTable.Bundles);
        }
예제 #6
0
        public JsonResult MonthSalesDetail()
        {
            var tomorrow = DateTime.Now.AddDays(1).Date;
            var first = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);

            List<Order> month;

            using (var db = new DataContext())
            {
                month = db.Orders.Include("Product").Where(o => o.OrderDate >= first && o.OrderDate < tomorrow).OrderBy(o => o.Product.ShortName).OrderBy(o => o.OrderDate).ToList();
            }


            Dictionary<string, int[]> orders = new Dictionary<string, int[]>();

            foreach (Order o in month)
            {
                
                if (orders.ContainsKey(o.Product.ShortName))
                {
                    orders[o.Product.ShortName][o.OrderDate.Day - 1] += 1;
                }
                else
                {
                    orders.Add(o.Product.ShortName,new int[32]);
                    orders[o.Product.ShortName][o.OrderDate.Day - 1] += 1;
                }
            }

            var transformedData = orders.Select(e => new {name = e.Key, data = e.Value});

            return Json(transformedData, JsonRequestBehavior.AllowGet);
        }