Beispiel #1
0
        public JsonResult StoreDashboardReport()
        {
            var allOrders        = _orderService.GetOrders(0, 0, null, null, null, null, null, null, null);
            var registeredRoleId = _customerService.GetCustomerRoleBySystemName("Registered").Id;
            var model            = new StoreDashboardReportModel
            {
                ProductsCount              = _catalogSearchService.PrepareQuery(new CatalogSearchQuery()).Count().ToString("N0"),
                CategoriesCount            = _categoryService.BuildCategoriesQuery(showHidden: true).Count().ToString("N0"),
                ManufacturersCount         = _manufacturerService.GetManufacturers().Count().ToString("N0"),
                AttributesCount            = _productAttributeService.GetAllProductAttributes(0, int.MaxValue).TotalCount.ToString("N0"),
                AttributeCombinationsCount = _productService.CountAllProductVariants().ToString("N0"),
                MediaCount = _mediaService.CountFiles(new MediaSearchQuery {
                    Deleted = false
                }).ToString("N0"),
                CustomersCount = _customerService.SearchCustomers(
                    new CustomerSearchQuery
                {
                    Deleted         = false,
                    CustomerRoleIds = new int[] { registeredRoleId }
                }
                    ).TotalCount.ToString("N0"),
                OrdersCount          = allOrders.Count().ToString("N0"),
                Sales                = (allOrders.Sum(x => (decimal?)x.OrderTotal) ?? 0).ToString("C0"),
                OnlineCustomersCount = _customerService.GetOnlineCustomers(DateTime.UtcNow.AddMinutes(-15), null, 0, int.MaxValue).TotalCount.ToString("N0"),
                CartsValue           = _shoppingCartService.GetAllOpenCartSubTotal().ToString("C0"),
                WishlistsValue       = _shoppingCartService.GetAllOpenWishlistSubTotal().ToString("C0")
            };

            return(new JsonResult
            {
                Data = new { model },
                JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
        public async Task <JsonResult> StoreDashboardReportAsync()
        {
            var ordersQuery    = _db.Orders.AsNoTracking();
            var registeredRole = await _db.CustomerRoles
                                 .AsNoTracking()
                                 .FirstOrDefaultAsync(x => x.SystemName == SystemCustomerRoleNames.Registered);

            var registeredCustomersQuery = _db.Customers
                                           .AsNoTracking()
                                           .ApplyRolesFilter(new[] { registeredRole.Id });

            var sumAllOrders = await ordersQuery.SumAsync(x => (decimal?)x.OrderTotal) ?? 0;

            var sumOpenCarts = await _db.ShoppingCartItems.GetOpenCartTypeSubTotalAsync(ShoppingCartType.ShoppingCart);

            var sumWishlists = await _db.ShoppingCartItems.GetOpenCartTypeSubTotalAsync(ShoppingCartType.Wishlist);

            var model = new StoreDashboardReportModel
            {
                ProductsCount              = (await _catalogSearchService.PrepareQuery(new CatalogSearchQuery()).CountAsync()).ToString("N0"),
                CategoriesCount            = (await _db.Categories.CountAsync()).ToString("N0"),
                ManufacturersCount         = (await _db.Manufacturers.CountAsync()).ToString("N0"),
                AttributesCount            = (await _db.ProductAttributes.CountAsync()).ToString("N0"),
                AttributeCombinationsCount = (await _db.ProductVariantAttributeCombinations.CountAsync(x => x.IsActive)).ToString("N0"),
                MediaCount           = (await Services.MediaService.CountFilesAsync(new MediaSearchQuery {
                    Deleted = false
                })).ToString("N0"),
                CustomersCount       = (await registeredCustomersQuery.CountAsync()).ToString("N0"),
                OrdersCount          = (await ordersQuery.CountAsync()).ToString("N0"),
                Sales                = Services.CurrencyService.PrimaryCurrency.AsMoney(sumAllOrders).ToString(),
                OnlineCustomersCount = (await _db.Customers.ApplyOnlineCustomersFilter(15).CountAsync()).ToString("N0"),
                CartsValue           = Services.CurrencyService.PrimaryCurrency.AsMoney(sumOpenCarts).ToString(),
                WishlistsValue       = Services.CurrencyService.PrimaryCurrency.AsMoney(sumWishlists).ToString()
            };

            return(new JsonResult(new { model }));
        }