Exemplo n.º 1
0
        public List <ProductOrCustomerViewModel> GetProductOrCustomer(string type)
        {
            List <ProductOrCustomerViewModel> result = null;

            using (DashboardOrderEntities _context = new DashboardOrderEntities())
            {
                if (!string.IsNullOrEmpty(type))
                {
                    if (type == "customers")
                    {
                        result = _context.Customers.Select(c => new ProductOrCustomerViewModel
                        {
                            Name          = c.CustomerName,
                            Image         = c.CustomerImage,
                            TypeOrCountry = c.CustomerCountry,
                            Type          = "Customers"
                        }).ToList();
                    }
                    else if (type == "products")
                    {
                        result = _context.Products.Select(p => new ProductOrCustomerViewModel
                        {
                            Name          = p.ProductName,
                            Image         = p.ProductImage,
                            TypeOrCountry = p.ProductType,
                            Type          = p.ProductType
                        }).ToList();
                    }
                }

                return(result);
            }
        }
Exemplo n.º 2
0
        public ActionResult TopCustomers()
        {
            List <TopCustomerViewModel> topFiveCustomers = null;

            using (DashboardOrderEntities _context = new DashboardOrderEntities())
            {
                var OrderByCustomer = (from o in _context.Orders
                                       group o by o.Customer.ID into g
                                       orderby g.Count() descending
                                       select new
                {
                    CustomerID = g.Key,
                    Count = g.Count()
                }).Take(5);

                topFiveCustomers = (from c in _context.Customers
                                    join o in OrderByCustomer
                                    on c.ID equals o.CustomerID
                                    select new TopCustomerViewModel
                {
                    CustomerName = c.CustomerName,
                    CustomerImage = c.CustomerImage,
                    CustomerCountry = c.CustomerCountry,
                    CountOrder = o.Count
                }).ToList();
            }

            return(PartialView("~/Views/DataCharts/TopCustomers.cshtml", topFiveCustomers));
        }
Exemplo n.º 3
0
        public ActionResult DataChart()
        {
            using (DashboardOrderEntities _context = new DashboardOrderEntities())
            {
                ViewBag.CountCustomers = _context.Customers.Count();
                ViewBag.CountOrders    = _context.Orders.Count();
                ViewBag.CountProducts  = _context.Products.Count();
            }

            return(View());
        }
Exemplo n.º 4
0
        public ActionResult CustomersByCountry()
        {
            DashboardOrderEntities _context = new DashboardOrderEntities();

            var customerByCountry = (from c in _context.Customers
                                     group c by c.CustomerCountry into g
                                     orderby g.Count() descending
                                     select new
            {
                Country = g.Key,
                CountCustomer = g.Count()
            }).ToList();

            return(Json(new { result = customerByCountry }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 5
0
        public ActionResult OrdersByCustomer()
        {
            DashboardOrderEntities _context = new DashboardOrderEntities();
            var ordersByCustomer            = (from o in _context.Orders
                                               group o by o.Customer.ID into g
                                               select new
            {
                Name = from c in _context.Customers
                       where c.ID == g.Key
                       select c.CustomerName,

                CountOrders = g.Count()
            }).ToList();


            return(Json(new { result = ordersByCustomer }, JsonRequestBehavior.AllowGet));
        }